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,91 @@
1
+ # SPDX-License-Identifier: MIT
2
+ """linalg._linalg 兼容实现(私有算法)。
3
+
4
+ multi_dot 的矩阵链乘法顺序由动态规划给出(Cormen 教材的标准
5
+ 矩阵链乘 DP)。
6
+ """
7
+
8
+
9
+ def _multi_dot_matrix_chain_order(arrays, return_costs=False):
10
+ """用 DP 求最低成本的矩阵乘法顺序(同名函数兼容)。
11
+
12
+ arrays: 1-d/2-d 数组序列(1-d 仅允许在首/末位,成本计算按
13
+ (1, n)/(n, 1) 处理)。return_costs=True 时返回 (split_table,
14
+ cost_table),均为 n×n ndarray;否则返回 split_table。
15
+ split[i][j] 为段 (i..j) 的最优切分点 k(0-based,i <= k < j);
16
+ split[i][i] = i;严格上三角(i<j)有效。
17
+ """
18
+ import rsarray as np
19
+ n = len(arrays)
20
+ m = [[0] * n for _ in range(n)]
21
+ s = [[i for i in range(n)] for _ in range(n)]
22
+ if n >= 2:
23
+ dims = [a.shape[0] if a.ndim == 2 else 1 for a in arrays]
24
+ dims.append(arrays[-1].shape[-1])
25
+ for l in range(2, n + 1):
26
+ for i in range(n - l + 1):
27
+ j = i + l - 1
28
+ best = None
29
+ best_k = i
30
+ for k in range(i, j):
31
+ val = m[i][k] + m[k + 1][j] + \
32
+ dims[i] * dims[k + 1] * dims[j + 1]
33
+ if best is None or val < best:
34
+ best = val
35
+ best_k = k
36
+ m[i][j] = best
37
+ s[i][j] = best_k
38
+ s_arr = np.array(s, dtype=np.int64)
39
+ if return_costs:
40
+ return s_arr, np.array(m)
41
+ return s_arr
42
+
43
+
44
+ def multi_dot(arrays, out=None):
45
+ """按最优顺序连乘多个矩阵(linalg.multi_dot 兼容)。
46
+
47
+ arrays: list/tuple,至少 2 个(不足 → ValueError);每个元素
48
+ 1-d/2-d,1-d 仅允许在首/末位;维数不匹配 → ValueError。
49
+ out: 给定时原地写入并返回该对象本身(ret is out)。
50
+ """
51
+ import rsarray as np
52
+ if not isinstance(arrays, (list, tuple)) or len(arrays) < 2:
53
+ raise ValueError("Expected an array-like of two or more matrices.")
54
+ arrays = [np.asanyarray(a) for a in arrays]
55
+ nd = len(arrays)
56
+ for i, a in enumerate(arrays):
57
+ if a.ndim > 2:
58
+ raise ValueError(
59
+ "Each array must be 1-dimensional or 2-dimensional")
60
+ if a.ndim == 1 and i not in (0, nd - 1):
61
+ raise ValueError(
62
+ "Each array must be 2-dimensional, except possibly the "
63
+ "first and last, which may be 1-dimensional as well")
64
+ for i in range(nd - 1):
65
+ a = arrays[i]
66
+ b = arrays[i + 1]
67
+ n_a = a.shape[1] if a.ndim == 2 else a.shape[0]
68
+ if n_a != b.shape[0]:
69
+ raise ValueError("Matrix multiplication dimension mismatch")
70
+
71
+ if nd == 2:
72
+ res = np.dot(arrays[0], arrays[1])
73
+ else:
74
+ s, _ = _multi_dot_matrix_chain_order(arrays, return_costs=True)
75
+
76
+ def rec(i, j):
77
+ if i == j:
78
+ return arrays[i]
79
+ k = int(s[i, j])
80
+ return np.dot(rec(i, k), rec(k + 1, j))
81
+
82
+ res = rec(0, nd - 1)
83
+
84
+ if out is not None:
85
+ out_arr = out if hasattr(out, '_array') else np.asanyarray(out)
86
+ out_arr[...] = res
87
+ return out_arr
88
+ return res
89
+
90
+
91
+ __all__ = ['_multi_dot_matrix_chain_order', 'multi_dot']