rsarray 1.2.10__cp315-cp315-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.cp315-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
@@ -0,0 +1,78 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core.strings 兼容门面:strings 底层 ufunc 的 Python 等价物。
3
+
4
+ 参考实现中这是 C 层 ufunc 模块;rsarray 的 ufunc 是 Python 层可调用
5
+ 对象。test_strings 的 gh-28829 回归测试依赖
6
+ ``np._core.strings._expandtabs_length.reduce(...)`` 对非字符串输入抛
7
+ ``_UFuncNoLoopError``(消息含 "did not contain a loop")。
8
+ """
9
+
10
+ import builtins
11
+
12
+ from rsarray._core._exceptions import _UFuncNoLoopError
13
+
14
+
15
+ def _no_loop_error(ufunc_name):
16
+ return _UFuncNoLoopError(
17
+ f"'{ufunc_name}' ufunc did not contain a loop with signature "
18
+ "matching types")
19
+
20
+
21
+ class _StringsUFunc:
22
+ """strings ufunc 占位:按输入类型做 no-loop 检查,字符串输入走等价实现。"""
23
+
24
+ def __init__(self, name, impl):
25
+ self._name = name
26
+ self._impl = impl
27
+ self.__name__ = name
28
+
29
+ def __call__(self, *args, **kwargs):
30
+ a = args[0]
31
+ if not _is_string_input(a):
32
+ raise _no_loop_error(self._name)
33
+ return self._impl(*args, **kwargs)
34
+
35
+ def reduce(self, a, *args, **kwargs):
36
+ # strings ufunc 无 reduce 语义:直接按 no-loop 报错
37
+ if not _is_string_input(a):
38
+ raise _no_loop_error(self._name)
39
+ raise _no_loop_error(self._name)
40
+
41
+
42
+ def _is_string_input(x):
43
+ if isinstance(x, (str, bytes)):
44
+ return True
45
+ k = getattr(getattr(x, 'dtype', None), 'kind', None)
46
+ return k in ('S', 'U')
47
+
48
+
49
+ def _expandtabs_length_impl(a, tabsize=8):
50
+ from rsarray import char as _char
51
+ vals = _char._decode(_char._get_strings(a))
52
+ ts = int(tabsize)
53
+ out = []
54
+ for v in vals:
55
+ new_len = 0
56
+ line_pos = 0
57
+ for ch in v:
58
+ if ch == '\t':
59
+ if ts > 0:
60
+ new_len += ts - (line_pos % ts)
61
+ line_pos += ts - (line_pos % ts)
62
+ else:
63
+ line_pos += 1
64
+ new_len += 1
65
+ if ch in '\n\r':
66
+ line_pos = 0
67
+ out.append(new_len)
68
+ from rsarray import ndarray as _nd
69
+ shape = _char._shape_of(a)
70
+ if isinstance(a, (str, bytes)) or shape == ():
71
+ res = _nd([builtins.float(out[0]) if out else 0], _dtype='int64')
72
+ return res.reshape(())
73
+ res = _nd([builtins.float(v) for v in out], _dtype='int64')
74
+ return res.reshape(shape)
75
+
76
+
77
+ _expandtabs_length = _StringsUFunc(
78
+ '_expandtabs_length', _expandtabs_length_impl)
rsarray/_core/umath.py ADDED
@@ -0,0 +1,176 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core.umath 兼容门面:按名暴露 rsarray 的 ufunc 集合。
3
+
4
+ 参考实现中这是 C 层 ufunc 模块;rsarray 的 ufunc 是 Python 层可调用
5
+ 对象。本模块在导入时把 rsarray 的 ufunc 函数标记(``_rs_ufunc`` +
6
+ ``.types`` 循环签名)并按同名导出,使 ``np._core.umath.__dict__``
7
+ 可直接按 ``isinstance(obj, np.ufunc)`` 迭代(test_umath_accuracy
8
+ 模块级代码依赖此)。
9
+ """
10
+
11
+ import rsarray as _np
12
+
13
+ # ufunc 循环签名(实际含 object 循环 OO->O 的标注了 object
14
+ # 循环;其余为数值循环)
15
+ _UFUNC_TYPES = {
16
+ 'add': 'OO->O,dd->d',
17
+ 'subtract': 'OO->O,dd->d',
18
+ 'multiply': 'OO->O,dd->d',
19
+ 'divide': 'OO->O,dd->d',
20
+ 'true_divide': 'OO->O,dd->d',
21
+ 'floor_divide': 'OO->O,dd->d',
22
+ 'mod': 'OO->O,dd->d',
23
+ 'fmod': 'dd->d',
24
+ 'remainder': 'OO->O,dd->d',
25
+ 'power': 'OO->O,dd->d',
26
+ 'negative': 'dd->d',
27
+ 'positive': 'dd->d',
28
+ 'absolute': 'dd->d',
29
+ 'fabs': 'dd->d',
30
+ 'sign': 'OO->O,dd->d',
31
+ 'copysign': 'dd->d',
32
+ 'maximum': 'OO->O,dd->d',
33
+ 'minimum': 'OO->O,dd->d',
34
+ 'hypot': 'dd->d',
35
+ 'ldexp': 'dd->d',
36
+ 'log': 'dd->d',
37
+ 'log2': 'dd->d',
38
+ 'log10': 'dd->d',
39
+ 'log1p': 'dd->d',
40
+ 'logaddexp': 'dd->d',
41
+ 'exp': 'dd->d',
42
+ 'expm1': 'dd->d',
43
+ 'exp2': 'dd->d',
44
+ 'sqrt': 'dd->d',
45
+ 'square': 'dd->d',
46
+ 'sin': 'dd->d',
47
+ 'cos': 'dd->d',
48
+ 'tan': 'dd->d',
49
+ 'arcsin': 'dd->d',
50
+ 'arccos': 'dd->d',
51
+ 'arctan': 'dd->d',
52
+ 'arctan2': 'dd->d',
53
+ 'sinh': 'dd->d',
54
+ 'cosh': 'dd->d',
55
+ 'tanh': 'dd->d',
56
+ 'arcsinh': 'dd->d',
57
+ 'arccosh': 'dd->d',
58
+ 'arctanh': 'dd->d',
59
+ 'floor': 'dd->d',
60
+ 'ceil': 'dd->d',
61
+ 'trunc': 'dd->d',
62
+ 'round': 'dd->d',
63
+ 'bitwise_and': 'OO->O,bb->b',
64
+ 'bitwise_or': 'OO->O,bb->b',
65
+ 'bitwise_xor': 'OO->O,bb->b',
66
+ 'invert': 'OO->O,bb->b',
67
+ 'bitwise_count': 'OO->O,bb->b',
68
+ 'left_shift': 'OO->O,dd->d',
69
+ 'right_shift': 'OO->O,dd->d',
70
+ 'logical_and': 'OO->O,??->?',
71
+ 'logical_or': 'OO->O,??->?',
72
+ 'logical_xor': 'OO->O,??->?',
73
+ 'logical_not': 'OO->O,?->?',
74
+ 'equal': 'OO->O,dd->d',
75
+ 'not_equal': 'OO->O,dd->d',
76
+ 'less': 'OO->O,dd->d',
77
+ 'greater': 'OO->O,dd->d',
78
+ 'less_equal': 'OO->O,dd->d',
79
+ 'greater_equal': 'OO->O,dd->d',
80
+ 'isfinite': 'dd->?',
81
+ 'isinf': 'dd->?',
82
+ 'isnan': 'dd->?',
83
+ 'all': 'OO->O,?->?',
84
+ 'any': 'OO->O,?->?',
85
+ 'cumsum': 'OO->O,dd->d',
86
+ 'cumprod': 'OO->O,dd->d',
87
+ 'gcd': 'dd->d',
88
+ 'lcm': 'dd->d',
89
+ }
90
+
91
+ __all__ = []
92
+
93
+ for _name, _types in _UFUNC_TYPES.items():
94
+ _f = getattr(_np, _name, None)
95
+ if _f is None or not callable(_f):
96
+ continue
97
+ if not getattr(_f, '_rs_ufunc', False):
98
+ _f._rs_ufunc = True
99
+ _f.types = _types
100
+ globals()[_name] = _f
101
+ __all__.append(_name)
102
+ del _name, _types, _f
103
+
104
+
105
+ def _slice(a, start, stop, step):
106
+ """``rsarray._core.umath._slice`` 等价:逐元素字符串切片。
107
+
108
+ start/stop/step 为 int 标量或序列(rsarray.strings.slice 完成哨兵
109
+ 归一后传入);None 按 step 符号逐元素展开为 intp 极值(step<0 取下界、
110
+ 否则取上界);step=0 → ValueError。返回与 a 同
111
+ dtype 种类(S→S、U→U)、形状 = a.shape 的数组。
112
+ """
113
+ import builtins
114
+ import rsarray as _np
115
+ from rsarray import char as _char
116
+ vals = _char._decode(_char._get_strings(a))
117
+ shape = _char._shape_of(a)
118
+ was_bytes = _char._a_was_bytes(a)
119
+ size = max(len(vals), 1)
120
+
121
+ def _flat(x, name):
122
+ if x is None:
123
+ return None
124
+ if isinstance(x, (list, tuple)):
125
+ f = list(x)
126
+ elif hasattr(x, 'tolist'):
127
+ t = x.tolist()
128
+ f = _char._flatten([t] if not isinstance(t, list) else t, [])
129
+ else:
130
+ f = [x]
131
+ try:
132
+ f = [int(v) for v in f]
133
+ except (TypeError, ValueError):
134
+ _dt = str(getattr(x, 'dtype', ''))
135
+ raise TypeError(
136
+ f"Cannot cast ufunc '_slice' input {name} from "
137
+ f"dtype('{_dt}') to dtype('int64') with casting rule "
138
+ f"'same_kind'") from None
139
+ if len(f) == 1 and size != 1:
140
+ f = f * size
141
+ return f
142
+
143
+ st = _flat(start, 'start')
144
+ ep = _flat(stop, 'stop')
145
+ sp = _flat(step, 'step')
146
+ if sp is None:
147
+ sp = [1] * size
148
+ # 注意:本模块命名空间里 any 是 rsarray 的 ufunc(对生成器求值失真),
149
+ # 必须用内置 any
150
+ if builtins.any(s == 0 for s in sp):
151
+ raise ValueError("slice step cannot be zero")
152
+ _iinfo = _np.iinfo(_np.intp)
153
+ _imax, _imin = int(_iinfo.max), int(_iinfo.min)
154
+ out = []
155
+ for i, v in enumerate(vals):
156
+ p_ = sp[i % len(sp)]
157
+ # —start None → where(step<0, imax, 0);stop None → where(step<0, imin, imax)
158
+ s_ = st[i % len(st)] if st else (_imax if p_ < 0 else 0)
159
+ e_ = ep[i % len(ep)] if ep else (_imin if p_ < 0 else _imax)
160
+ out.append(v[s_:e_:p_])
161
+ if was_bytes:
162
+ out = [s.encode('utf-8', 'surrogateescape') for s in out]
163
+ if isinstance(a, (str, bytes)) or not shape:
164
+ return _char._wrap_str(out, (), was_bytes)
165
+ return _char._wrap_str(out, shape, was_bytes)
166
+
167
+
168
+ def __getattr__(name):
169
+ if name == 'identity':
170
+ from rsarray._core import ufunc
171
+ return ufunc.identity
172
+ import rsarray
173
+ obj = getattr(rsarray, name, None)
174
+ if obj is not None and not name.startswith('_'):
175
+ return obj
176
+ raise AttributeError(f"module 'rsarray._core.umath' has no attribute {name!r}")