Skip to content

Commit

Permalink
Merge pull request #535 from ubermag/remove_typesystem
Browse files Browse the repository at this point in the history
removed_type_system
  • Loading branch information
lang-m authored Feb 2, 2025
2 parents 9d50517 + cb4f3ca commit 2fd9253
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
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

0 comments on commit 2fd9253

Please sign in to comment.