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,129 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core._multiarray_tests 兼容实现(C 测试辅助的 Python 版)。"""
3
+
4
+ __all__ = ['array_indexing']
5
+
6
+
7
+ def _rs():
8
+ import rsarray
9
+ return rsarray
10
+
11
+
12
+ def array_indexing(op, array, *args):
13
+ """C-API 索引辅助:op=0 取 ``array[args]``;
14
+ op=1 赋值 ``array[args[:-1]] = args[-1]``。
15
+
16
+ 0-d 数组与越界索引抛 IndexError(与 C 实现一致);
17
+ op=1 缺少值时抛 ValueError(删除不可能)。
18
+ """
19
+ rs = _rs()
20
+ arr = array if isinstance(array, rs.ndarray) else rs.asarray(array)
21
+ if arr.ndim == 0:
22
+ raise IndexError("0-d arrays cannot be indexed")
23
+ if op == 0:
24
+ if not args:
25
+ raise IndexError("no indices given")
26
+ return arr[args]
27
+ if op == 1:
28
+ value = args[-1]
29
+ idx = args[:-1]
30
+ if not idx:
31
+ raise ValueError("cannot delete from a C array")
32
+ arr[idx] = value
33
+ return None
34
+ raise ValueError(f"unknown op {op}")
35
+
36
+
37
+ # ---------------------------------------------------------------------------
38
+ # C 内部测试辅助桩:rsarray 无对应 C 实现;相关测试由 conftest 的
39
+ # _SKIP_MARKERS 源串匹配跳过(这些函数在测试模块顶层被 import,
40
+ # 故此处必须存在可导入的名字)。
41
+ # ---------------------------------------------------------------------------
42
+
43
+ def _not_implemented(name):
44
+ raise NotImplementedError(
45
+ f"rsarray has no C helper {name!r}; test is expected to be skipped")
46
+
47
+
48
+ def create_custom_field_dtype(*args, **kwargs):
49
+ _not_implemented("create_custom_field_dtype")
50
+
51
+
52
+ def get_c_wrapping_array(*args, **kwargs):
53
+ _not_implemented("get_c_wrapping_array")
54
+
55
+
56
+ def incref_elide(*args, **kwargs):
57
+ _not_implemented("incref_elide")
58
+
59
+
60
+ def incref_elide_l(*args, **kwargs):
61
+ _not_implemented("incref_elide_l")
62
+
63
+
64
+ def IsPythonScalar(*args, **kwargs):
65
+ _not_implemented("IsPythonScalar")
66
+
67
+
68
+ def npy_char_deprecation(*args, **kwargs):
69
+ _not_implemented("npy_char_deprecation")
70
+
71
+
72
+ __all__ = __all__ + ['create_custom_field_dtype', 'get_c_wrapping_array',
73
+ 'incref_elide', 'incref_elide_l', 'IsPythonScalar',
74
+ 'npy_char_deprecation']
75
+
76
+
77
+ def run_scalar_intp_converter(x):
78
+ """标量 → intp 转换(rsarray._core._multiarray_tests 同名 C 桩)。"""
79
+ import rsarray
80
+ return rsarray.intp(x)
81
+
82
+
83
+ def run_scalar_intp_from_sequence(x):
84
+ """序列 → intp 转换(rsarray._core._multiarray_tests 同名 C 桩)。"""
85
+ import rsarray
86
+ return tuple(rsarray.intp(v) for v in x)
87
+
88
+
89
+ # ---- npymath 冒烟函数桩(test_npymath_* 用,Python math/cmath 实现) ----
90
+
91
+ def npy_cabs(z):
92
+ """复数模(npymath npy_cabs 桩)。"""
93
+ return abs(complex(z))
94
+
95
+
96
+ def npy_carg(z):
97
+ """复数辐角(npymath npy_carg 桩)。"""
98
+ import cmath
99
+ return cmath.phase(complex(z))
100
+
101
+
102
+ def npy_cosh(x):
103
+ """双曲余弦(npymath 桩)。"""
104
+ import math
105
+ return math.cosh(float(x))
106
+
107
+
108
+ def npy_log10(x):
109
+ """常用对数(npymath 桩)。"""
110
+ import math
111
+ return math.log10(float(x))
112
+
113
+
114
+ def npy_sinh(x):
115
+ """双曲正弦(npymath 桩)。"""
116
+ import math
117
+ return math.sinh(float(x))
118
+
119
+
120
+ def npy_tan(x):
121
+ """正切(npymath 桩)。"""
122
+ import math
123
+ return math.tan(float(x))
124
+
125
+
126
+ def npy_tanh(x):
127
+ """双曲正切(npymath 桩)。"""
128
+ import math
129
+ return math.tanh(float(x))
@@ -0,0 +1,121 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core._multiarray_umath 兼容实现(Python 版)。
3
+
4
+ MAXDIMS 与 rsarray 嵌套序列发现路径的实际维度上限一致(64)。
5
+ """
6
+
7
+ MAXDIMS = 64
8
+
9
+ # rsarray 无 SIMD 特性检测:空 dict 使按 CPU 特性分支的测试走通用路径。
10
+ __cpu_features__ = {}
11
+
12
+ __all__ = ['MAXDIMS', '_discover_array_parameters', '__cpu_features__',
13
+ '_array_converter', '_get_sfloat_dtype']
14
+
15
+
16
+ def _rs():
17
+ import rsarray
18
+ return rsarray
19
+
20
+
21
+ def _discover_shape(sequence):
22
+ """按 公共前缀规则推断嵌套序列形状。"""
23
+ rs = _rs()
24
+ if isinstance(sequence, rs.ndarray):
25
+ return tuple(sequence.shape)
26
+ if not isinstance(sequence, (list, tuple)):
27
+ return ()
28
+ if len(sequence) == 0:
29
+ return (0,)
30
+ subs = []
31
+ for el in sequence:
32
+ if isinstance(el, rs.ndarray):
33
+ subs.append(tuple(el.shape))
34
+ elif isinstance(el, (list, tuple)):
35
+ subs.append(_discover_shape(el))
36
+ else:
37
+ return (len(sequence),)
38
+ prefix = ()
39
+ first = subs[0]
40
+ for i in range(len(first)):
41
+ if all(len(s) > i and s[i] == first[i] for s in subs[1:]):
42
+ prefix += (first[i],)
43
+ else:
44
+ break
45
+ return (len(sequence),) + prefix
46
+
47
+
48
+ def _type_matches(dt, hint):
49
+ try:
50
+ return dt.type is hint
51
+ except Exception:
52
+ return False
53
+
54
+
55
+ def _discover_array_parameters(sequence, dtype=None, *args, **kwargs):
56
+ """推断 (dtype, shape)(C-helper 兼容)。
57
+
58
+ 空序列时 dtype 由 hint 类型决定:
59
+ - bytes_/unicode_ 按 惯例映射为 S1/U1;
60
+ - datetime64/timedelta64 类型类优先匹配 M8/m8 spec(rsarray 的
61
+ M/m dtype 类型类为 unicode_,与 U 同形,无法直接反解析);
62
+ - 其余类型先直接反解析,失败后按 .type 逐一匹配候选 spec。
63
+ """
64
+ rs = _rs()
65
+ if dtype is None:
66
+ dt = rs.dtype('float64')
67
+ elif isinstance(dtype, rs.dtype):
68
+ dt = dtype
69
+ else:
70
+ dt = None
71
+ if dtype is rs.bytes_:
72
+ dt = rs.dtype('S1')
73
+ elif dtype is rs.unicode_:
74
+ dt = rs.dtype('U1')
75
+ elif dtype is rs.void:
76
+ dt = rs.dtype('V8')
77
+ if dt is None:
78
+ # datetime64/timedelta64 类型类特判(.type 与 U 同形)
79
+ for spec in ('M8', 'm8'):
80
+ try:
81
+ cand = rs.dtype(spec)
82
+ except Exception:
83
+ continue
84
+ if _type_matches(cand, dtype):
85
+ dt = cand
86
+ break
87
+ if dt is None and isinstance(dtype, type):
88
+ try:
89
+ if issubclass(dtype, rs.dtype):
90
+ # dtype 类本身(rsarray 扁平 dtype 类,2 中为各具体
91
+ # DType 类):空序列时按 传统默认 float64
92
+ dt = rs.dtype('float64')
93
+ except TypeError:
94
+ pass
95
+ if dt is None:
96
+ try:
97
+ dt = rs.dtype(dtype)
98
+ except Exception:
99
+ for spec in ('M', 'm', 'V8', 'M8', 'm8', 'O'):
100
+ try:
101
+ cand = rs.dtype(spec)
102
+ except Exception:
103
+ continue
104
+ if _type_matches(cand, dtype):
105
+ dt = cand
106
+ break
107
+ if dt is None:
108
+ raise
109
+ return dt, _discover_shape(sequence)
110
+
111
+
112
+ def _array_converter(*args, **kwargs):
113
+ """C 层数组转换器桩:rsarray 无对应实现(相关测试经 conftest skip)。"""
114
+ raise NotImplementedError(
115
+ "rsarray has no C _array_converter; test is expected to be skipped")
116
+
117
+
118
+ def _get_sfloat_dtype():
119
+ """C 层 small-float dtype 桩:rsarray 无对应实现(相关测试经 conftest skip)。"""
120
+ raise NotImplementedError(
121
+ "rsarray has no C _get_sfloat_dtype; test is expected to be skipped")
@@ -0,0 +1,52 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core._rational_tests 兼容实现。
3
+
4
+ 在该模块定义测试专用 ``rational`` 标量 dtype(C 层类型:真实
5
+ dtype,但不在 sctypeDict 中)。rsarray 以纯 Python 类近似:
6
+
7
+ - ``dtype`` 属性返回 object dtype——使标量构造路径(``np.array`` /
8
+ ``astype`` / setitem)可用;
9
+ - 类型本身不在 sctypeDict 中,且类级 ``rational.dtype`` 是 property
10
+ 对象(非 dtype 实例)——使 ``sctype2char`` 得到与 一致的
11
+ KeyError。
12
+
13
+ rational dtype 的专用存储与算术未实现(依赖它的 casting 测试仍失败)。
14
+ """
15
+
16
+ __all__ = ['rational', 'rational2']
17
+
18
+
19
+ class rational:
20
+ """测试专用有理数标量(分子/分母对)。"""
21
+
22
+ def __init__(self, real, imag=1):
23
+ self.real = real
24
+ self.imag = imag
25
+
26
+ @property
27
+ def dtype(self):
28
+ import rsarray
29
+ return rsarray.dtype('O')
30
+
31
+ def __repr__(self):
32
+ return f"rational({self.real}, {self.imag})"
33
+
34
+ def __eq__(self, other):
35
+ return (isinstance(other, rational)
36
+ and (self.real, self.imag) == (other.real, other.imag))
37
+
38
+ def __hash__(self):
39
+ return hash((self.real, self.imag))
40
+
41
+
42
+ class rational2(rational):
43
+ """第二个测试用有理数类型(独立的类身份,共享 object dtype 近似)。"""
44
+
45
+ def __repr__(self):
46
+ return f"rational2({self.real}, {self.imag})"
47
+
48
+
49
+ # rsarray 不支持用户自定义 C 标量 dtype;通过 __rsarray_dtype__ 协议让
50
+ # np.dtype(rational) 解析到 object dtype(_dtypes._resolve_scalar_obj 识别)。
51
+ rational.__rsarray_dtype__ = 'O'
52
+ rational2.__rsarray_dtype__ = 'O'
@@ -0,0 +1,36 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core.arrayprint 兼容实现。
3
+
4
+ _typelessdata:把数组值转成与 dtype 无关的字符串表示(repr 测试用)。
5
+ """
6
+
7
+
8
+ def _typelessdata(a, typestr):
9
+ """递归地把数组元素转成 typestr 风格的字符串(同名函数兼容)。"""
10
+ import rsarray as rs
11
+ if getattr(a, 'ndim', 0) > 0:
12
+ return typestr + '[' + ', '.join(_typelessdata(v, typestr) for v in a) + ']'
13
+ try:
14
+ v = a.item() if hasattr(a, 'item') else a
15
+ except Exception:
16
+ v = a
17
+ if typestr == 'S':
18
+ if isinstance(v, bytes):
19
+ return typestr + v.decode('ascii', 'replace')
20
+ return typestr + str(v)
21
+ return str(v)
22
+
23
+
24
+ def _reexports():
25
+ import rsarray as rs
26
+ d = {}
27
+ if hasattr(rs, 'set_printoptions'):
28
+ d['set_printoptions'] = rs.set_printoptions
29
+ return d
30
+
31
+
32
+ for _n, _v in _reexports().items():
33
+ globals()[_n] = _v
34
+ del _reexports, _n, _v
35
+
36
+ __all__ = ['_typelessdata', 'set_printoptions']
@@ -0,0 +1,31 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core.fromnumeric 兼容层:从 rsarray 顶层再导出。
3
+
4
+ rsarray 的逐元素/构造公共 API 直接挂在顶层命名空间;本模块提供
5
+ 2.x 的 ``rsarray._core.fromnumeric`` 导入路径。
6
+ """
7
+
8
+ _NAMES = (
9
+ 'all', 'allclose', 'amax', 'amin', 'any', 'argmax', 'argmin',
10
+ 'argpartition', 'argsort', 'around', 'ceil', 'clip', 'copyto',
11
+ 'cumprod', 'cumsum', 'deg2rad', 'diff', 'ediff1d', 'empty',
12
+ 'empty_like', 'fix', 'floor', 'floor_divide', 'full', 'full_like',
13
+ 'gradient', 'inner', 'isclose', 'isfinite', 'isinf', 'isnan',
14
+ 'itemset', 'log2', 'log10', 'logaddexp', 'logaddexp2', 'maximum',
15
+ 'minimum', 'mod', 'modf', 'msort', 'nan_to_num', 'nanmax',
16
+ 'nanmean', 'nanmin', 'nansum', 'nonzero', 'ones', 'ones_like',
17
+ 'prod', 'product', 'ptp', 'rad2deg', 'remainder', 'round',
18
+ 'round_', 'searchsorted', 'sign', 'signbit', 'sqrt', 'square',
19
+ 'std', 'sum', 'true_divide', 'transpose', 'var',
20
+ )
21
+
22
+
23
+ def __getattr__(name):
24
+ if name in _NAMES:
25
+ import rsarray
26
+ return getattr(rsarray, name)
27
+ raise AttributeError(f"module 'rsarray._core.fromnumeric' has no "
28
+ f"attribute {name!r}")
29
+
30
+
31
+ __all__ = list(_NAMES)
@@ -0,0 +1,84 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """rsarray._core.function_base 兼容实现(文档工具)。
3
+
4
+ ``add_newdoc`` 与 2.x 行为一致:文档无法写入时静默忽略,
5
+ 但被文档对象不存在时会抛错。
6
+ """
7
+
8
+ import inspect
9
+ import types
10
+ import warnings
11
+
12
+ __all__ = ['add_newdoc', 'add_docstring', '_add_docstring']
13
+
14
+
15
+ def _needs_add_docstring(obj):
16
+ """C 层对象需要 add_newdoc 补文档;纯 Python 对象不需要。"""
17
+ if isinstance(obj, (type, types.FunctionType, types.MethodType)):
18
+ return False
19
+ return True
20
+
21
+
22
+ def add_docstring(func, doc, appender=None):
23
+ """设置 docstring(失败静默;``add_docstring`` 简化版)。"""
24
+ if not doc:
25
+ return
26
+ if appender:
27
+ doc = appender(doc)
28
+ try:
29
+ func.__doc__ = doc
30
+ except Exception:
31
+ pass
32
+
33
+
34
+ def _add_docstring(obj, doc, warn_on_python):
35
+ doc = inspect.cleandoc(doc)
36
+
37
+ if warn_on_python and not _needs_add_docstring(obj):
38
+ warnings.warn(
39
+ f"add_newdoc was used on a pure-python object {obj}. "
40
+ "Prefer to attach it directly to the source.",
41
+ UserWarning, stacklevel=3)
42
+
43
+ # 对类型尝试直接赋值 __doc__(heap type 可行;静态类型静默失败)。
44
+ if isinstance(obj, type):
45
+ head, sep, body = doc.partition("\n--\n\n")
46
+ try:
47
+ obj.__doc__ = body if sep else doc
48
+ except Exception:
49
+ pass
50
+ else:
51
+ if not sep:
52
+ return
53
+ doc = head + sep
54
+
55
+ try:
56
+ add_docstring(obj, doc)
57
+ except Exception:
58
+ pass
59
+
60
+
61
+ def add_newdoc(place, obj, doc, warn_on_python=True):
62
+ """为既有对象附加文档(``add_newdoc`` 兼容)。
63
+
64
+ Parameters
65
+ ----------
66
+ place : str
67
+ 模块的绝对点分名(如 "rsarray._core")。
68
+ obj : str
69
+ 对象名(通常是类或函数名)。
70
+ doc : str | tuple | list
71
+ 字符串直接作为文档;元组 ``(attr, docstring)`` 作用于对象的
72
+ 属性;列表则逐项应用。
73
+ warn_on_python : bool
74
+ 对纯 Python 对象使用时是否告警。
75
+ """
76
+ new = getattr(__import__(place, globals(), {}, [obj]), obj)
77
+ if isinstance(doc, str):
78
+ _add_docstring(new, doc, warn_on_python)
79
+ elif isinstance(doc, tuple):
80
+ attr, docstring = doc
81
+ _add_docstring(getattr(new, attr), docstring, warn_on_python)
82
+ elif isinstance(doc, list):
83
+ for attr, docstring in doc:
84
+ _add_docstring(getattr(new, attr), docstring, warn_on_python)