rsnumpy 1.0.6__tar.gz → 1.1.3__tar.gz
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.
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/.gitignore +3 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/Cargo.lock +66 -13
- rsnumpy-1.1.3/Cargo.toml +49 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/PKG-INFO +186 -22
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/README.md +185 -21
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/build_wheel.sh +12 -12
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/pyproject.toml +1 -1
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/__init__.py +819 -99
- rsnumpy-1.1.3/python/rsnumpy/_extra.py +2831 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/array_methods.py +2 -1
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/array_ops.py +56 -14
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/linalg/__init__.py +14 -3
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/random/__init__.py +12 -7
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/statistics.py +9 -18
- rsnumpy-1.1.3/src/arithmetic/mod.rs +47 -0
- rsnumpy-1.1.3/src/bitwise/mod.rs +92 -0
- rsnumpy-1.1.3/src/buffer/mod.rs +271 -0
- rsnumpy-1.1.3/src/creation/mod.rs +284 -0
- rsnumpy-1.1.3/src/formatting/mod.rs +229 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/src/indexing.rs +88 -47
- rsnumpy-1.1.3/src/io/mod.rs +395 -0
- rsnumpy-1.1.3/src/lib.rs +2025 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/src/linalg.rs +58 -186
- rsnumpy-1.1.3/src/logic/mod.rs +167 -0
- rsnumpy-1.1.3/src/manipulation/mod.rs +735 -0
- rsnumpy-1.1.3/src/mathematics/mod.rs +309 -0
- rsnumpy-1.1.3/src/poly/mod.rs +312 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/src/random.rs +83 -51
- rsnumpy-1.1.3/src/searching/mod.rs +304 -0
- rsnumpy-1.1.3/src/setops/mod.rs +433 -0
- rsnumpy-1.1.3/src/sorting/mod.rs +346 -0
- rsnumpy-1.1.3/src/statistics/mod.rs +883 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/test/run_test.py +339 -3
- rsnumpy-1.1.3/test/simple.csv +5 -0
- rsnumpy-1.1.3/test/test_new.txt +3777 -0
- rsnumpy-1.0.6/Cargo.toml +0 -42
- rsnumpy-1.0.6/src/lib.rs +0 -6092
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/.github/workflows/ci.yml +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/.github/workflows/release.yml +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/LICENSE +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/RELEASE_NOTES.md +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/char.py +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/io.py +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/math_functions.py +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/matlib.py +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/python/rsnumpy/polynomial/__init__.py +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/rust-toolchain.toml +0 -0
- {rsnumpy-1.0.6 → rsnumpy-1.1.3}/src/fft.rs +0 -0
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
# It is not intended for manual editing.
|
|
3
3
|
version = 4
|
|
4
4
|
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "accelerate-src"
|
|
7
|
+
version = "0.3.2"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "415ed64958754dbe991900f3940677e6a7eefb4d7367afd70d642677b0c7d19d"
|
|
10
|
+
|
|
5
11
|
[[package]]
|
|
6
12
|
name = "adler2"
|
|
7
13
|
version = "2.0.1"
|
|
@@ -25,6 +31,15 @@ version = "1.5.1"
|
|
|
25
31
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
26
32
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
27
33
|
|
|
34
|
+
[[package]]
|
|
35
|
+
name = "blas-src"
|
|
36
|
+
version = "0.10.0"
|
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
38
|
+
checksum = "b95e83dc868db96e69795c0213143095f03de9dd3252f205d4ac716e4076a7e0"
|
|
39
|
+
dependencies = [
|
|
40
|
+
"accelerate-src",
|
|
41
|
+
]
|
|
42
|
+
|
|
28
43
|
[[package]]
|
|
29
44
|
name = "block-buffer"
|
|
30
45
|
version = "0.12.1"
|
|
@@ -140,11 +155,20 @@ dependencies = [
|
|
|
140
155
|
"cfg-if",
|
|
141
156
|
]
|
|
142
157
|
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "crossbeam-channel"
|
|
160
|
+
version = "0.5.16"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "d85363c37faeca707aef026efa9f3b34d077bce547e48f770770625c6013679e"
|
|
163
|
+
dependencies = [
|
|
164
|
+
"crossbeam-utils",
|
|
165
|
+
]
|
|
166
|
+
|
|
143
167
|
[[package]]
|
|
144
168
|
name = "crossbeam-deque"
|
|
145
|
-
version = "0.8.
|
|
169
|
+
version = "0.8.7"
|
|
146
170
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
147
|
-
checksum = "
|
|
171
|
+
checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb"
|
|
148
172
|
dependencies = [
|
|
149
173
|
"crossbeam-epoch",
|
|
150
174
|
"crossbeam-utils",
|
|
@@ -152,18 +176,18 @@ dependencies = [
|
|
|
152
176
|
|
|
153
177
|
[[package]]
|
|
154
178
|
name = "crossbeam-epoch"
|
|
155
|
-
version = "0.9.
|
|
179
|
+
version = "0.9.20"
|
|
156
180
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
157
|
-
checksum = "
|
|
181
|
+
checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f"
|
|
158
182
|
dependencies = [
|
|
159
183
|
"crossbeam-utils",
|
|
160
184
|
]
|
|
161
185
|
|
|
162
186
|
[[package]]
|
|
163
187
|
name = "crossbeam-utils"
|
|
164
|
-
version = "0.8.
|
|
188
|
+
version = "0.8.22"
|
|
165
189
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
166
|
-
checksum = "
|
|
190
|
+
checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17"
|
|
167
191
|
|
|
168
192
|
[[package]]
|
|
169
193
|
name = "crypto-common"
|
|
@@ -286,6 +310,12 @@ version = "0.5.0"
|
|
|
286
310
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
287
311
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
288
312
|
|
|
313
|
+
[[package]]
|
|
314
|
+
name = "hermit-abi"
|
|
315
|
+
version = "0.5.2"
|
|
316
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
317
|
+
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
|
318
|
+
|
|
289
319
|
[[package]]
|
|
290
320
|
name = "hmac"
|
|
291
321
|
version = "0.13.0"
|
|
@@ -384,14 +414,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
384
414
|
checksum = "a06de3016e9fae57a36fd14dba131fccf49f74b40b7fbdb472f96e361ec71a08"
|
|
385
415
|
dependencies = [
|
|
386
416
|
"autocfg",
|
|
417
|
+
"num_cpus",
|
|
418
|
+
"once_cell",
|
|
387
419
|
"rawpointer",
|
|
420
|
+
"thread-tree",
|
|
388
421
|
]
|
|
389
422
|
|
|
390
423
|
[[package]]
|
|
391
424
|
name = "memchr"
|
|
392
|
-
version = "2.8.
|
|
425
|
+
version = "2.8.3"
|
|
393
426
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
394
|
-
checksum = "
|
|
427
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
395
428
|
|
|
396
429
|
[[package]]
|
|
397
430
|
name = "miniz_oxide"
|
|
@@ -456,6 +489,16 @@ dependencies = [
|
|
|
456
489
|
"libm",
|
|
457
490
|
]
|
|
458
491
|
|
|
492
|
+
[[package]]
|
|
493
|
+
name = "num_cpus"
|
|
494
|
+
version = "1.17.0"
|
|
495
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
496
|
+
checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b"
|
|
497
|
+
dependencies = [
|
|
498
|
+
"hermit-abi",
|
|
499
|
+
"libc",
|
|
500
|
+
]
|
|
501
|
+
|
|
459
502
|
[[package]]
|
|
460
503
|
name = "once_cell"
|
|
461
504
|
version = "1.21.4"
|
|
@@ -656,8 +699,9 @@ dependencies = [
|
|
|
656
699
|
|
|
657
700
|
[[package]]
|
|
658
701
|
name = "rsnumpy"
|
|
659
|
-
version = "1.
|
|
702
|
+
version = "1.1.3"
|
|
660
703
|
dependencies = [
|
|
704
|
+
"blas-src",
|
|
661
705
|
"ndarray",
|
|
662
706
|
"num-complex",
|
|
663
707
|
"num-traits",
|
|
@@ -686,9 +730,9 @@ dependencies = [
|
|
|
686
730
|
|
|
687
731
|
[[package]]
|
|
688
732
|
name = "rustversion"
|
|
689
|
-
version = "1.0.
|
|
733
|
+
version = "1.0.23"
|
|
690
734
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
691
|
-
checksum = "
|
|
735
|
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
692
736
|
|
|
693
737
|
[[package]]
|
|
694
738
|
name = "serde"
|
|
@@ -802,6 +846,15 @@ dependencies = [
|
|
|
802
846
|
"syn",
|
|
803
847
|
]
|
|
804
848
|
|
|
849
|
+
[[package]]
|
|
850
|
+
name = "thread-tree"
|
|
851
|
+
version = "0.3.3"
|
|
852
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
853
|
+
checksum = "ffbd370cb847953a25954d9f63e14824a36113f8c72eecf6eccef5dc4b45d630"
|
|
854
|
+
dependencies = [
|
|
855
|
+
"crossbeam-channel",
|
|
856
|
+
]
|
|
857
|
+
|
|
805
858
|
[[package]]
|
|
806
859
|
name = "time"
|
|
807
860
|
version = "0.3.53"
|
|
@@ -930,9 +983,9 @@ dependencies = [
|
|
|
930
983
|
|
|
931
984
|
[[package]]
|
|
932
985
|
name = "zlib-rs"
|
|
933
|
-
version = "0.6.
|
|
986
|
+
version = "0.6.6"
|
|
934
987
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
935
|
-
checksum = "
|
|
988
|
+
checksum = "b142a20ec14a91d5bc708c1dc21b080c550113d8aa77afa29635673a65dd02c5"
|
|
936
989
|
|
|
937
990
|
[[package]]
|
|
938
991
|
name = "zopfli"
|
rsnumpy-1.1.3/Cargo.toml
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "rsnumpy"
|
|
3
|
+
version = "1.1.3"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
|
|
7
|
+
[lib]
|
|
8
|
+
name = "rsnumpy"
|
|
9
|
+
crate-type = ["cdylib"]
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
pyo3 = { version = "0.29.0", features = ["extension-module"] }
|
|
13
|
+
# matrixmultiply-threading:非 BLAS 平台上让纯 Rust GEMM 内核多线程并行。
|
|
14
|
+
ndarray = { version = "0.17.2", features = [
|
|
15
|
+
"rayon",
|
|
16
|
+
"serde",
|
|
17
|
+
"matrixmultiply-threading",
|
|
18
|
+
] }
|
|
19
|
+
rayon = "1.12.0"
|
|
20
|
+
rand = "0.10.2"
|
|
21
|
+
rand_distr = "0.6.0"
|
|
22
|
+
num-traits = "0.2.19"
|
|
23
|
+
rustfft = "6.4.1"
|
|
24
|
+
zip = "8.6.0"
|
|
25
|
+
num-complex = "0.4.6"
|
|
26
|
+
thiserror = "2.0.0"
|
|
27
|
+
|
|
28
|
+
# macOS:链接系统自带的 Accelerate 框架作为 BLAS 后端(无需额外安装),
|
|
29
|
+
# matmul/dot 由 ndarray 的 blas 特性自动分派到原生高性能 GEMM。
|
|
30
|
+
# 其它平台不启用 BLAS,自动回退到上面的 matrixmultiply 多线程纯 Rust 内核。
|
|
31
|
+
[target.'cfg(target_os = "macos")'.dependencies]
|
|
32
|
+
ndarray = { version = "0.17.2", features = ["blas"] }
|
|
33
|
+
blas-src = { version = "0.10", features = ["accelerate"] }
|
|
34
|
+
|
|
35
|
+
[profile.release]
|
|
36
|
+
opt-level = 3
|
|
37
|
+
lto = "fat"
|
|
38
|
+
codegen-units = 1
|
|
39
|
+
strip = "symbols"
|
|
40
|
+
|
|
41
|
+
[profile.dev]
|
|
42
|
+
opt-level = 0
|
|
43
|
+
debug = true
|
|
44
|
+
|
|
45
|
+
[lints.clippy]
|
|
46
|
+
too_many_arguments = "allow"
|
|
47
|
+
type_complexity = "allow"
|
|
48
|
+
cast_precision_loss = "allow"
|
|
49
|
+
cast_sign_loss = "allow"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rsnumpy
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.3
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -51,15 +51,19 @@ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
|
51
51
|
rsnumpy/
|
|
52
52
|
├── src/ # Rust 源码
|
|
53
53
|
│ ├── lib.rs # 核心 ndarray 与通用函数
|
|
54
|
+
│ ├── indexing.rs # 多维索引与切片
|
|
54
55
|
│ ├── fft.rs # 快速傅里叶变换
|
|
55
56
|
│ ├── linalg.rs # 线性代数
|
|
56
|
-
│ └── random.rs #
|
|
57
|
-
├── rsnumpy/
|
|
57
|
+
│ └── random.rs # 随机数生成(可复现并行采样)
|
|
58
|
+
├── python/rsnumpy/ # Python 薄包装
|
|
58
59
|
│ ├── __init__.py # 主模块,整合所有 API
|
|
59
60
|
│ ├── array_methods.py # ndarray 对象方法
|
|
60
61
|
│ ├── array_ops.py # 数组操作函数
|
|
62
|
+
│ ├── _extra.py # 补充 API(别名、nan 系列、集合运算、窗函数等)
|
|
61
63
|
│ ├── math_functions.py # 数学函数
|
|
62
64
|
│ ├── statistics.py # 统计函数
|
|
65
|
+
│ ├── char.py # 字符串数组函数
|
|
66
|
+
│ ├── matlib.py # 矩阵便捷构造
|
|
63
67
|
│ ├── io.py # 文件 I/O
|
|
64
68
|
│ ├── linalg/ # 线性代数子模块
|
|
65
69
|
│ ├── polynomial/ # 多项式子模块
|
|
@@ -283,6 +287,8 @@ print(np.random.rand(3).tolist())
|
|
|
283
287
|
print(np.random.randn(3).tolist())
|
|
284
288
|
```
|
|
285
289
|
|
|
290
|
+
> **可复现性**:相同 `seed` 保证生成相同的结果。大数组采样在 Rust 层并行执行,采用固定分块 + `splitmix64` 派生各分块的独立种子,因此**结果与线程数无关**,在不同机器上同样可复现。同一个 `Generator` 每次调用都会推进内部状态,连续调用不会产生重复序列。
|
|
291
|
+
|
|
286
292
|
#### 5.7 FFT
|
|
287
293
|
|
|
288
294
|
```python
|
|
@@ -365,6 +371,81 @@ print(np.isinf(a))
|
|
|
365
371
|
print(np.isfinite(a))
|
|
366
372
|
```
|
|
367
373
|
|
|
374
|
+
#### 5.11 日期时间与网格
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
import rsnumpy as np
|
|
378
|
+
|
|
379
|
+
# 日期时间标量(兼容 numpy.datetime64)
|
|
380
|
+
d = np.datetime64('2024-01-01')
|
|
381
|
+
delta = np.timedelta64(7, 'D') # 7 天
|
|
382
|
+
print(d + delta) # numpy.datetime64('2024-01-08')
|
|
383
|
+
print(np.datetime64('2024-01-08') - d) # numpy.timedelta64(7,'D')
|
|
384
|
+
|
|
385
|
+
# 用 datetime64/timedelta64 生成日期序列
|
|
386
|
+
days = np.arange(np.datetime64('2024-01-01'),
|
|
387
|
+
np.datetime64('2024-01-05'),
|
|
388
|
+
np.timedelta64(1, 'D'))
|
|
389
|
+
|
|
390
|
+
# 坐标网格(默认 'xy' 索引,与 NumPy 一致)
|
|
391
|
+
x = np.array([1, 2, 3])
|
|
392
|
+
y = np.array([10, 20])
|
|
393
|
+
X, Y = np.meshgrid(x, y)
|
|
394
|
+
print(X.tolist()) # [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
|
|
395
|
+
print(Y.tolist()) # [[10.0, 10.0, 10.0], [20.0, 20.0, 20.0]]
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
#### 5.12 补充 API 覆盖(对齐 NumPy 2.5.1)
|
|
399
|
+
|
|
400
|
+
在核心 Rust 原语之上,`_extra.py` 补充了约 140 个 NumPy 兼容函数,全部对照 NumPy 2.5.1 逐函数验证通过。计算密集/逐元素部分复用现有 Rust 原语,纯变形与组合类则以薄 Python 包装实现。
|
|
401
|
+
|
|
402
|
+
```python
|
|
403
|
+
import rsnumpy as np
|
|
404
|
+
|
|
405
|
+
# 三角/双曲别名(Array API 命名)
|
|
406
|
+
np.acos(1.0); np.asin(0.0); np.atan(1.0); np.atan2(1.0, 1.0)
|
|
407
|
+
np.radians(180.0); np.degrees(np.pi)
|
|
408
|
+
|
|
409
|
+
# 逐元素数学
|
|
410
|
+
np.hypot(3.0, 4.0) # 5.0
|
|
411
|
+
np.maximum([1, 5], [3, 2]) # [3, 5]
|
|
412
|
+
np.fmax([np.nan, 2], [1, np.nan]) # 忽略 NaN
|
|
413
|
+
np.logaddexp(0.0, 0.0) # 数值稳定 log(exp(a)+exp(b))
|
|
414
|
+
np.rint([0.5, 1.5, 2.5]) # 四舍六入五成双 -> [0, 2, 2]
|
|
415
|
+
np.gcd(12, 8); np.lcm(4, 6)
|
|
416
|
+
frac, whole = np.modf([1.5, 2.25])
|
|
417
|
+
|
|
418
|
+
# nan 系列归约
|
|
419
|
+
a = np.array([1.0, np.nan, 3.0])
|
|
420
|
+
np.nansum(a); np.nanmean(a); np.nanstd(a); np.nanmax(a)
|
|
421
|
+
np.nancumsum(a); np.nanargmax(a)
|
|
422
|
+
np.prod([1, 2, 3, 4]) # 24
|
|
423
|
+
|
|
424
|
+
# 集合运算
|
|
425
|
+
np.intersect1d([1, 2, 3], [2, 3, 4]) # [2, 3]
|
|
426
|
+
np.union1d([1, 2], [2, 3]) # [1, 2, 3]
|
|
427
|
+
np.setdiff1d([1, 2, 3], [2]) # [1, 3]
|
|
428
|
+
np.isin([1, 2, 5], [1, 5]) # [True, False, True]
|
|
429
|
+
uniq, counts = np.unique_counts([1, 1, 2, 3, 3, 3])
|
|
430
|
+
|
|
431
|
+
# 变形 / 组合
|
|
432
|
+
np.block([[np.eye(2), np.ones((2, 1))]])
|
|
433
|
+
np.pad([1, 2, 3], (1, 2), mode='reflect')
|
|
434
|
+
np.kron([1, 2], [1, 1])
|
|
435
|
+
np.tensordot(np.ones((2, 3)), np.ones((3, 4)), axes=1)
|
|
436
|
+
|
|
437
|
+
# 复数
|
|
438
|
+
z = np.array([1 + 2j, 3 - 1j])
|
|
439
|
+
np.real(z); np.imag(z); np.conjugate(z); np.angle(z)
|
|
440
|
+
|
|
441
|
+
# 信号 / 窗函数 / 插值
|
|
442
|
+
np.convolve([1, 2, 3], [1, 1])
|
|
443
|
+
np.interp(2.5, [1, 2, 3], [10, 20, 30])
|
|
444
|
+
np.hanning(8); np.hamming(8); np.blackman(8); np.bartlett(8)
|
|
445
|
+
np.vander([1, 2, 3], 3)
|
|
446
|
+
np.bincount([0, 1, 1, 2, 2, 2])
|
|
447
|
+
```
|
|
448
|
+
|
|
368
449
|
---
|
|
369
450
|
|
|
370
451
|
### 6. 常见问题
|
|
@@ -457,26 +538,32 @@ A: 当前版本仅支持 CPU。
|
|
|
457
538
|
**Project layout:**
|
|
458
539
|
|
|
459
540
|
```
|
|
541
|
+
|
|
460
542
|
rsnumpy/
|
|
461
|
-
├── src/
|
|
462
|
-
│
|
|
463
|
-
│
|
|
464
|
-
│
|
|
465
|
-
│
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
│
|
|
469
|
-
│
|
|
470
|
-
│
|
|
471
|
-
│
|
|
472
|
-
│
|
|
473
|
-
│
|
|
474
|
-
│
|
|
475
|
-
│
|
|
476
|
-
├──
|
|
477
|
-
├──
|
|
478
|
-
├──
|
|
479
|
-
└──
|
|
543
|
+
├── src/ # Rust source
|
|
544
|
+
│ ├── lib.rs # Core ndarray & general functions
|
|
545
|
+
│ ├── indexing.rs # Multi-dimensional indexing & slicing
|
|
546
|
+
│ ├── fft.rs # Fast Fourier Transform
|
|
547
|
+
│ ├── linalg.rs # Linear algebra
|
|
548
|
+
│ └── random.rs # Random number generation (reproducible parallel sampling)
|
|
549
|
+
├── python/rsnumpy/ # Python thin wrappers
|
|
550
|
+
│ ├── **init**.py # Main module, exports public API
|
|
551
|
+
│ ├── array_methods.py # ndarray object methods
|
|
552
|
+
│ ├── array_ops.py # Array manipulation functions
|
|
553
|
+
│ ├── _extra.py # Supplementary API (aliases, nan-reductions, set ops, windows, ...)
|
|
554
|
+
│ ├── math_functions.py # Math functions
|
|
555
|
+
│ ├── statistics.py # Statistics functions
|
|
556
|
+
│ ├── char.py # String array functions
|
|
557
|
+
│ ├── matlib.py # Matrix construction helpers
|
|
558
|
+
│ ├── io.py # File I/O
|
|
559
|
+
│ ├── linalg/ # Linear algebra submodule
|
|
560
|
+
│ ├── polynomial/ # Polynomial submodule
|
|
561
|
+
│ └── random/ # Random submodule
|
|
562
|
+
├── Cargo.toml # Rust dependencies
|
|
563
|
+
├── pyproject.toml # Python build config
|
|
564
|
+
├── build_wheel.sh # Build script
|
|
565
|
+
└── README.md # This file
|
|
566
|
+
|
|
480
567
|
```
|
|
481
568
|
|
|
482
569
|
---
|
|
@@ -692,6 +779,8 @@ print(np.random.rand(3).tolist())
|
|
|
692
779
|
print(np.random.randn(3).tolist())
|
|
693
780
|
```
|
|
694
781
|
|
|
782
|
+
> **Reproducibility**: the same `seed` always produces the same result. Large-array sampling runs in parallel on the Rust side using fixed-size chunks with per-chunk seeds derived via `splitmix64`, so results are **independent of the thread count** and reproducible across machines. Each call on a `Generator` advances its internal state, so consecutive calls never repeat the same sequence.
|
|
783
|
+
|
|
695
784
|
#### 5.7 FFT
|
|
696
785
|
|
|
697
786
|
```python
|
|
@@ -774,6 +863,81 @@ print(np.isinf(a))
|
|
|
774
863
|
print(np.isfinite(a))
|
|
775
864
|
```
|
|
776
865
|
|
|
866
|
+
#### 5.11 Datetime & meshgrid
|
|
867
|
+
|
|
868
|
+
```python
|
|
869
|
+
import rsnumpy as np
|
|
870
|
+
|
|
871
|
+
# Datetime scalars (compatible with numpy.datetime64)
|
|
872
|
+
d = np.datetime64('2024-01-01')
|
|
873
|
+
delta = np.timedelta64(7, 'D') # 7 days
|
|
874
|
+
print(d + delta) # numpy.datetime64('2024-01-08')
|
|
875
|
+
print(np.datetime64('2024-01-08') - d) # numpy.timedelta64(7,'D')
|
|
876
|
+
|
|
877
|
+
# Generate a date range with datetime64/timedelta64
|
|
878
|
+
days = np.arange(np.datetime64('2024-01-01'),
|
|
879
|
+
np.datetime64('2024-01-05'),
|
|
880
|
+
np.timedelta64(1, 'D'))
|
|
881
|
+
|
|
882
|
+
# Coordinate grids (default 'xy' indexing, matching NumPy)
|
|
883
|
+
x = np.array([1, 2, 3])
|
|
884
|
+
y = np.array([10, 20])
|
|
885
|
+
X, Y = np.meshgrid(x, y)
|
|
886
|
+
print(X.tolist()) # [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
|
|
887
|
+
print(Y.tolist()) # [[10.0, 10.0, 10.0], [20.0, 20.0, 20.0]]
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
#### 5.12 Supplementary API Coverage (aligned with NumPy 2.5.1)
|
|
891
|
+
|
|
892
|
+
On top of the core Rust primitives, `_extra.py` adds ~140 NumPy-compatible functions, each verified against NumPy 2.5.1. Compute-heavy / element-wise paths reuse existing Rust primitives, while pure reshaping and composition helpers are implemented as thin Python wrappers.
|
|
893
|
+
|
|
894
|
+
```python
|
|
895
|
+
import rsnumpy as np
|
|
896
|
+
|
|
897
|
+
# Trig/hyperbolic aliases (Array API names)
|
|
898
|
+
np.acos(1.0); np.asin(0.0); np.atan(1.0); np.atan2(1.0, 1.0)
|
|
899
|
+
np.radians(180.0); np.degrees(np.pi)
|
|
900
|
+
|
|
901
|
+
# Element-wise math
|
|
902
|
+
np.hypot(3.0, 4.0) # 5.0
|
|
903
|
+
np.maximum([1, 5], [3, 2]) # [3, 5]
|
|
904
|
+
np.fmax([np.nan, 2], [1, np.nan]) # NaN-ignoring
|
|
905
|
+
np.logaddexp(0.0, 0.0) # numerically stable log(exp(a)+exp(b))
|
|
906
|
+
np.rint([0.5, 1.5, 2.5]) # round-half-to-even -> [0, 2, 2]
|
|
907
|
+
np.gcd(12, 8); np.lcm(4, 6)
|
|
908
|
+
frac, whole = np.modf([1.5, 2.25])
|
|
909
|
+
|
|
910
|
+
# nan-reductions
|
|
911
|
+
a = np.array([1.0, np.nan, 3.0])
|
|
912
|
+
np.nansum(a); np.nanmean(a); np.nanstd(a); np.nanmax(a)
|
|
913
|
+
np.nancumsum(a); np.nanargmax(a)
|
|
914
|
+
np.prod([1, 2, 3, 4]) # 24
|
|
915
|
+
|
|
916
|
+
# Set operations
|
|
917
|
+
np.intersect1d([1, 2, 3], [2, 3, 4]) # [2, 3]
|
|
918
|
+
np.union1d([1, 2], [2, 3]) # [1, 2, 3]
|
|
919
|
+
np.setdiff1d([1, 2, 3], [2]) # [1, 3]
|
|
920
|
+
np.isin([1, 2, 5], [1, 5]) # [True, False, True]
|
|
921
|
+
uniq, counts = np.unique_counts([1, 1, 2, 3, 3, 3])
|
|
922
|
+
|
|
923
|
+
# Reshaping / composition
|
|
924
|
+
np.block([[np.eye(2), np.ones((2, 1))]])
|
|
925
|
+
np.pad([1, 2, 3], (1, 2), mode='reflect')
|
|
926
|
+
np.kron([1, 2], [1, 1])
|
|
927
|
+
np.tensordot(np.ones((2, 3)), np.ones((3, 4)), axes=1)
|
|
928
|
+
|
|
929
|
+
# Complex
|
|
930
|
+
z = np.array([1 + 2j, 3 - 1j])
|
|
931
|
+
np.real(z); np.imag(z); np.conjugate(z); np.angle(z)
|
|
932
|
+
|
|
933
|
+
# Signal / windows / interpolation
|
|
934
|
+
np.convolve([1, 2, 3], [1, 1])
|
|
935
|
+
np.interp(2.5, [1, 2, 3], [10, 20, 30])
|
|
936
|
+
np.hanning(8); np.hamming(8); np.blackman(8); np.bartlett(8)
|
|
937
|
+
np.vander([1, 2, 3], 3)
|
|
938
|
+
np.bincount([0, 1, 1, 2, 2, 2])
|
|
939
|
+
```
|
|
940
|
+
|
|
777
941
|
---
|
|
778
942
|
|
|
779
943
|
### 6. FAQ
|