rsarray 1.2.10__cp313-cp313-win_amd64.whl

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.
Files changed (59) hide show
  1. rsarray/__init__.py +12028 -0
  2. rsarray/_core/__init__.py +213 -0
  3. rsarray/_core/_exceptions.py +83 -0
  4. rsarray/_core/_internal.py +331 -0
  5. rsarray/_core/_multiarray_tests.py +129 -0
  6. rsarray/_core/_multiarray_umath.py +121 -0
  7. rsarray/_core/_rational_tests.py +52 -0
  8. rsarray/_core/arrayprint.py +36 -0
  9. rsarray/_core/fromnumeric.py +31 -0
  10. rsarray/_core/function_base.py +84 -0
  11. rsarray/_core/multiarray.py +385 -0
  12. rsarray/_core/numeric.py +28 -0
  13. rsarray/_core/numerictypes.py +233 -0
  14. rsarray/_core/records.py +14 -0
  15. rsarray/_core/shape_base.py +23 -0
  16. rsarray/_core/strings.py +78 -0
  17. rsarray/_core/umath.py +176 -0
  18. rsarray/_dtypes.py +1229 -0
  19. rsarray/_extra.py +6621 -0
  20. rsarray/_typing.py +24 -0
  21. rsarray/array_methods.py +1224 -0
  22. rsarray/array_ops.py +1585 -0
  23. rsarray/char.py +1590 -0
  24. rsarray/exceptions.py +45 -0
  25. rsarray/fft/__init__.py +231 -0
  26. rsarray/io.py +453 -0
  27. rsarray/lib/__init__.py +102 -0
  28. rsarray/lib/_function_base_impl.py +37 -0
  29. rsarray/lib/_index_tricks_impl.py +98 -0
  30. rsarray/lib/_nanfunctions_impl.py +1637 -0
  31. rsarray/lib/_stride_tricks_impl.py +110 -0
  32. rsarray/lib/recfunctions.py +1222 -0
  33. rsarray/lib/stride_tricks.py +106 -0
  34. rsarray/linalg/__init__.py +2603 -0
  35. rsarray/linalg/_linalg.py +91 -0
  36. rsarray/linalg/_pylinalg.py +1008 -0
  37. rsarray/linalg/lapack_lite.py +13 -0
  38. rsarray/ma/__init__.py +92 -0
  39. rsarray/ma/core.py +1385 -0
  40. rsarray/ma/extras.py +711 -0
  41. rsarray/ma/mrecords.py +144 -0
  42. rsarray/math_functions.py +965 -0
  43. rsarray/matlib.py +67 -0
  44. rsarray/num_core.cp313-win_amd64.pyd +0 -0
  45. rsarray/polynomial/__init__.py +148 -0
  46. rsarray/polynomial/_npcompat.py +721 -0
  47. rsarray/polynomial/polynomial.py +1082 -0
  48. rsarray/random/__init__.py +2266 -0
  49. rsarray/random/_distributions.py +773 -0
  50. rsarray/rec.py +207 -0
  51. rsarray/statistics.py +1360 -0
  52. rsarray/strings.py +349 -0
  53. rsarray/typing/__init__.py +26 -0
  54. rsarray-1.2.10.dist-info/METADATA +280 -0
  55. rsarray-1.2.10.dist-info/RECORD +59 -0
  56. rsarray-1.2.10.dist-info/WHEEL +4 -0
  57. rsarray-1.2.10.dist-info/licenses/LICENSE +21 -0
  58. rsarray-1.2.10.dist-info/licenses/NOTICE +7 -0
  59. rsarray-1.2.10.dist-info/sboms/rsarray.cyclonedx.json +2789 -0
rsarray/ma/mrecords.py ADDED
@@ -0,0 +1,144 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """掩码记录数组(ma.mrecords 兼容实现)。
3
+
4
+ MaskedRecords:基于结构化(记录)数据的掩码数组;逐记录访问返回
5
+ 带字段接口的记录对象。
6
+ """
7
+
8
+ import rsarray as np
9
+ from .core import MaskedArray, asarray, getmaskarray, nomask
10
+
11
+
12
+ class _MaskedRecord(tuple):
13
+ """带字段访问的记录(ma.mrecords 记录语义)。"""
14
+
15
+ def __new__(cls, values, dtype_obj, mask=None, parent=None, index=0):
16
+ obj = tuple.__new__(cls, tuple(values))
17
+ obj._values = list(values)
18
+ obj._dtype_obj = dtype_obj
19
+ obj._mask = list(mask) if mask is not None else [False] * len(values)
20
+ obj._parent = parent
21
+ obj._index = index
22
+ return obj
23
+
24
+ def __getattr__(self, name):
25
+ dt = self.__dict__.get('_dtype_obj')
26
+ names = getattr(dt, '_names', None) if dt is not None else None
27
+ if names and name in names:
28
+ i = names.index(name)
29
+ if self.__dict__.get('_mask', [False] * len(names))[i]:
30
+ return np.ma.masked
31
+ return self._values[i]
32
+ raise AttributeError(name)
33
+
34
+ @property
35
+ def dtype(self):
36
+ return self._dtype_obj
37
+
38
+
39
+ class MaskedRecords(MaskedArray):
40
+ """记录型掩码数组(ma.mrecords.MaskedRecords 兼容子集)。"""
41
+
42
+ def __init__(self, data=None, mask=False, dtype=None, fill_value=None,
43
+ **kwargs):
44
+ if data is None:
45
+ data = np.array([], dtype=dtype) if dtype is not None else np.array([])
46
+ elif not hasattr(data, '_array'):
47
+ data = np.array(data, dtype=dtype)
48
+ super().__init__(data, mask=mask, dtype=dtype,
49
+ fill_value=fill_value, **kwargs)
50
+
51
+ def __getitem__(self, key):
52
+ dt = self._data.dtype
53
+ if dt.names and isinstance(key, int) and self._data.ndim == 1:
54
+ names = dt.names
55
+ i = key % self._data.shape[0]
56
+ row = self._data[i]
57
+ values = [row[n] for n in names]
58
+ m = self._mask
59
+ rowmask = m[i * len(names):(i + 1) * len(names)]
60
+ return _MaskedRecord(values, dt, mask=rowmask, parent=self,
61
+ index=i)
62
+ return super().__getitem__(key)
63
+
64
+ def __iter__(self):
65
+ for i in range(len(self)):
66
+ yield self[i]
67
+
68
+
69
+ def mrecarray(data=None, dtype=None, shape=None, **kwargs):
70
+ """构造 MaskedRecords(ma.mrecords.mrecarray 兼容)。"""
71
+ return MaskedRecords(data, mask=kwargs.pop('mask', False),
72
+ dtype=dtype, fill_value=kwargs.pop('fill_value', None),
73
+ **kwargs)
74
+
75
+
76
+ def fromarrays(*args, **kwargs):
77
+ """从列数组构造 MaskedRecords(ma.mrecords.fromarrays 兼容)。
78
+
79
+ 单 list/tuple 参数按列解包(数组语义);MaskedArray 列取其底层
80
+ 数据(rec 层不理解 ma;掩码位置数据保留原值,与标准语义一致)。
81
+ """
82
+ mask = kwargs.pop('mask', None)
83
+ if len(args) == 1 and isinstance(args[0], (list, tuple)):
84
+ _first = args[0][0] if args[0] else None
85
+ if _first is not None and (
86
+ isinstance(_first, MaskedArray)
87
+ or hasattr(_first, '_array') or hasattr(_first, 'dtype')):
88
+ args = tuple(args[0])
89
+ dtype = kwargs.pop('dtype', None)
90
+ cols = []
91
+ for a in args:
92
+ if isinstance(a, MaskedArray):
93
+ cols.append(a.data)
94
+ else:
95
+ cols.append(a)
96
+ if dtype is None:
97
+ # 由列推断字段名/类型(names= 支持)
98
+ names = kwargs.pop('names', None)
99
+ if not cols or not names:
100
+ raise ValueError("fromarrays requires names= when dtype is None")
101
+ dtype = [(n, np.asarray(c).dtype) for n, c in zip(names, cols)]
102
+ recs = np.rec.fromarrays(cols, dtype=dtype, **kwargs)
103
+ return MaskedRecords(recs, mask=mask)
104
+
105
+
106
+ def fromrecords(recs, **kwargs):
107
+ """从记录序列构造 MaskedRecords(ma.mrecords.fromrecords 兼容)。"""
108
+ arr = np.rec.fromrecords(recs, **kwargs)
109
+ return MaskedRecords(arr)
110
+
111
+
112
+ def fromtextfile(name, **kwargs):
113
+ raise NotImplementedError(
114
+ "rsarray.ma.mrecords.fromtextfile is not implemented")
115
+
116
+
117
+ def addfield(a, data, name, dtype=None, newbytes=0):
118
+ """给记录数组追加字段(ma.mrecords.addfield 兼容)。"""
119
+ a = asarray(a)
120
+ if not np.dtype(a.data.dtype).names:
121
+ raise TypeError("addfield: a must be a record array")
122
+ rec = a.data
123
+ if name in rec.dtype.names:
124
+ raise ValueError(f"field {name!r} already exists")
125
+ vals = np.asarray(data, dtype=dtype)
126
+ newdt = list(rec.dtype.names) + [name]
127
+ # 逐记录重组
128
+ oldnames = rec.dtype.names
129
+ rows = []
130
+ for i in range(rec.shape[0]):
131
+ row = tuple(rec[i][n] for n in oldnames) + (vals[i] if i < vals.size else None,)
132
+ rows.append(row)
133
+ newarr = np.array(rows, dtype=rec.dtype.names and
134
+ [(n, rec.dtype.fields[n][0]) for n in oldnames] +
135
+ [(name, vals.dtype)])
136
+ m = list(a._mask)
137
+ extra = [False] * len(oldnames) if data is not None else []
138
+ a._data = newarr
139
+ a._mask = m + [False] * rec.shape[0]
140
+ return a
141
+
142
+
143
+ __all__ = ['MaskedRecords', 'mrecarray', 'fromarrays', 'fromrecords',
144
+ 'fromtextfile', 'addfield']