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.
- rsarray/__init__.py +12028 -0
- rsarray/_core/__init__.py +213 -0
- rsarray/_core/_exceptions.py +83 -0
- rsarray/_core/_internal.py +331 -0
- rsarray/_core/_multiarray_tests.py +129 -0
- rsarray/_core/_multiarray_umath.py +121 -0
- rsarray/_core/_rational_tests.py +52 -0
- rsarray/_core/arrayprint.py +36 -0
- rsarray/_core/fromnumeric.py +31 -0
- rsarray/_core/function_base.py +84 -0
- rsarray/_core/multiarray.py +385 -0
- rsarray/_core/numeric.py +28 -0
- rsarray/_core/numerictypes.py +233 -0
- rsarray/_core/records.py +14 -0
- rsarray/_core/shape_base.py +23 -0
- rsarray/_core/strings.py +78 -0
- rsarray/_core/umath.py +176 -0
- rsarray/_dtypes.py +1229 -0
- rsarray/_extra.py +6621 -0
- rsarray/_typing.py +24 -0
- rsarray/array_methods.py +1224 -0
- rsarray/array_ops.py +1585 -0
- rsarray/char.py +1590 -0
- rsarray/exceptions.py +45 -0
- rsarray/fft/__init__.py +231 -0
- rsarray/io.py +453 -0
- rsarray/lib/__init__.py +102 -0
- rsarray/lib/_function_base_impl.py +37 -0
- rsarray/lib/_index_tricks_impl.py +98 -0
- rsarray/lib/_nanfunctions_impl.py +1637 -0
- rsarray/lib/_stride_tricks_impl.py +110 -0
- rsarray/lib/recfunctions.py +1222 -0
- rsarray/lib/stride_tricks.py +106 -0
- rsarray/linalg/__init__.py +2603 -0
- rsarray/linalg/_linalg.py +91 -0
- rsarray/linalg/_pylinalg.py +1008 -0
- rsarray/linalg/lapack_lite.py +13 -0
- rsarray/ma/__init__.py +92 -0
- rsarray/ma/core.py +1385 -0
- rsarray/ma/extras.py +711 -0
- rsarray/ma/mrecords.py +144 -0
- rsarray/math_functions.py +965 -0
- rsarray/matlib.py +67 -0
- rsarray/num_core.cp315-win_amd64.pyd +0 -0
- rsarray/polynomial/__init__.py +148 -0
- rsarray/polynomial/_npcompat.py +721 -0
- rsarray/polynomial/polynomial.py +1082 -0
- rsarray/random/__init__.py +2266 -0
- rsarray/random/_distributions.py +773 -0
- rsarray/rec.py +207 -0
- rsarray/statistics.py +1360 -0
- rsarray/strings.py +349 -0
- rsarray/typing/__init__.py +26 -0
- rsarray-1.2.10.dist-info/METADATA +280 -0
- rsarray-1.2.10.dist-info/RECORD +59 -0
- rsarray-1.2.10.dist-info/WHEEL +4 -0
- rsarray-1.2.10.dist-info/licenses/LICENSE +21 -0
- rsarray-1.2.10.dist-info/licenses/NOTICE +7 -0
- rsarray-1.2.10.dist-info/sboms/rsarray.cyclonedx.json +2789 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
"""Stride-based view helpers (a compatible subset of `lib.stride_tricks`).
|
|
3
|
+
|
|
4
|
+
`rsarray` arrays always own one contiguous row-major buffer, so a true
|
|
5
|
+
zero-copy *view* with arbitrary strides is not representable here the way it is
|
|
6
|
+
in . `as_strided` therefore gathers into a fresh array.
|
|
7
|
+
|
|
8
|
+
The important consequence is about **negative strides that reach before the
|
|
9
|
+
start of the array you pass**. reads that memory from the parent buffer,
|
|
10
|
+
because `parent[k:]` is a view sharing storage. In rsarray basic slicing copies
|
|
11
|
+
and `.base` is `None`, so the earlier elements simply are not reachable; the
|
|
12
|
+
caller has the start of the new copy and nothing behind it. Such accesses are
|
|
13
|
+
rejected with a `ValueError` naming the offending offset, rather than silently
|
|
14
|
+
wrapping around Python-style into the tail of the buffer.
|
|
15
|
+
|
|
16
|
+
Reads that stay inside the array -- including backwards traversal via a
|
|
17
|
+
negative stride, as long as the offsets do not go below zero -- behave exactly
|
|
18
|
+
as the reference implementation's.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import rsarray as np
|
|
22
|
+
|
|
23
|
+
__all__ = ['as_strided']
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def as_strided(x, shape=None, strides=None, subok=False, writeable=True,
|
|
27
|
+
check_bounds=True):
|
|
28
|
+
"""Create a strided array from an existing one.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
x : array_like
|
|
33
|
+
Array whose underlying buffer supplies the values.
|
|
34
|
+
shape : sequence of int, optional
|
|
35
|
+
Shape of the result. Defaults to `x.shape`.
|
|
36
|
+
strides : sequence of int, optional
|
|
37
|
+
Strides of the result **in bytes**, -style. Defaults to the
|
|
38
|
+
C-contiguous strides of `shape`.
|
|
39
|
+
subok : bool, optional
|
|
40
|
+
Accepted for compatibility; rsarray has no subclass hierarchy.
|
|
41
|
+
writeable : bool, optional
|
|
42
|
+
Accepted for compatibility. The result owns its memory, so it is
|
|
43
|
+
always writeable and writes never reach `x`.
|
|
44
|
+
check_bounds : bool, optional
|
|
45
|
+
Accepted for compatibility. Bounds are always checked
|
|
46
|
+
(out-of-range strides raise ValueError below).
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
out : rsarray.ndarray
|
|
51
|
+
A new array with the requested shape, gathered from `x`.
|
|
52
|
+
|
|
53
|
+
Raises
|
|
54
|
+
------
|
|
55
|
+
ValueError
|
|
56
|
+
If the strides reach outside `x`, which for negative strides means they
|
|
57
|
+
reach before its start. See the module docstring.
|
|
58
|
+
"""
|
|
59
|
+
_ = check_bounds
|
|
60
|
+
shape = tuple(int(s) for s in (x.shape if shape is None else shape))
|
|
61
|
+
strides = tuple(int(s) for s in (x.strides if strides is None else strides))
|
|
62
|
+
if len(shape) != len(strides):
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f'strides and shape must have the same length, got '
|
|
65
|
+
f'{len(strides)} and {len(shape)}')
|
|
66
|
+
|
|
67
|
+
itemsize = int(x.itemsize)
|
|
68
|
+
# Element-count steps; a stride that is not a whole number of elements
|
|
69
|
+
# cannot be walked element-wise at all. Strides on length-1 axes are
|
|
70
|
+
# never walked (offset contribution is always 0), so 's "relaxed
|
|
71
|
+
# strides" allow arbitrary values there — skip the check for them.
|
|
72
|
+
for value, dim in zip(strides, shape):
|
|
73
|
+
if dim > 1 and value % itemsize != 0:
|
|
74
|
+
raise ValueError(
|
|
75
|
+
f'stride {value} is not a multiple of the itemsize '
|
|
76
|
+
f'{itemsize} of dtype {x.dtype}')
|
|
77
|
+
steps = [value // itemsize for value in strides]
|
|
78
|
+
|
|
79
|
+
flat = np.asarray(x).ravel().tolist()
|
|
80
|
+
size = len(flat)
|
|
81
|
+
total = 1
|
|
82
|
+
for axis in shape:
|
|
83
|
+
total *= axis
|
|
84
|
+
|
|
85
|
+
values = []
|
|
86
|
+
for index in range(total):
|
|
87
|
+
offset = 0
|
|
88
|
+
remainder = index
|
|
89
|
+
for axis in reversed(range(len(shape))):
|
|
90
|
+
remainder, along = divmod(remainder, shape[axis])
|
|
91
|
+
offset += along * steps[axis]
|
|
92
|
+
if offset < 0:
|
|
93
|
+
raise ValueError(
|
|
94
|
+
f'strided access reaches element {offset}, before the start of '
|
|
95
|
+
f'the array. would serve that from the parent buffer, '
|
|
96
|
+
f'but rsarray slicing copies, so there is nothing there to '
|
|
97
|
+
f'read; build those values explicitly or pass an array whose '
|
|
98
|
+
f'own storage begins further back.')
|
|
99
|
+
if offset >= size:
|
|
100
|
+
raise ValueError(
|
|
101
|
+
f'strided access reaches element {offset}, past the end of the '
|
|
102
|
+
f'array holding {size} elements.')
|
|
103
|
+
values.append(flat[offset])
|
|
104
|
+
|
|
105
|
+
# 保留输入 dtype(asarray 从 Python 值推断会得 float64,须显式回投到 x.dtype)
|
|
106
|
+
return np.asarray(values).reshape(shape).astype(x.dtype)
|