|
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,27 @@ 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 | + self.center = np.asarray(center) |
108 | 107 |
|
109 | 108 | npoints = order + 1 |
110 | 109 | if nodes == "equispaced": |
111 | | - points_1d = np.linspace(-h/2, h/2, npoints, dtype=dtype) |
| 110 | + points_1d = np.linspace(-h/2, h/2, npoints) |
112 | 111 | weights_1d = None |
113 | 112 |
|
114 | 113 | elif nodes == "chebyshev": |
115 | | - a = np.arange(npoints, dtype=dtype) |
| 114 | + a = np.arange(npoints) |
116 | 115 | points_1d = (h/2)*np.cos((2*(a+1)-1)/(2*npoints)*np.pi) |
117 | 116 | weights_1d = None |
118 | 117 |
|
119 | 118 | elif nodes == "legendre": |
120 | 119 | from scipy.special import legendre |
121 | 120 | 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) |
| 121 | + points_1d = points_1d * (h/2) |
| 122 | + weights_1d = weights_1d * (h/2) |
124 | 123 |
|
125 | 124 | else: |
126 | 125 | raise ValueError(f"invalid node set: {nodes}") |
|
0 commit comments