|
35 | 35 | if TYPE_CHECKING: |
36 | 36 | from collections.abc import Callable, Sequence |
37 | 37 |
|
38 | | - from optype.numpy import Array1D, Array2D, ArrayND |
| 38 | + from optype.numpy import Array1D, Array2D, ArrayND, ToArray1D |
39 | 39 |
|
40 | 40 |
|
41 | 41 | __doc__ = """ |
@@ -99,28 +99,28 @@ class CalculusPatch: |
99 | 99 | _pshape: tuple[int, ...] |
100 | 100 |
|
101 | 101 | def __init__(self, |
102 | | - center: Array1D[np.floating[Any]], |
| 102 | + center: ToArray1D[np.floating[Any]], |
103 | 103 | h: float = 1e-1, |
104 | 104 | order: int = 4, |
105 | 105 | nodes: NodesKind = "chebyshev") -> None: |
106 | | - self.center = center |
107 | | - dtype = center.dtype |
| 106 | + center = np.asarray(center) |
| 107 | + assert center.ndim == 1 |
108 | 108 |
|
109 | 109 | npoints = order + 1 |
110 | 110 | if nodes == "equispaced": |
111 | | - points_1d = np.linspace(-h/2, h/2, npoints, dtype=dtype) |
| 111 | + points_1d = np.linspace(-h/2, h/2, npoints) |
112 | 112 | weights_1d = None |
113 | 113 |
|
114 | 114 | elif nodes == "chebyshev": |
115 | | - a = np.arange(npoints, dtype=dtype) |
| 115 | + a = np.arange(npoints) |
116 | 116 | points_1d = (h/2)*np.cos((2*(a+1)-1)/(2*npoints)*np.pi) |
117 | 117 | weights_1d = None |
118 | 118 |
|
119 | 119 | elif nodes == "legendre": |
120 | 120 | from scipy.special import legendre |
121 | 121 | points_1d, weights_1d, _ = legendre(npoints).weights.T |
122 | | - points_1d = (points_1d * (h/2)).astype(dtype) |
123 | | - weights_1d = (weights_1d * (h/2)).astype(dtype) |
| 122 | + points_1d = points_1d * (h/2) |
| 123 | + weights_1d = weights_1d * (h/2) |
124 | 124 |
|
125 | 125 | else: |
126 | 126 | raise ValueError(f"invalid node set: {nodes}") |
|
0 commit comments