numpy2 2.0.0__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {numpy2-2.0.0/numpy2.egg-info → numpy2-2.1.0}/PKG-INFO +9 -9
- {numpy2-2.0.0 → numpy2-2.1.0}/README.md +6 -4
- numpy2-2.1.0/numpy2/__init__.py +487 -0
- numpy2-2.1.0/numpy2/advanced.py +572 -0
- numpy2-2.1.0/numpy2/array.py +1718 -0
- numpy2-2.1.0/numpy2/converters.py +213 -0
- numpy2-2.1.0/numpy2/core.py +324 -0
- numpy2-2.1.0/numpy2/dtypes.py +219 -0
- numpy2-2.1.0/numpy2/fft.py +226 -0
- numpy2-2.1.0/numpy2/integrations.py +204 -0
- numpy2-2.1.0/numpy2/linalg.py +418 -0
- numpy2-2.1.0/numpy2/math_ops.py +690 -0
- numpy2-2.1.0/numpy2/random.py +425 -0
- {numpy2-2.0.0 → numpy2-2.1.0/numpy2.egg-info}/PKG-INFO +9 -9
- {numpy2-2.0.0 → numpy2-2.1.0}/numpy2.egg-info/SOURCES.txt +7 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/numpy2.egg-info/requires.txt +0 -2
- {numpy2-2.0.0 → numpy2-2.1.0}/pyproject.toml +33 -13
- {numpy2-2.0.0 → numpy2-2.1.0}/setup.py +34 -13
- numpy2-2.1.0/tests/test_core.py +379 -0
- numpy2-2.0.0/numpy2/__init__.py +0 -136
- numpy2-2.0.0/numpy2/converters.py +0 -265
- numpy2-2.0.0/numpy2/core.py +0 -385
- numpy2-2.0.0/numpy2/integrations.py +0 -291
- numpy2-2.0.0/tests/test_core.py +0 -204
- {numpy2-2.0.0 → numpy2-2.1.0}/CONTRIBUTING.md +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/LICENSE +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/MANIFEST.in +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/numpy2.egg-info/dependency_links.txt +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/numpy2.egg-info/not-zip-safe +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/numpy2.egg-info/top_level.txt +0 -0
- {numpy2-2.0.0 → numpy2-2.1.0}/setup.cfg +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: numpy2
|
|
3
|
-
Version: 2.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 2.1.0
|
|
4
|
+
Summary: Pure-Python NumPy drop-in: full NumPy API + JSON serialization, array compression, pipeline transforms, schema validation, zero dependencies
|
|
5
5
|
Home-page: https://github.com/maheshmakvana/numpy2
|
|
6
6
|
Author: Mahesh Makvana
|
|
7
7
|
Author-email: Mahesh Makvana <mahesh.makvana@example.com>
|
|
@@ -10,7 +10,7 @@ Project-URL: Homepage, https://github.com/maheshmakvana/numpy2
|
|
|
10
10
|
Project-URL: Bug Tracker, https://github.com/maheshmakvana/numpy2/issues
|
|
11
11
|
Project-URL: Documentation, https://github.com/maheshmakvana/numpy2/wiki
|
|
12
12
|
Project-URL: Source Code, https://github.com/maheshmakvana/numpy2
|
|
13
|
-
Keywords: numpy,json
|
|
13
|
+
Keywords: numpy,numpy2,numpy drop-in,numpy replacement,pure python numpy,json serialization,numpy json,fastapi numpy,flask numpy,django numpy,web api numpy,array compression,array cache,array pipeline,array validation,sliding window,batch processing numpy,streaming array,pandas,data-science,type-conversion,rest-api,ndarray,linear algebra,fft,random,numerical computing,scientific computing,int64 json,numpy serializable,object of type int64 is not json serializable,numpy web framework,numpy fastapi
|
|
14
14
|
Classifier: Development Status :: 5 - Production/Stable
|
|
15
15
|
Classifier: Environment :: Web Environment
|
|
16
16
|
Classifier: Intended Audience :: Developers
|
|
@@ -30,8 +30,6 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
30
30
|
Requires-Python: >=3.8
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
32
32
|
License-File: LICENSE
|
|
33
|
-
Requires-Dist: numpy>=1.20.0
|
|
34
|
-
Requires-Dist: pandas>=1.3.0
|
|
35
33
|
Provides-Extra: fastapi
|
|
36
34
|
Requires-Dist: fastapi>=0.95.0; extra == "fastapi"
|
|
37
35
|
Requires-Dist: starlette>=0.26.0; extra == "fastapi"
|
|
@@ -54,10 +52,12 @@ Dynamic: requires-python
|
|
|
54
52
|
|
|
55
53
|
**Built by [Mahesh Makvana](https://github.com/maheshmakvana)**
|
|
56
54
|
|
|
57
|
-
](https://pypi.org/project/numpy2/)
|
|
56
|
+
[](https://pypi.org/project/numpy2/)
|
|
57
|
+
[](https://pypi.org/project/numpy2/)
|
|
58
|
+
[](LICENSE)
|
|
59
|
+
[](https://pypi.org/project/numpy2/)
|
|
60
|
+
[](https://pypi.org/project/numpy2/)
|
|
61
61
|
|
|
62
62
|
---
|
|
63
63
|
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
**Built by [Mahesh Makvana](https://github.com/maheshmakvana)**
|
|
4
4
|
|
|
5
|
-
](https://pypi.org/project/numpy2/)
|
|
6
|
+
[](https://pypi.org/project/numpy2/)
|
|
7
|
+
[](https://pypi.org/project/numpy2/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://pypi.org/project/numpy2/)
|
|
10
|
+
[](https://pypi.org/project/numpy2/)
|
|
9
11
|
|
|
10
12
|
---
|
|
11
13
|
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
"""
|
|
2
|
+
numpy2 - Drop-in NumPy replacement, pure Python, no NumPy required
|
|
3
|
+
====================================================================
|
|
4
|
+
|
|
5
|
+
Replace every ``import numpy as np`` with ``import numpy2 as np`` and
|
|
6
|
+
everything works identically — PLUS built-in JSON serialization and
|
|
7
|
+
web framework integration.
|
|
8
|
+
|
|
9
|
+
>>> import numpy2 as np # replaces: import numpy as np
|
|
10
|
+
>>> arr = np.array([1, 2, 3]) # identical API
|
|
11
|
+
>>> arr.mean() # 2.0
|
|
12
|
+
>>> np.to_json(arr) # '[1, 2, 3]'
|
|
13
|
+
|
|
14
|
+
NumPy is used as an optional accelerator when installed; if it is absent
|
|
15
|
+
every operation runs in pure Python.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
__version__ = "2.1.0"
|
|
19
|
+
__author__ = "Mahesh Makvana"
|
|
20
|
+
__email__ = "mahesh.makvana@example.com"
|
|
21
|
+
__license__ = "MIT"
|
|
22
|
+
|
|
23
|
+
# ── 1. dtype system ───────────────────────────────────────────────────────────
|
|
24
|
+
from .dtypes import (
|
|
25
|
+
dtype,
|
|
26
|
+
bool_, bool8,
|
|
27
|
+
int8, int16, int32, int64,
|
|
28
|
+
int_, intp, intc,
|
|
29
|
+
uint8, uint16, uint32, uint64,
|
|
30
|
+
float16, float32, float64,
|
|
31
|
+
float_, double, single, half,
|
|
32
|
+
complex64, complex128,
|
|
33
|
+
object_, str_, bytes_,
|
|
34
|
+
longdouble, clongdouble,
|
|
35
|
+
result_type,
|
|
36
|
+
)
|
|
37
|
+
# extra aliases
|
|
38
|
+
bool8 = bool_
|
|
39
|
+
csingle = complex64
|
|
40
|
+
cdouble = complex128
|
|
41
|
+
longfloat = longdouble
|
|
42
|
+
|
|
43
|
+
# ── 2. ndarray & array creation ───────────────────────────────────────────────
|
|
44
|
+
from .array import (
|
|
45
|
+
ndarray,
|
|
46
|
+
array, asarray, ascontiguousarray, asfortranarray,
|
|
47
|
+
zeros, ones, full, empty,
|
|
48
|
+
zeros_like, ones_like, full_like, empty_like,
|
|
49
|
+
eye, identity,
|
|
50
|
+
arange, linspace, logspace, geomspace,
|
|
51
|
+
diag, diagflat, tril, triu, vander,
|
|
52
|
+
meshgrid,
|
|
53
|
+
indices, fromiter, frombuffer, fromfunction, fromstring,
|
|
54
|
+
loadtxt, savetxt, load, save, savez,
|
|
55
|
+
concatenate, stack, vstack, hstack, dstack, column_stack, row_stack,
|
|
56
|
+
split, hsplit, vsplit, dsplit,
|
|
57
|
+
tile, repeat, unique,
|
|
58
|
+
flip, fliplr, flipud, rot90, roll, pad,
|
|
59
|
+
broadcast_to, broadcast_arrays,
|
|
60
|
+
expand_dims, squeeze,
|
|
61
|
+
atleast_1d, atleast_2d, atleast_3d,
|
|
62
|
+
where, select, argwhere,
|
|
63
|
+
argmax, argmin, argsort, sort, lexsort, searchsorted,
|
|
64
|
+
count_nonzero, flatnonzero, nonzero,
|
|
65
|
+
isnan, isinf, isfinite, isneginf, isposinf,
|
|
66
|
+
isreal, iscomplex, isscalar, isclose, allclose,
|
|
67
|
+
array_equal, array_equiv,
|
|
68
|
+
may_share_memory, shares_memory,
|
|
69
|
+
can_cast, common_type, min_scalar_type, promote_types,
|
|
70
|
+
shape, ndim, size,
|
|
71
|
+
copyto, iterable,
|
|
72
|
+
unravel_index, ravel_multi_index,
|
|
73
|
+
ix_, ndindex, ndenumerate,
|
|
74
|
+
apply_along_axis, apply_over_axes,
|
|
75
|
+
vectorize, frompyfunc,
|
|
76
|
+
# constants
|
|
77
|
+
nan, inf, pi, e, newaxis,
|
|
78
|
+
# matrix ops
|
|
79
|
+
matmul,
|
|
80
|
+
# broadcast helper (internal but useful)
|
|
81
|
+
_broadcast_shapes as _broadcast_shapes_internal,
|
|
82
|
+
)
|
|
83
|
+
PINF = inf
|
|
84
|
+
NINF = -inf
|
|
85
|
+
Inf = inf
|
|
86
|
+
Infinity = inf
|
|
87
|
+
NaN = nan
|
|
88
|
+
False_ = False
|
|
89
|
+
True_ = True
|
|
90
|
+
PZERO = 0.0
|
|
91
|
+
NZERO = -0.0
|
|
92
|
+
|
|
93
|
+
# mgrid / ogrid stubs
|
|
94
|
+
class _MGridClass:
|
|
95
|
+
def __getitem__(self, key):
|
|
96
|
+
raise NotImplementedError("Use meshgrid or arange in numpy2 pure mode")
|
|
97
|
+
mgrid = _MGridClass()
|
|
98
|
+
ogrid = _MGridClass()
|
|
99
|
+
|
|
100
|
+
# index_exp / s_ stubs
|
|
101
|
+
class _IndexExpClass:
|
|
102
|
+
def __getitem__(self, key):
|
|
103
|
+
return key
|
|
104
|
+
index_exp = _IndexExpClass()
|
|
105
|
+
s_ = _IndexExpClass()
|
|
106
|
+
|
|
107
|
+
c_ = None # not yet implemented
|
|
108
|
+
r_ = None
|
|
109
|
+
|
|
110
|
+
# ── 3. math / ufuncs ──────────────────────────────────────────────────────────
|
|
111
|
+
from .math_ops import (
|
|
112
|
+
# trig
|
|
113
|
+
sin, cos, tan,
|
|
114
|
+
arcsin, arccos, arctan, arctan2,
|
|
115
|
+
hypot, deg2rad, rad2deg, degrees, radians, unwrap,
|
|
116
|
+
# hyperbolic
|
|
117
|
+
sinh, cosh, tanh, arcsinh, arccosh, arctanh,
|
|
118
|
+
# exp / log
|
|
119
|
+
exp, exp2, expm1, log, log2, log10, log1p,
|
|
120
|
+
# rounding
|
|
121
|
+
floor, ceil, trunc, rint, fix, around, round_,
|
|
122
|
+
# arithmetic ufuncs
|
|
123
|
+
add, subtract, multiply, divide, true_divide, floor_divide,
|
|
124
|
+
negative, positive, power, float_power,
|
|
125
|
+
remainder, mod, fmod,
|
|
126
|
+
absolute, fabs, sign, heaviside,
|
|
127
|
+
sqrt, cbrt, square, reciprocal,
|
|
128
|
+
# logical
|
|
129
|
+
logical_and, logical_or, logical_xor, logical_not,
|
|
130
|
+
# bitwise
|
|
131
|
+
bitwise_and, bitwise_or, bitwise_xor, bitwise_not, invert,
|
|
132
|
+
left_shift, right_shift,
|
|
133
|
+
# comparison
|
|
134
|
+
greater, greater_equal, less, less_equal, equal, not_equal,
|
|
135
|
+
maximum, minimum, fmax, fmin,
|
|
136
|
+
# complex
|
|
137
|
+
real, imag, conj, conjugate, angle,
|
|
138
|
+
# reductions
|
|
139
|
+
sum, prod, nansum, nanprod,
|
|
140
|
+
mean, nanmean, std, nanstd, var, nanvar,
|
|
141
|
+
min, max, nanmin, nanmax,
|
|
142
|
+
ptp, cumsum, cumprod, nancumsum, nancumprod,
|
|
143
|
+
diff, gradient, ediff1d,
|
|
144
|
+
# linear algebra
|
|
145
|
+
cross, dot, vdot, inner, outer, kron, tensordot, einsum,
|
|
146
|
+
# stats
|
|
147
|
+
median, nanmedian,
|
|
148
|
+
percentile, nanpercentile, quantile, nanquantile,
|
|
149
|
+
average, correlate, convolve,
|
|
150
|
+
cov, corrcoef,
|
|
151
|
+
histogram, histogram2d, histogramdd,
|
|
152
|
+
bincount, digitize, interp, trapz,
|
|
153
|
+
i0, sinc,
|
|
154
|
+
lcm, gcd, modf, frexp, ldexp, spacing, nextafter,
|
|
155
|
+
# abs alias
|
|
156
|
+
abs as absolute_fn,
|
|
157
|
+
)
|
|
158
|
+
# shadow Python builtins with numpy2 versions
|
|
159
|
+
abs = absolute
|
|
160
|
+
round = around
|
|
161
|
+
|
|
162
|
+
# ── 4. submodules ─────────────────────────────────────────────────────────────
|
|
163
|
+
from . import linalg
|
|
164
|
+
from . import fft
|
|
165
|
+
from . import random
|
|
166
|
+
|
|
167
|
+
# make polynomial, ma, lib stubs (users can still use them via numpy if installed)
|
|
168
|
+
try:
|
|
169
|
+
import numpy as _np_opt
|
|
170
|
+
polynomial = _np_opt.polynomial
|
|
171
|
+
ma = _np_opt.ma
|
|
172
|
+
lib = _np_opt.lib
|
|
173
|
+
char = _np_opt.char
|
|
174
|
+
try:
|
|
175
|
+
strings = _np_opt.strings
|
|
176
|
+
except AttributeError:
|
|
177
|
+
pass
|
|
178
|
+
try:
|
|
179
|
+
exceptions = _np_opt.exceptions
|
|
180
|
+
except AttributeError:
|
|
181
|
+
pass
|
|
182
|
+
# also expose numpy's testing module
|
|
183
|
+
testing = _np_opt.testing
|
|
184
|
+
except ImportError:
|
|
185
|
+
# provide minimal stubs so imports don't crash
|
|
186
|
+
class _Stub:
|
|
187
|
+
def __getattr__(self, name):
|
|
188
|
+
raise ImportError(f"numpy2: 'numpy.{name}' requires NumPy to be installed")
|
|
189
|
+
polynomial = _Stub()
|
|
190
|
+
ma = _Stub()
|
|
191
|
+
lib = _Stub()
|
|
192
|
+
char = _Stub()
|
|
193
|
+
testing = _Stub()
|
|
194
|
+
|
|
195
|
+
# ── 5. numpy2 advanced features ──────────────────────────────────────────────
|
|
196
|
+
from .advanced import (
|
|
197
|
+
ArrayCache,
|
|
198
|
+
ArrayPipeline,
|
|
199
|
+
ArrayValidator,
|
|
200
|
+
ArrayValidationError,
|
|
201
|
+
ProfiledArray,
|
|
202
|
+
compress_array,
|
|
203
|
+
decompress_array,
|
|
204
|
+
compress_to_b64,
|
|
205
|
+
decompress_from_b64,
|
|
206
|
+
sliding_window_view,
|
|
207
|
+
batch_apply,
|
|
208
|
+
to_structured,
|
|
209
|
+
array_chunks,
|
|
210
|
+
describe,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# ── 6. numpy2 web extras ──────────────────────────────────────────────────────
|
|
214
|
+
from .core import (
|
|
215
|
+
to_json, from_json,
|
|
216
|
+
serialize, deserialize,
|
|
217
|
+
JSONEncoder, JSONDecoder,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
from .converters import (
|
|
221
|
+
numpy_to_python, pandas_to_json,
|
|
222
|
+
python_to_numpy, infer_dtype,
|
|
223
|
+
safe_cast, batch_convert,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
from .integrations import (
|
|
227
|
+
FastAPIResponse, FlaskResponse, DjangoResponse,
|
|
228
|
+
setup_json_encoder, create_response_handler,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# ── 6. nditer / ndenumerate compatibility ────────────────────────────────────
|
|
232
|
+
class nditer:
|
|
233
|
+
"""Minimal nditer stub."""
|
|
234
|
+
def __init__(self, op, flags=None, op_flags=None, op_dtypes=None,
|
|
235
|
+
order='K', casting='safe', op_axes=None, itershape=None,
|
|
236
|
+
buffersize=0):
|
|
237
|
+
from .array import asarray
|
|
238
|
+
self._arr = asarray(op) if not isinstance(op, (list, tuple)) else [asarray(o) for o in op]
|
|
239
|
+
self._idx = 0
|
|
240
|
+
if isinstance(self._arr, list):
|
|
241
|
+
self._data = list(zip(*[a._data for a in self._arr]))
|
|
242
|
+
else:
|
|
243
|
+
self._data = self._arr._data
|
|
244
|
+
|
|
245
|
+
def __iter__(self):
|
|
246
|
+
return self
|
|
247
|
+
|
|
248
|
+
def __next__(self):
|
|
249
|
+
if self._idx >= len(self._data):
|
|
250
|
+
raise StopIteration
|
|
251
|
+
val = self._data[self._idx]
|
|
252
|
+
self._idx += 1
|
|
253
|
+
return val
|
|
254
|
+
|
|
255
|
+
def __len__(self):
|
|
256
|
+
return len(self._data)
|
|
257
|
+
|
|
258
|
+
@property
|
|
259
|
+
def finished(self):
|
|
260
|
+
return self._idx >= len(self._data)
|
|
261
|
+
|
|
262
|
+
def iternext(self):
|
|
263
|
+
if self._idx < len(self._data):
|
|
264
|
+
self._idx += 1
|
|
265
|
+
return True
|
|
266
|
+
return False
|
|
267
|
+
|
|
268
|
+
# ── 7. poly functions ─────────────────────────────────────────────────────────
|
|
269
|
+
from .math_ops import interp as _interp
|
|
270
|
+
|
|
271
|
+
def polyval(p, x):
|
|
272
|
+
"""Evaluate polynomial with coefficients p at points x."""
|
|
273
|
+
from .array import asarray
|
|
274
|
+
p = asarray(p)
|
|
275
|
+
x = asarray(x)
|
|
276
|
+
result = zeros_like(x, dtype='float64')
|
|
277
|
+
for coef in p._data:
|
|
278
|
+
result = result * x + coef
|
|
279
|
+
return result
|
|
280
|
+
|
|
281
|
+
def polyfit(x, y, deg):
|
|
282
|
+
"""Least-squares polynomial fit. Returns coefficients."""
|
|
283
|
+
from .array import asarray
|
|
284
|
+
from .linalg import lstsq
|
|
285
|
+
x = asarray(x, dtype='float64')
|
|
286
|
+
y = asarray(y, dtype='float64')
|
|
287
|
+
# Vandermonde matrix
|
|
288
|
+
V = vander(x, deg + 1)
|
|
289
|
+
coeffs, _, _, _ = lstsq(V, y)
|
|
290
|
+
return coeffs
|
|
291
|
+
|
|
292
|
+
def polyadd(a1, a2):
|
|
293
|
+
from .array import asarray
|
|
294
|
+
a1, a2 = asarray(a1, dtype='float64'), asarray(a2, dtype='float64')
|
|
295
|
+
n1, n2 = len(a1._data), len(a2._data)
|
|
296
|
+
if n1 < n2:
|
|
297
|
+
a1 = concatenate([zeros(n2 - n1, dtype='float64'), a1])
|
|
298
|
+
elif n2 < n1:
|
|
299
|
+
a2 = concatenate([zeros(n1 - n2, dtype='float64'), a2])
|
|
300
|
+
return a1 + a2
|
|
301
|
+
|
|
302
|
+
def polysub(a1, a2):
|
|
303
|
+
return polyadd(a1, -asarray(a2, dtype='float64'))
|
|
304
|
+
|
|
305
|
+
def polymul(a1, a2):
|
|
306
|
+
return convolve(a1, a2)
|
|
307
|
+
|
|
308
|
+
def polydiv(u, v):
|
|
309
|
+
u = list(asarray(u, dtype='float64')._data)
|
|
310
|
+
v = list(asarray(v, dtype='float64')._data)
|
|
311
|
+
# polynomial long division
|
|
312
|
+
q, r = [], list(u)
|
|
313
|
+
while len(r) >= len(v):
|
|
314
|
+
coef = r[0] / v[0]
|
|
315
|
+
q.append(coef)
|
|
316
|
+
for i in range(len(v)):
|
|
317
|
+
r[i] -= coef * v[i]
|
|
318
|
+
r.pop(0)
|
|
319
|
+
return array(q, dtype='float64'), array(r, dtype='float64')
|
|
320
|
+
|
|
321
|
+
def polyder(p, m=1):
|
|
322
|
+
p = list(asarray(p, dtype='float64')._data)
|
|
323
|
+
for _ in range(m):
|
|
324
|
+
n = len(p) - 1
|
|
325
|
+
p = [(n - i) * p[i] for i in range(n)]
|
|
326
|
+
return array(p, dtype='float64')
|
|
327
|
+
|
|
328
|
+
def polyint(p, m=1, k=None):
|
|
329
|
+
p = list(asarray(p, dtype='float64')._data)
|
|
330
|
+
for _ in range(m):
|
|
331
|
+
n = len(p)
|
|
332
|
+
p = [p[i] / (n - i) for i in range(n)] + [0.0]
|
|
333
|
+
return array(p, dtype='float64')
|
|
334
|
+
|
|
335
|
+
def poly(seq_of_zeros):
|
|
336
|
+
"""Return polynomial with given roots."""
|
|
337
|
+
seq = asarray(seq_of_zeros, dtype='float64')
|
|
338
|
+
result = array([1.0])
|
|
339
|
+
for root in seq._data:
|
|
340
|
+
result = polymul(result, array([1.0, -root]))
|
|
341
|
+
return result
|
|
342
|
+
|
|
343
|
+
class poly1d:
|
|
344
|
+
"""1-D polynomial class."""
|
|
345
|
+
def __init__(self, c_or_r, r=False, variable=None):
|
|
346
|
+
c = asarray(c_or_r, dtype='float64')
|
|
347
|
+
if r:
|
|
348
|
+
self.coeffs = poly(c)
|
|
349
|
+
else:
|
|
350
|
+
self.coeffs = c
|
|
351
|
+
|
|
352
|
+
def __call__(self, val):
|
|
353
|
+
return polyval(self.coeffs, asarray(val, dtype='float64'))
|
|
354
|
+
|
|
355
|
+
@property
|
|
356
|
+
def order(self):
|
|
357
|
+
return len(self.coeffs._data) - 1
|
|
358
|
+
|
|
359
|
+
def __repr__(self):
|
|
360
|
+
return f"poly1d({self.coeffs.tolist()})"
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
# ── 8. seterr / errstate (stubs) ──────────────────────────────────────────────
|
|
364
|
+
_err_state = {'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
|
|
365
|
+
|
|
366
|
+
def seterr(divide=None, over=None, under=None, invalid=None, all=None):
|
|
367
|
+
old = dict(_err_state)
|
|
368
|
+
for key, val in [('divide', divide), ('over', over), ('under', under), ('invalid', invalid)]:
|
|
369
|
+
if val is not None:
|
|
370
|
+
_err_state[key] = val
|
|
371
|
+
if all is not None:
|
|
372
|
+
for key in _err_state:
|
|
373
|
+
_err_state[key] = all
|
|
374
|
+
return old
|
|
375
|
+
|
|
376
|
+
def geterr():
|
|
377
|
+
return dict(_err_state)
|
|
378
|
+
|
|
379
|
+
class errstate:
|
|
380
|
+
def __init__(self, **kwargs):
|
|
381
|
+
self._kwargs = kwargs
|
|
382
|
+
self._old = {}
|
|
383
|
+
def __enter__(self):
|
|
384
|
+
self._old = seterr(**self._kwargs)
|
|
385
|
+
def __exit__(self, *args):
|
|
386
|
+
seterr(**self._old)
|
|
387
|
+
|
|
388
|
+
def seterrcall(func):
|
|
389
|
+
pass
|
|
390
|
+
|
|
391
|
+
def geterrcall():
|
|
392
|
+
return None
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# ── 9. __all__ ────────────────────────────────────────────────────────────────
|
|
396
|
+
__all__ = [
|
|
397
|
+
# dtype
|
|
398
|
+
'dtype',
|
|
399
|
+
'bool_', 'bool8', 'int8', 'int16', 'int32', 'int64',
|
|
400
|
+
'int_', 'intp', 'intc',
|
|
401
|
+
'uint8', 'uint16', 'uint32', 'uint64',
|
|
402
|
+
'float16', 'float32', 'float64', 'float_', 'double', 'single', 'half',
|
|
403
|
+
'complex64', 'complex128', 'csingle', 'cdouble',
|
|
404
|
+
'object_', 'str_', 'bytes_',
|
|
405
|
+
'longdouble', 'longfloat', 'clongdouble',
|
|
406
|
+
'result_type',
|
|
407
|
+
# ndarray & creation
|
|
408
|
+
'ndarray', 'matrix',
|
|
409
|
+
'array', 'asarray', 'ascontiguousarray', 'asfortranarray',
|
|
410
|
+
'zeros', 'ones', 'full', 'empty',
|
|
411
|
+
'zeros_like', 'ones_like', 'full_like', 'empty_like',
|
|
412
|
+
'eye', 'identity', 'arange', 'linspace', 'logspace', 'geomspace',
|
|
413
|
+
'diag', 'diagflat', 'tril', 'triu', 'vander',
|
|
414
|
+
'meshgrid', 'mgrid', 'ogrid', 'indices',
|
|
415
|
+
'fromiter', 'frombuffer', 'fromfunction', 'fromstring',
|
|
416
|
+
'loadtxt', 'savetxt', 'load', 'save', 'savez',
|
|
417
|
+
'concatenate', 'stack', 'vstack', 'hstack', 'dstack', 'column_stack', 'row_stack',
|
|
418
|
+
'split', 'hsplit', 'vsplit', 'dsplit',
|
|
419
|
+
'tile', 'repeat', 'unique',
|
|
420
|
+
'flip', 'fliplr', 'flipud', 'rot90', 'roll', 'pad',
|
|
421
|
+
'broadcast_to', 'broadcast_arrays', 'expand_dims', 'squeeze',
|
|
422
|
+
'atleast_1d', 'atleast_2d', 'atleast_3d',
|
|
423
|
+
'where', 'select', 'argwhere', 'argmax', 'argmin', 'argsort', 'sort', 'lexsort',
|
|
424
|
+
'searchsorted', 'count_nonzero', 'flatnonzero', 'nonzero',
|
|
425
|
+
'isnan', 'isinf', 'isfinite', 'isneginf', 'isposinf',
|
|
426
|
+
'isreal', 'iscomplex', 'isscalar', 'isclose', 'allclose',
|
|
427
|
+
'array_equal', 'array_equiv',
|
|
428
|
+
'may_share_memory', 'shares_memory',
|
|
429
|
+
'can_cast', 'common_type', 'min_scalar_type', 'promote_types',
|
|
430
|
+
'shape', 'ndim', 'size', 'copyto', 'iterable',
|
|
431
|
+
'unravel_index', 'ravel_multi_index', 'ix_', 'ndindex', 'ndenumerate',
|
|
432
|
+
'apply_along_axis', 'apply_over_axes', 'vectorize', 'frompyfunc',
|
|
433
|
+
'nan', 'inf', 'pi', 'e', 'newaxis', 'nan', 'inf',
|
|
434
|
+
'NaN', 'Inf', 'Infinity', 'PINF', 'NINF',
|
|
435
|
+
'matmul', 'nditer', 'index_exp', 's_',
|
|
436
|
+
# math
|
|
437
|
+
'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'arctan2',
|
|
438
|
+
'hypot', 'deg2rad', 'rad2deg', 'degrees', 'radians', 'unwrap',
|
|
439
|
+
'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
|
|
440
|
+
'exp', 'exp2', 'expm1', 'log', 'log2', 'log10', 'log1p',
|
|
441
|
+
'floor', 'ceil', 'trunc', 'rint', 'fix', 'around', 'round_',
|
|
442
|
+
'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide',
|
|
443
|
+
'negative', 'positive', 'power', 'float_power',
|
|
444
|
+
'remainder', 'mod', 'fmod',
|
|
445
|
+
'absolute', 'fabs', 'sign', 'heaviside',
|
|
446
|
+
'sqrt', 'cbrt', 'square', 'reciprocal',
|
|
447
|
+
'logical_and', 'logical_or', 'logical_xor', 'logical_not',
|
|
448
|
+
'bitwise_and', 'bitwise_or', 'bitwise_xor', 'bitwise_not', 'invert',
|
|
449
|
+
'left_shift', 'right_shift',
|
|
450
|
+
'greater', 'greater_equal', 'less', 'less_equal', 'equal', 'not_equal',
|
|
451
|
+
'maximum', 'minimum', 'fmax', 'fmin',
|
|
452
|
+
'real', 'imag', 'conj', 'conjugate', 'angle',
|
|
453
|
+
'sum', 'prod', 'nansum', 'nanprod',
|
|
454
|
+
'mean', 'nanmean', 'std', 'nanstd', 'var', 'nanvar',
|
|
455
|
+
'min', 'max', 'nanmin', 'nanmax',
|
|
456
|
+
'ptp', 'cumsum', 'cumprod', 'nancumsum', 'nancumprod',
|
|
457
|
+
'diff', 'gradient', 'ediff1d',
|
|
458
|
+
'cross', 'dot', 'vdot', 'inner', 'outer', 'kron', 'tensordot', 'einsum',
|
|
459
|
+
'median', 'nanmedian', 'percentile', 'nanpercentile', 'quantile', 'nanquantile',
|
|
460
|
+
'average', 'correlate', 'convolve', 'cov', 'corrcoef',
|
|
461
|
+
'histogram', 'histogram2d', 'histogramdd',
|
|
462
|
+
'bincount', 'digitize', 'interp', 'trapz',
|
|
463
|
+
'i0', 'sinc', 'lcm', 'gcd', 'modf', 'frexp', 'ldexp', 'spacing', 'nextafter',
|
|
464
|
+
# poly
|
|
465
|
+
'polyval', 'polyfit', 'polyadd', 'polysub', 'polymul', 'polydiv',
|
|
466
|
+
'polyder', 'polyint', 'poly', 'poly1d',
|
|
467
|
+
# err state
|
|
468
|
+
'seterr', 'geterr', 'errstate', 'seterrcall', 'geterrcall',
|
|
469
|
+
# submodules
|
|
470
|
+
'linalg', 'fft', 'random', 'polynomial', 'ma', 'lib', 'testing', 'char',
|
|
471
|
+
# web extras
|
|
472
|
+
'to_json', 'from_json', 'serialize', 'deserialize',
|
|
473
|
+
'JSONEncoder', 'JSONDecoder',
|
|
474
|
+
'numpy_to_python', 'pandas_to_json', 'python_to_numpy',
|
|
475
|
+
'infer_dtype', 'safe_cast', 'batch_convert',
|
|
476
|
+
'FastAPIResponse', 'FlaskResponse', 'DjangoResponse',
|
|
477
|
+
'setup_json_encoder', 'create_response_handler',
|
|
478
|
+
# advanced
|
|
479
|
+
'ArrayCache', 'ArrayPipeline', 'ArrayValidator', 'ArrayValidationError',
|
|
480
|
+
'ProfiledArray',
|
|
481
|
+
'compress_array', 'decompress_array', 'compress_to_b64', 'decompress_from_b64',
|
|
482
|
+
'sliding_window_view', 'batch_apply', 'to_structured',
|
|
483
|
+
'array_chunks', 'describe',
|
|
484
|
+
]
|
|
485
|
+
|
|
486
|
+
# matrix alias (2-D array subclass stub)
|
|
487
|
+
matrix = ndarray
|