Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed_type_system #535

Merged
merged 3 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup headless display
uses: pyvista/setup-headless-display-action@v2
uses: pyvista/setup-headless-display-action@v3

- name: Set up conda
uses: conda-incubator/setup-miniconda@v3
Expand Down
28 changes: 18 additions & 10 deletions discretisedfield/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import ubermagutil.typesystem as ts
import ubermagutil.units as uu


@ts.typesystem(
dim=ts.Scalar(expected_type=int, positive=True, const=True),
n=ts.Scalar(expected_type=int, positive=True, const=True),
)
class Line:
"""Line class.

Expand Down Expand Up @@ -99,13 +94,18 @@ def __init__(self, points, values, point_columns, value_columns):
raise ValueError(msg)

# Set the dimension (const descriptor).
if isinstance(values[0], numbers.Complex):
self.dim = 1
else:
self.dim = len(values[0])
dim = 1 if isinstance(values[0], numbers.Complex) else len(values[0])

if not isinstance(dim, int) or dim <= 0:
raise ValueError(f"dim must be a positive integer, got {dim}.")

# Set the number of values (const descriptor).
self.n = len(points)
n = len(points)
if not isinstance(n, int) or n <= 0:
raise ValueError(f"n must be a positive integer, got {n}.")

self._dim = dim
self._n = n

points = np.array(points)
values = np.array(values).reshape((points.shape[0], -1))
Expand All @@ -121,6 +121,14 @@ def __init__(self, points, values, point_columns, value_columns):
self._point_columns = list(point_columns)
self._value_columns = list(value_columns)

@property
def dim(self):
return self._dim

@property
def n(self):
return self._n

@property
def point_columns(self):
"""The names of point columns.
Expand Down
Loading