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/rec.py ADDED
@@ -0,0 +1,207 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """记录数组(rec 兼容层)。
3
+
4
+ 参考实现中 ``rec`` 是 ``rsarray._core.records`` 的 star-import;
5
+ rsarray 在本模块直接提供同名集合:array / fromrecords / fromarrays /
6
+ fromstring / fromfile / find_duplicate / recarray。
7
+ """
8
+
9
+ from collections import Counter
10
+
11
+ import rsarray as np
12
+
13
+
14
+ def __getattr__(name):
15
+ if name == 'recarray':
16
+ return np.recarray
17
+ if name == 'record':
18
+ return np.record
19
+ raise AttributeError("module 'rsarray.rec' has no attribute %r" % name)
20
+
21
+
22
+ def _resolve_rec_dtype(dtype, formats, names):
23
+ """formats/names → dtype 规格(rec 函数共用)。"""
24
+ if dtype is not None:
25
+ return dtype
26
+ if formats is None:
27
+ return None
28
+ if isinstance(formats, str):
29
+ return formats
30
+ if names is not None:
31
+ if isinstance(names, str):
32
+ names = [n.strip() for n in names.split(',')]
33
+ return list(zip(names, formats))
34
+ return formats
35
+
36
+
37
+ def _read_bytes(file):
38
+ if hasattr(file, 'read'):
39
+ return file.read()
40
+ with open(file, 'rb') as f:
41
+ return f.read()
42
+
43
+
44
+ def _infer_scalar_dtype(v):
45
+ """从标量值推断类型(rec.array 推断语义)。"""
46
+ if isinstance(v, bool):
47
+ return '?'
48
+ if isinstance(v, int):
49
+ return 'i8'
50
+ if isinstance(v, float):
51
+ return 'f8'
52
+ if isinstance(v, complex):
53
+ return 'c16'
54
+ if isinstance(v, str):
55
+ return 'U' + str(max(1, len(v)))
56
+ if isinstance(v, (bytes, bytearray)):
57
+ return 'S' + str(max(1, len(v)))
58
+ return 'f8'
59
+
60
+
61
+ def _infer_struct_dtype(obj, names):
62
+ """从数据与字段名推断结构化 dtype(rec.array 语义:仅给 names、
63
+ 无 formats 时按首条记录推断各字段类型)。"""
64
+ if isinstance(names, str):
65
+ names = [n.strip() for n in names.split(',')]
66
+ try:
67
+ first = obj[0]
68
+ except Exception:
69
+ first = obj
70
+ if isinstance(first, (list, tuple)):
71
+ vals = list(first)
72
+ else:
73
+ vals = [first] * len(names)
74
+ fields = []
75
+ for i, n in enumerate(names):
76
+ v = vals[i] if i < len(vals) else 0
77
+ fields.append((n, _infer_scalar_dtype(v)))
78
+ return fields
79
+
80
+
81
+ def array(obj, dtype=None, shape=None, formats=None, names=None, **kwargs):
82
+ """从数据构造一个 recarray(支持属性方式访问字段)。
83
+
84
+ 对象参数为文件对象或原始 bytes(配合 formats/shape/byteorder)时
85
+ 走二进制读取路径(rec.array 兼容)。
86
+ """
87
+ dt = _resolve_rec_dtype(dtype, formats, names)
88
+ if hasattr(obj, 'read'):
89
+ return _as_recarray(fromfile(obj, dtypes=dt, shape=shape,
90
+ **kwargs))
91
+ if isinstance(obj, (bytes, bytearray)) and dt is not None:
92
+ return _as_recarray(fromstring(bytes(obj), dtypes=dt, shape=shape,
93
+ **kwargs))
94
+ # 数组语义:仅给 names(无 dtype/formats)→ 从数据推断各字段类型构造
95
+ # 结构化 dtype(否则 np.array 会推断成浮点数组、丢失结构)
96
+ if dt is None and names is not None:
97
+ dt = _infer_struct_dtype(obj, names)
98
+ a = np.array(obj, dtype=dt)
99
+ return np._as_recarray(a)
100
+
101
+
102
+ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None,
103
+ **kwargs):
104
+ """从记录列表构造 recarray。"""
105
+ return array(recList, dtype=dtype, shape=shape, formats=formats,
106
+ names=names, **kwargs)
107
+
108
+
109
+ def fromarrays(itemsets, dtypes=None, names=None, shape=None, **kwargs):
110
+ """从字段数组列表构造 recarray(数据拷贝,rec.fromarrays 兼容)。"""
111
+ rs = np
112
+ # dtype 关键字(兼容):单个结构化 dtype,取其字段名与各字段类型
113
+ dt_kw = kwargs.get('dtype', None)
114
+ if names is not None and isinstance(names, str):
115
+ names = [n.strip() for n in names.split(',')]
116
+ if dt_kw is not None:
117
+ _d = rs.dtype(dt_kw)
118
+ names = list(_d.names) if _d.names \
119
+ else ['f%d' % i for i in range(len(itemsets))]
120
+ dtypes = [_d.fields[n][0] for n in names]
121
+ dt = _d
122
+ elif dtypes is None:
123
+ if names is None:
124
+ names = ['f%d' % i for i in range(len(itemsets))]
125
+ dtypes = []
126
+ for a in itemsets:
127
+ arr = a if isinstance(a, rs.ndarray) else rs.asarray(a)
128
+ # 数组语义:嵌套 structured 数组不支持(字段套字段)
129
+ if getattr(getattr(arr.dtype, 'names', None), '__len__', lambda: 0)():
130
+ raise ValueError('element sizes are not compatible')
131
+ dtypes.append(arr.dtype)
132
+ dt = rs.dtype(list(zip(names, dtypes)))
133
+ else:
134
+ dtypes = list(dtypes)
135
+ if names is None:
136
+ names = ['f%d' % i for i in range(len(dtypes))]
137
+ dt = rs.dtype(list(zip(names, dtypes)))
138
+ n = len(itemsets[0])
139
+ recs = []
140
+ for i in range(n):
141
+ recs.append(tuple(itemsets[k][i] for k in range(len(itemsets))))
142
+ a = rs.array(recs, dtype=dt)
143
+ return rs._as_recarray(a)
144
+
145
+
146
+ def fromstring(string, dtypes=None, shape=None, offset=0, sep='',
147
+ formats=None, names=None, byteorder=None, **kwargs):
148
+ """从 bytes 字符串读取数组(rec.fromstring 兼容)。
149
+
150
+ object dtype(引用)不支持,抛 ValueError。
151
+ """
152
+ from rsarray._core import multiarray
153
+ rs = np
154
+ dt = _resolve_rec_dtype(dtypes, formats, names)
155
+ if dt is None:
156
+ dt = 'f8'
157
+ dt = rs.dtype(dt)
158
+ if dt.kind == 'O':
159
+ raise ValueError("Arrays containing references are not supported")
160
+ data = bytes(string)
161
+ if sep:
162
+ text = data.decode('ascii', 'replace')
163
+ vals = [float(v) for v in text.replace('\n', sep).split(sep)
164
+ if v.strip()]
165
+ a = rs.array(vals, dtype=dt)
166
+ return a.reshape(shape) if shape else a
167
+ data = data[offset:]
168
+ n = shape if shape is not None else len(data) // dt.itemsize
169
+ vals = multiarray.unpack_array_bytes(data, dt, n, byteorder)
170
+ return rs.array(vals, dtype=dt)
171
+
172
+
173
+ def fromfile(file, dtypes=None, shape=None, offset=0, sep='',
174
+ formats=None, names=None, byteorder=None, **kwargs):
175
+ """从文件读取数组(rec.fromfile 兼容)。
176
+
177
+ object dtype(引用)不支持,抛 ValueError。
178
+ """
179
+ from rsarray._core import multiarray
180
+ rs = np
181
+ dt = _resolve_rec_dtype(dtypes, formats, names)
182
+ if dt is None:
183
+ dt = 'f8'
184
+ dt = rs.dtype(dt)
185
+ if dt.kind == 'O':
186
+ raise ValueError("Arrays containing references are not supported")
187
+ if sep:
188
+ data = _read_bytes(file)
189
+ text = data.decode('ascii', 'replace')
190
+ vals = [float(v) for v in text.replace('\n', sep).split(sep)
191
+ if v.strip()]
192
+ a = rs.array(vals, dtype=dt)
193
+ return a.reshape(shape) if shape else a
194
+ data = _read_bytes(file)
195
+ data = data[offset:]
196
+ n = shape if shape is not None else len(data) // dt.itemsize
197
+ vals = multiarray.unpack_array_bytes(data, dt, n, byteorder)
198
+ return rs.array(vals, dtype=dt)
199
+
200
+
201
+ def _as_recarray(a):
202
+ return np._as_recarray(a)
203
+
204
+
205
+ def find_duplicate(lst):
206
+ """Find duplication in a list, return a list of duplicated elements."""
207
+ return [item for item, counts in Counter(lst).items() if counts > 1]