PyPyNum 1.18.0__py3-none-any.whl → 1.18.1__py3-none-any.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.
- pypynum/README.md +48 -106
- pypynum/__init__.py +2 -2
- pypynum/arrays.py +81 -36
- pypynum/dists.py +155 -174
- pypynum/geoms.py +306 -83
- pypynum/hypcmpnms.py +59 -0
- pypynum/images.py +2 -2
- pypynum/matrices.py +114 -80
- pypynum/numbers.py +26 -14
- pypynum/utils.py +43 -33
- pypynum/vectors.py +7 -7
- {pypynum-1.18.0.dist-info → pypynum-1.18.1.dist-info}/METADATA +49 -107
- {pypynum-1.18.0.dist-info → pypynum-1.18.1.dist-info}/RECORD +15 -15
- {pypynum-1.18.0.dist-info → pypynum-1.18.1.dist-info}/WHEEL +0 -0
- {pypynum-1.18.0.dist-info → pypynum-1.18.1.dist-info}/top_level.txt +0 -0
pypynum/README.md
CHANGED
|
@@ -19,7 +19,7 @@ science, and ML, it offers efficient, general-purpose tools.
|
|
|
19
19
|
[](https://pepy.tech/project/pypynum)
|
|
20
20
|
[](https://pepy.tech/project/pypynum)
|
|
21
21
|
|
|
22
|
-
## PyPyNum | Version -> 1.18.
|
|
22
|
+
## PyPyNum | Version -> 1.18.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
@@ -148,70 +148,10 @@ Python interpreter and run it!
|
|
|
148
148
|
|
|
149
149
|
### Functional Changes Compared to the Previous Version
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
1. `arrays` Module
|
|
157
|
-
a. Fixed reflection operation errors in the `Array` class.
|
|
158
|
-
|
|
159
|
-
2. `ciphers` Module
|
|
160
|
-
a. The `base_64` function's input parameter and return type have been changed from `str` to `bytes`.
|
|
161
|
-
|
|
162
|
-
3. `groups` Module
|
|
163
|
-
a. The `Group` class has been refactored and new available methods have been added.
|
|
164
|
-
b. The `group` function now accepts an additional `operation` parameter.
|
|
165
|
-
|
|
166
|
-
4. `images` Module
|
|
167
|
-
a. Added a new class `JPEG` for JPEG image handling.
|
|
168
|
-
b. Added JPEG processing functions: `jpeg_adjust_qtable`, `jpeg_category`, `jpeg_channel_encoding`,
|
|
169
|
-
`jpeg_chroma_dc_huff`, `jpeg_dct8x8`, `jpeg_decode_pixels`, `jpeg_encode_pixels`, `jpeg_luma_dc_huff`,
|
|
170
|
-
`jpeg_rle_decoding`, `jpeg_rle_encoding`, `jpeg_split_pixels`, and `jpeg_zigzag`.
|
|
171
|
-
c. Added color space conversion functions `rgb2ycbcr` and `ycbcr2rgb` (which are JPEG-related functions).
|
|
172
|
-
d. Added `entropy` function (which is a PNG function).
|
|
173
|
-
e. Added PNG filter functions `png_apply_filter` and `png_reverse_filter`, allowing the `apply_filter` parameter
|
|
174
|
-
to be specified during writing to compress the generated file size.
|
|
175
|
-
|
|
176
|
-
5. `kernels` Module
|
|
177
|
-
a. Added `matmul8x8kernel` function for 8x8 matrix multiplication kernel operations.
|
|
178
|
-
|
|
179
|
-
6. `maths` Module
|
|
180
|
-
a. Added `dsigmoid` function.
|
|
181
|
-
b. Updated `sumprod` function with a new `floating` parameter.
|
|
182
|
-
|
|
183
|
-
7. `matrices` Module
|
|
184
|
-
a. Added `dctmtx` function to generate a discrete cosine transform matrix.
|
|
185
|
-
|
|
186
|
-
8. `numbers` Module
|
|
187
|
-
a. Added `round_sigfig` function.
|
|
188
|
-
b. Added `words2int` function to convert English words to integers.
|
|
189
|
-
|
|
190
|
-
9. `plotting` Module
|
|
191
|
-
a. Renamed the `color` function to `colortext`.
|
|
192
|
-
|
|
193
|
-
10. `seqs` Module
|
|
194
|
-
a. Updated `stirling1` function with a new `sign` parameter.
|
|
195
|
-
|
|
196
|
-
11. `special` Module
|
|
197
|
-
a. Added `ellipe` and `ellipk` functions for complete elliptic integrals.
|
|
198
|
-
|
|
199
|
-
12. `symbols` Module
|
|
200
|
-
a. Added `Expr` class.
|
|
201
|
-
b. Added `build_expr_tree`, `infix2postfix`, and `tokenize` functions.
|
|
202
|
-
c. The `parse_expr` function now returns an `Expr` object (previously returned a `list`).
|
|
203
|
-
|
|
204
|
-
13. `ufuncs` Module
|
|
205
|
-
a. Renamed comparison functions to follow more explicit naming conventions:
|
|
206
|
-
i. `eq` renamed to `equal`
|
|
207
|
-
ii. `ge` renamed to `greater_equal`
|
|
208
|
-
iii. `gt` renamed to `greater_than`
|
|
209
|
-
iv. `le` renamed to `less_equal`
|
|
210
|
-
v. `lt` renamed to `less_than`
|
|
211
|
-
vi. `ne` renamed to `not_equal`
|
|
212
|
-
|
|
213
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
214
|
-
```
|
|
151
|
+
> 1. The `hypcmpnms` module added hypercomplex exponential and logarithmic operations.
|
|
152
|
+
> 2. The `dists` module fixed all calculation errors.
|
|
153
|
+
> 3. The `geoms` module fixed calculation errors and added more features.
|
|
154
|
+
> 4. The `utils` module fixed calculation errors in the `IntervalSet` class.
|
|
215
155
|
|
|
216
156
|
### Run Time Test
|
|
217
157
|
|
|
@@ -239,23 +179,23 @@ Python interpreter version
|
|
|
239
179
|
PyPyNum
|
|
240
180
|
├── arrays
|
|
241
181
|
│ ├── CLASS
|
|
242
|
-
│ │ ├── Array(object)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
182
|
+
│ │ ├── Array(object)/__init__(self: Any, data: Any, check: Any, dtype: Any) -> Any
|
|
243
183
|
│ │ └── BoolArray(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
244
184
|
│ └── FUNCTION
|
|
245
|
-
│ ├── array(data: Any) -> Any
|
|
246
|
-
│ ├── asarray(data: Any) -> Any
|
|
185
|
+
│ ├── array(data: Any, dtype: Any) -> Any
|
|
186
|
+
│ ├── asarray(data: Any, dtype: Any) -> Any
|
|
247
187
|
│ ├── aslist(data: Any) -> Any
|
|
248
188
|
│ ├── boolarray(data: Any) -> Any
|
|
249
|
-
│ ├── fill(shape: typing.
|
|
250
|
-
│ ├── full(shape: typing.
|
|
251
|
-
│ ├── full_like(a: typing.Any, fill_value: typing.Any, rtype: typing.Callable) -> typing.Any
|
|
189
|
+
│ ├── fill(shape: typing.Sequence, sequence: typing.Sequence, repeat: bool, pad: typing.Any, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
190
|
+
│ ├── full(shape: typing.Sequence, fill_value: typing.Any, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
191
|
+
│ ├── full_like(a: typing.Any, fill_value: typing.Any, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
252
192
|
│ ├── get_shape(data: Any) -> Any
|
|
253
193
|
│ ├── is_valid_array(_array: Any, _shape: Any) -> Any
|
|
254
|
-
│ ├── ones(shape: typing.
|
|
255
|
-
│ ├── ones_like(a: typing.Any, rtype: typing.Callable) -> typing.Any
|
|
194
|
+
│ ├── ones(shape: typing.Sequence, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
195
|
+
│ ├── ones_like(a: typing.Any, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
256
196
|
│ ├── tensorproduct(tensors: pypynum.arrays.Array) -> pypynum.arrays.Array
|
|
257
|
-
│ ├── zeros(shape: typing.
|
|
258
|
-
│ └── zeros_like(a: typing.Any, rtype: typing.Callable) -> typing.Any
|
|
197
|
+
│ ├── zeros(shape: typing.Sequence, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
198
|
+
│ └── zeros_like(a: typing.Any, rtype: typing.Callable, dtype: type) -> typing.Any
|
|
259
199
|
├── chars
|
|
260
200
|
│ ├── CLASS
|
|
261
201
|
│ └── FUNCTION
|
|
@@ -297,7 +237,7 @@ PyPyNum
|
|
|
297
237
|
├── dists
|
|
298
238
|
│ ├── CLASS
|
|
299
239
|
│ └── FUNCTION
|
|
300
|
-
│ ├── beta_pdf(x: Any,
|
|
240
|
+
│ ├── beta_pdf(x: Any, alpha: Any, beta: Any) -> Any
|
|
301
241
|
│ ├── binom_pmf(k: Any, n: Any, p: Any) -> Any
|
|
302
242
|
│ ├── cauchy_cdf(x: Any, x0: Any, gamma: Any) -> Any
|
|
303
243
|
│ ├── cauchy_pdf(x: Any, x0: Any, gamma: Any) -> Any
|
|
@@ -308,22 +248,22 @@ PyPyNum
|
|
|
308
248
|
│ ├── f_pdf(x: Any, dfnum: Any, dfden: Any) -> Any
|
|
309
249
|
│ ├── gamma_pdf(x: Any, shape: Any, scale: Any) -> Any
|
|
310
250
|
│ ├── geometric_pmf(k: Any, p: Any) -> Any
|
|
311
|
-
│ ├── hypergeom_pmf(
|
|
312
|
-
│ ├── invgauss_pdf(x: Any, mu: Any,
|
|
251
|
+
│ ├── hypergeom_pmf(M: Any, n: Any, N: Any, k: Any) -> Any
|
|
252
|
+
│ ├── invgauss_pdf(x: Any, mu: Any, lam: Any) -> Any
|
|
313
253
|
│ ├── levy_pdf(x: Any, c: Any) -> Any
|
|
314
254
|
│ ├── log_logistic_cdf(x: Any, alpha: Any, beta: Any) -> Any
|
|
315
255
|
│ ├── log_logistic_pdf(x: Any, alpha: Any, beta: Any) -> Any
|
|
316
|
-
│ ├── logistic_cdf(x: Any,
|
|
317
|
-
│ ├── logistic_pdf(x: Any,
|
|
256
|
+
│ ├── logistic_cdf(x: Any, loc: Any, scale: Any) -> Any
|
|
257
|
+
│ ├── logistic_pdf(x: Any, loc: Any, scale: Any) -> Any
|
|
318
258
|
│ ├── lognorm_cdf(x: Any, mu: Any, sigma: Any) -> Any
|
|
319
|
-
│ ├── lognorm_pdf(x: Any,
|
|
259
|
+
│ ├── lognorm_pdf(x: Any, mu: Any, sigma: Any) -> Any
|
|
320
260
|
│ ├── logser_pmf(k: Any, p: Any) -> Any
|
|
321
261
|
│ ├── multinomial_pmf(k: Any, n: Any, p: Any) -> Any
|
|
322
262
|
│ ├── nbinom_pmf(k: Any, n: Any, p: Any) -> Any
|
|
323
|
-
│ ├── nhypergeom_pmf(
|
|
263
|
+
│ ├── nhypergeom_pmf(M: Any, n: Any, r: Any, k: Any) -> Any
|
|
324
264
|
│ ├── normal_cdf(x: Any, mu: Any, sigma: Any) -> Any
|
|
325
265
|
│ ├── normal_pdf(x: Any, mu: Any, sigma: Any) -> Any
|
|
326
|
-
│ ├── pareto_pdf(x: Any,
|
|
266
|
+
│ ├── pareto_pdf(x: Any, b: Any, scale: Any) -> Any
|
|
327
267
|
│ ├── poisson_pmf(k: Any, mu: Any) -> Any
|
|
328
268
|
│ ├── rayleigh_pdf(x: Any, sigma: Any) -> Any
|
|
329
269
|
│ ├── t_pdf(x: Any, df: Any) -> Any
|
|
@@ -356,6 +296,8 @@ PyPyNum
|
|
|
356
296
|
│ │ ├── Quadrilateral(object)/__init__(self: Any, a: typing.Union[list, tuple], b: typing.Union[list, tuple], c: typing.Union[list, tuple], d: typing.Union[list, tuple]) -> Any
|
|
357
297
|
│ │ └── Triangle(object)/__init__(self: Any, a: typing.Union[list, tuple], b: typing.Union[list, tuple], c: typing.Union[list, tuple]) -> Any
|
|
358
298
|
│ └── FUNCTION
|
|
299
|
+
│ ├── _rotate_point(p: Any, theta: Any, cx: Any, cy: Any) -> Any
|
|
300
|
+
│ ├── _scale_point(p: Any, k: Any, cx: Any, cy: Any) -> Any
|
|
359
301
|
│ └── distance(g1: Any, g2: Any, error: typing.Union[int, float]) -> float
|
|
360
302
|
├── graphs
|
|
361
303
|
│ ├── CLASS
|
|
@@ -546,23 +488,23 @@ PyPyNum
|
|
|
546
488
|
│ └── zeta(alpha: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
547
489
|
├── matrices
|
|
548
490
|
│ ├── CLASS
|
|
549
|
-
│ │ └── Matrix(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
491
|
+
│ │ └── Matrix(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any, dtype: Any) -> Any
|
|
550
492
|
│ └── FUNCTION
|
|
551
|
-
│ ├── cholesky(matrix: pypynum.matrices.Matrix, hermitian: bool) -> pypynum.matrices.Matrix
|
|
552
|
-
│ ├── dctmtx(n: int) -> pypynum.matrices.Matrix
|
|
553
|
-
│ ├── diag(v: typing.Any, k: int, n: int, m: int) -> typing.Any
|
|
493
|
+
│ ├── cholesky(matrix: pypynum.matrices.Matrix, hermitian: bool, dtype: Any) -> pypynum.matrices.Matrix
|
|
494
|
+
│ ├── dctmtx(n: int, dtype: Any) -> pypynum.matrices.Matrix
|
|
495
|
+
│ ├── diag(v: typing.Any, k: int, n: int, m: int, dtype: Any) -> typing.Any
|
|
554
496
|
│ ├── diag_indices(n: int, k: int, m: int) -> tuple
|
|
555
|
-
│ ├── eigen(matrix: pypynum.matrices.Matrix) -> tuple
|
|
556
|
-
│ ├── hessenberg(matrix: pypynum.matrices.Matrix) -> tuple
|
|
557
|
-
│ ├── identity(n: int, m: int) -> pypynum.matrices.Matrix
|
|
558
|
-
│ ├── lu(matrix: pypynum.matrices.Matrix) -> tuple
|
|
559
|
-
│ ├── mat(data: typing.Any) -> pypynum.matrices.Matrix
|
|
560
|
-
│ ├── perm_mat(num_rows: int, num_cols: int, row_swaps: typing.Union[list, tuple], col_swaps: typing.Union[list, tuple], rtype: typing.Callable) -> typing.Any
|
|
497
|
+
│ ├── eigen(matrix: pypynum.matrices.Matrix, dtype: Any) -> tuple
|
|
498
|
+
│ ├── hessenberg(matrix: pypynum.matrices.Matrix, dtype: Any) -> tuple
|
|
499
|
+
│ ├── identity(n: int, m: int, dtype: Any) -> pypynum.matrices.Matrix
|
|
500
|
+
│ ├── lu(matrix: pypynum.matrices.Matrix, dtype: Any) -> tuple
|
|
501
|
+
│ ├── mat(data: typing.Any, dtype: Any) -> pypynum.matrices.Matrix
|
|
502
|
+
│ ├── perm_mat(num_rows: int, num_cols: int, row_swaps: typing.Union[list, tuple], col_swaps: typing.Union[list, tuple], rtype: typing.Callable, dtype: Any) -> typing.Any
|
|
561
503
|
│ ├── perm_mat_indices(num_rows: int, num_cols: int, row_swaps: typing.Union[list, tuple], col_swaps: typing.Union[list, tuple]) -> tuple
|
|
562
|
-
│ ├── qr(matrix: pypynum.matrices.Matrix, reduce: bool) -> tuple
|
|
563
|
-
│ ├── rank_decomp(matrix: pypynum.matrices.Matrix) -> tuple
|
|
564
|
-
│ ├── rotate90(matrix: pypynum.matrices.Matrix, times: int) -> pypynum.matrices.Matrix
|
|
565
|
-
│ ├── svd(matrix: pypynum.matrices.Matrix, full: bool, calc_uv: bool) -> tuple
|
|
504
|
+
│ ├── qr(matrix: pypynum.matrices.Matrix, reduce: bool, dtype: Any) -> tuple
|
|
505
|
+
│ ├── rank_decomp(matrix: pypynum.matrices.Matrix, dtype: Any) -> tuple
|
|
506
|
+
│ ├── rotate90(matrix: pypynum.matrices.Matrix, times: int, dtype: Any) -> pypynum.matrices.Matrix
|
|
507
|
+
│ ├── svd(matrix: pypynum.matrices.Matrix, full: bool, calc_uv: bool, dtype: Any) -> tuple
|
|
566
508
|
│ ├── tril_indices(n: int, k: int, m: int) -> tuple
|
|
567
509
|
│ └── triu_indices(n: int, k: int, m: int) -> tuple
|
|
568
510
|
├── multiprec
|
|
@@ -801,7 +743,7 @@ PyPyNum
|
|
|
801
743
|
│ └── FUNCTION
|
|
802
744
|
├── vectors
|
|
803
745
|
│ ├── CLASS
|
|
804
|
-
│ │ └── Vector(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
746
|
+
│ │ └── Vector(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any, dtype: Any) -> Any
|
|
805
747
|
│ └── FUNCTION
|
|
806
748
|
│ └── vec(data: Any) -> Any
|
|
807
749
|
└── zh_cn
|
|
@@ -1066,7 +1008,7 @@ print("Value of exp(e^2):", exp_e_squared)
|
|
|
1066
1008
|
"""
|
|
1067
1009
|
Modulus of the complex1: 3.064156670102011971734464
|
|
1068
1010
|
Square root of the complex2: 1.630869996965458756791024890326755654659+0.9631646481434200567938527724670041364524i
|
|
1069
|
-
Power of complex1 raised to complex2: 0.
|
|
1011
|
+
Power of complex1 raised to complex2: 0.144632311554759549910373681032-0.17337039786352194417298867399i
|
|
1070
1012
|
Value of Euler's gamma constant: 0.577215664901532860606512090082402431042159336
|
|
1071
1013
|
Logarithm of 2 (base 10): 0.30102999566398119521373889472449302676818988146211
|
|
1072
1014
|
Value of exp(e^2): 1618.1779919126535017
|
|
@@ -1084,7 +1026,7 @@ Bessel Function of the first kind, order 0 at x=1: 0.7651976865579666
|
|
|
1084
1026
|
Modified Bessel function of the first kind, order 1 at x=1: 0.565159103992485
|
|
1085
1027
|
Hypergeometric function 0F1 at z=0.5 with b0=1: 1.5660829297563503
|
|
1086
1028
|
Hypergeometric function 1F1 at z=1 with a0=1, b0=1: 2.7182818284590455
|
|
1087
|
-
q-Pochhammer Symbol with a=2+1j, q=0.5+0.1j, n=2+1j: (-0.
|
|
1029
|
+
q-Pochhammer Symbol with a=2+1j, q=0.5+0.1j, n=2+1j: (-0.3335342940577659+1.8573191887407858j)
|
|
1088
1030
|
q-Gamma Function at n=2 with q=0.5+0.1j: (0.9999999999999989-4.953510875709033e-16j)
|
|
1089
1031
|
"""
|
|
1090
1032
|
|
|
@@ -1161,7 +1103,7 @@ print(equations.poly_eq(p))
|
|
|
1161
1103
|
print(equations.lin_eq(*m))
|
|
1162
1104
|
|
|
1163
1105
|
"""
|
|
1164
|
-
[(-1.5615528128088307-
|
|
1106
|
+
[(-1.5615528128088307-3.728101026218476e-24j), (1.0000000000000007+3.2415545137443745e-25j), (2.5615528128088294+7.352235277305158e-24j)]
|
|
1165
1107
|
[1.6666666666666665, -0.6666666666666666, -0.4444444444444444]
|
|
1166
1108
|
"""
|
|
1167
1109
|
|
|
@@ -1262,10 +1204,10 @@ print(random.randint(0, 9, [2, 3, 4]))
|
|
|
1262
1204
|
print(random.uniform(0, 9, [2, 3, 4]))
|
|
1263
1205
|
|
|
1264
1206
|
"""
|
|
1265
|
-
[[[0.
|
|
1266
|
-
[[[0.
|
|
1267
|
-
[[[
|
|
1268
|
-
[[[
|
|
1207
|
+
[[[0.18059388030329554, -0.7950286594701896, -1.6124456807502878, 1.0650032690802622], [1.231592625021916, -0.2923569307790834, 0.5743684840351643, -0.5994993318165575], [-0.4541501878112403, 0.5194701735167844, -0.41134655581914514, 2.5838345235765336]], [[-0.38027869224951916, 1.407233237769525, -1.4230691454968791, -1.098291804499891], [0.0720517812951513, 1.2716687933757764, -0.389868632414012, 0.18416602669163057], [-0.49978319823217315, 0.8789409340735714, -1.4538419291500941, -1.895514116697364]]]
|
|
1208
|
+
[[[0.3214199347664204, 0.4682526051010606, 0.8691333897517276, 0.65768740769836], [0.7632355843244432, 0.5804412886619936, 0.008332295847854443, 0.6151292129754637], [0.9795343167986345, 0.5205461670247327, 0.7248923173697739, 0.11717223436961488]], [[0.7662005170926139, 0.9714376279553422, 0.9550672285743181, 0.08793525427569937], [0.6339393968200449, 0.8301210945735973, 0.6564657233275701, 0.6220565155685059], [0.21406744938064437, 0.3047415909582225, 0.6510510008125593, 0.12269523561892148]]]
|
|
1209
|
+
[[[5, 1, 4, 9], [9, 1, 6, 2], [4, 3, 1, 9]], [[0, 9, 6, 9], [7, 8, 0, 2], [9, 8, 5, 3]]]
|
|
1210
|
+
[[[1.6943948141992893, 2.247908784078809, 8.414928873268128, 4.628393016930337], [7.572639917918929, 5.357050653981085, 8.240417270343459, 3.24879148260883], [4.771181663822661, 1.905700180078211, 3.7868896315863747, 4.2241419541638265]], [[4.635584514037156, 7.401849961502754, 0.6758543569780475, 6.101106332926675], [1.9978290038252968, 7.441511948419005, 0.10317848285562836, 5.723737686439019], [0.13415224754500865, 7.69176143777073, 2.9628506743472967, 5.077060383033804]]]
|
|
1269
1211
|
"""
|
|
1270
1212
|
|
|
1271
1213
|
print(regs.lin_reg(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1284,7 +1226,7 @@ print(tools.frange(0, 3, 0.4))
|
|
|
1284
1226
|
print(tools.linspace(0, 2.8, 8))
|
|
1285
1227
|
|
|
1286
1228
|
"""
|
|
1287
|
-
{<class 'int'>: [1], <class 'float'>: [2.3, 3.14], <class 'complex'>: [(4+5j)], <class 'str'>: ['string'], <class 'type'>: [<class 'list'>, <class 'tuple'>], <class 'bool'>: [True, False], <class 'module'>: [<module 'pypynum.tools' from 'C:\\Users\\Administrator\\PycharmProjects\\
|
|
1229
|
+
{<class 'int'>: [1], <class 'float'>: [2.3, 3.14], <class 'complex'>: [(4+5j)], <class 'str'>: ['string'], <class 'type'>: [<class 'list'>, <class 'tuple'>], <class 'bool'>: [True, False], <class 'module'>: [<module 'pypynum.tools' from 'C:\\Users\\Administrator\\PycharmProjects\\PythonProject\\pypynum\\tools.py'>]}
|
|
1288
1230
|
['Python', 6, 'NumPy', <class 'int'>, 'PyPyNum', 9, 'pypynum', True]
|
|
1289
1231
|
[0.0, 0.4, 0.8, 1.2000000000000002, 1.6, 2.0, 2.4000000000000004, 2.8000000000000003, 3.2]
|
|
1290
1232
|
[0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
|
pypynum/__init__.py
CHANGED
|
@@ -60,7 +60,7 @@ from .seqs import *
|
|
|
60
60
|
from .special import *
|
|
61
61
|
from .stattest import *
|
|
62
62
|
from .symbols import *
|
|
63
|
-
from .
|
|
63
|
+
from . import tensors
|
|
64
64
|
from .tools import *
|
|
65
65
|
from .trees import *
|
|
66
66
|
from .types import config
|
|
@@ -68,7 +68,7 @@ from .ufuncs import *
|
|
|
68
68
|
from .utils import *
|
|
69
69
|
from .vectors import *
|
|
70
70
|
|
|
71
|
-
__version__ = "1.18.
|
|
71
|
+
__version__ = "1.18.1"
|
|
72
72
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
73
73
|
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", "GitHub -> https://github.com/PythonSJL/PyPyNum", sep=" | ")
|
|
74
74
|
for key, value in tuple(globals().items()):
|
pypynum/arrays.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .types import Any, Callable,
|
|
1
|
+
from .types import Any, Callable, Sequence, ShapeError
|
|
2
2
|
|
|
3
3
|
ArrayError = ShapeError("The shape of the array is invalid")
|
|
4
4
|
MatchError = ShapeError("The shapes of the two arrays do not match")
|
|
@@ -9,11 +9,31 @@ class Array:
|
|
|
9
9
|
It is the base class of vectors and matrices, supporting operations and many statistical functions.
|
|
10
10
|
:param data: An array in the form of a list
|
|
11
11
|
:param check: Check the rationality of the input array
|
|
12
|
+
:param dtype: The data type of the elements in the array, default is object
|
|
12
13
|
"""
|
|
13
14
|
|
|
14
|
-
def __init__(self, data=None, check=True):
|
|
15
|
+
def __init__(self, data=None, check=True, dtype=object):
|
|
15
16
|
if data is None:
|
|
16
17
|
data = []
|
|
18
|
+
self.dtype = dtype
|
|
19
|
+
|
|
20
|
+
def _convert_list(data, dtype):
|
|
21
|
+
if isinstance(data, list):
|
|
22
|
+
return [_convert_list(item, dtype) for item in data]
|
|
23
|
+
else:
|
|
24
|
+
try:
|
|
25
|
+
return dtype(data)
|
|
26
|
+
except (ValueError, TypeError):
|
|
27
|
+
return data
|
|
28
|
+
|
|
29
|
+
if dtype is not object:
|
|
30
|
+
if isinstance(data, list):
|
|
31
|
+
data = _convert_list(data, dtype)
|
|
32
|
+
else:
|
|
33
|
+
try:
|
|
34
|
+
data = dtype(data)
|
|
35
|
+
except (ValueError, TypeError):
|
|
36
|
+
pass
|
|
17
37
|
self.shape = [] if data == [] else get_shape(data)
|
|
18
38
|
if check and self.shape and not isinstance(data, (int, float, complex)):
|
|
19
39
|
is_valid_array(data, self.shape)
|
|
@@ -102,7 +122,8 @@ class Array:
|
|
|
102
122
|
if isinstance(other, Array):
|
|
103
123
|
if self.shape != other.shape:
|
|
104
124
|
raise MatchError
|
|
105
|
-
return fill(self.shape, [t1 + t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
125
|
+
return fill(self.shape, [t1 + t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
126
|
+
dtype=self.dtype)
|
|
106
127
|
elif isinstance(other, (int, float, complex)):
|
|
107
128
|
from .ufuncs import add
|
|
108
129
|
return add(self, other)
|
|
@@ -113,7 +134,8 @@ class Array:
|
|
|
113
134
|
if isinstance(other, Array):
|
|
114
135
|
if self.shape != other.shape:
|
|
115
136
|
raise MatchError
|
|
116
|
-
return fill(self.shape, [t1 - t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
137
|
+
return fill(self.shape, [t1 - t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
138
|
+
dtype=self.dtype)
|
|
117
139
|
elif isinstance(other, (int, float, complex)):
|
|
118
140
|
from .ufuncs import subtract
|
|
119
141
|
return subtract(self, other)
|
|
@@ -124,7 +146,8 @@ class Array:
|
|
|
124
146
|
if isinstance(other, Array):
|
|
125
147
|
if self.shape != other.shape:
|
|
126
148
|
raise MatchError
|
|
127
|
-
return fill(self.shape, [t1 * t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
149
|
+
return fill(self.shape, [t1 * t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
150
|
+
dtype=self.dtype)
|
|
128
151
|
elif isinstance(other, (int, float, complex)):
|
|
129
152
|
from .ufuncs import multiply
|
|
130
153
|
return multiply(self, other)
|
|
@@ -135,7 +158,8 @@ class Array:
|
|
|
135
158
|
if isinstance(other, Array):
|
|
136
159
|
if self.shape != other.shape:
|
|
137
160
|
raise MatchError
|
|
138
|
-
return fill(self.shape, [t1 / t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
161
|
+
return fill(self.shape, [t1 / t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
162
|
+
dtype=self.dtype)
|
|
139
163
|
elif isinstance(other, (int, float, complex)):
|
|
140
164
|
from .ufuncs import divide
|
|
141
165
|
return divide(self, other)
|
|
@@ -146,7 +170,8 @@ class Array:
|
|
|
146
170
|
if isinstance(other, Array):
|
|
147
171
|
if self.shape != other.shape:
|
|
148
172
|
raise MatchError
|
|
149
|
-
return fill(self.shape, [t1 // t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
173
|
+
return fill(self.shape, [t1 // t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
174
|
+
dtype=self.dtype)
|
|
150
175
|
elif isinstance(other, (int, float, complex)):
|
|
151
176
|
from .ufuncs import floor_divide
|
|
152
177
|
return floor_divide(self, other)
|
|
@@ -157,7 +182,8 @@ class Array:
|
|
|
157
182
|
if isinstance(other, Array):
|
|
158
183
|
if self.shape != other.shape:
|
|
159
184
|
raise MatchError
|
|
160
|
-
return fill(self.shape, [t1 % t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self)
|
|
185
|
+
return fill(self.shape, [t1 % t2 for t1, t2 in zip(self.flatten(), other.flatten())], rtype=type(self),
|
|
186
|
+
dtype=self.dtype)
|
|
161
187
|
elif isinstance(other, (int, float, complex)):
|
|
162
188
|
from .ufuncs import modulo
|
|
163
189
|
return modulo(self, other)
|
|
@@ -177,31 +203,31 @@ class Array:
|
|
|
177
203
|
|
|
178
204
|
def __rsub__(self, other):
|
|
179
205
|
if isinstance(other, (int, float, complex)):
|
|
180
|
-
return fill(self.shape, [other - t for t in self.flatten()], rtype=type(self))
|
|
206
|
+
return fill(self.shape, [other - t for t in self.flatten()], rtype=type(self), dtype=self.dtype)
|
|
181
207
|
else:
|
|
182
208
|
raise ValueError("Another must be an array or number")
|
|
183
209
|
|
|
184
210
|
def __rtruediv__(self, other):
|
|
185
211
|
if isinstance(other, (int, float, complex)):
|
|
186
|
-
return fill(self.shape, [other / t for t in self.flatten()], rtype=type(self))
|
|
212
|
+
return fill(self.shape, [other / t for t in self.flatten()], rtype=type(self), dtype=self.dtype)
|
|
187
213
|
else:
|
|
188
214
|
raise ValueError("Another must be an array or number")
|
|
189
215
|
|
|
190
216
|
def __rfloordiv__(self, other):
|
|
191
217
|
if isinstance(other, (int, float, complex)):
|
|
192
|
-
return fill(self.shape, [other // t for t in self.flatten()], rtype=type(self))
|
|
218
|
+
return fill(self.shape, [other // t for t in self.flatten()], rtype=type(self), dtype=self.dtype)
|
|
193
219
|
else:
|
|
194
220
|
raise ValueError("Another must be an array or number")
|
|
195
221
|
|
|
196
222
|
def __rmod__(self, other):
|
|
197
223
|
if isinstance(other, (int, float, complex)):
|
|
198
|
-
return fill(self.shape, [other % t for t in self.flatten()], rtype=type(self))
|
|
224
|
+
return fill(self.shape, [other % t for t in self.flatten()], rtype=type(self), dtype=self.dtype)
|
|
199
225
|
else:
|
|
200
226
|
raise ValueError("Another must be an array or number")
|
|
201
227
|
|
|
202
228
|
def __rpow__(self, other):
|
|
203
229
|
if isinstance(other, (int, float, complex)):
|
|
204
|
-
return fill(self.shape, [other ** t for t in self.flatten()], rtype=type(self))
|
|
230
|
+
return fill(self.shape, [other ** t for t in self.flatten()], rtype=type(self), dtype=self.dtype)
|
|
205
231
|
else:
|
|
206
232
|
raise ValueError("Exponential must be an array or number")
|
|
207
233
|
|
|
@@ -245,7 +271,7 @@ class Array:
|
|
|
245
271
|
return data
|
|
246
272
|
|
|
247
273
|
def reshape(self, shape, repeat=True, pad=0):
|
|
248
|
-
return fill(shape, self.flatten(), repeat, pad, type(self))
|
|
274
|
+
return fill(shape, self.flatten(), repeat, pad, type(self), dtype=self.dtype)
|
|
249
275
|
|
|
250
276
|
def copy(self):
|
|
251
277
|
from copy import deepcopy
|
|
@@ -263,7 +289,7 @@ class Array:
|
|
|
263
289
|
else:
|
|
264
290
|
return [inner(list(_), 0) for _ in zip(*a)]
|
|
265
291
|
|
|
266
|
-
return type(self)(inner(self, axis))
|
|
292
|
+
return type(self)(inner(self, axis), dtype=self.dtype)
|
|
267
293
|
|
|
268
294
|
def sum(self, axis=None):
|
|
269
295
|
return self.basic(sum, axis)
|
|
@@ -337,8 +363,8 @@ def is_valid_array(_array, _shape):
|
|
|
337
363
|
inner(_array, _shape, len(_array), shape_len)
|
|
338
364
|
|
|
339
365
|
|
|
340
|
-
def array(data=None):
|
|
341
|
-
return Array(data)
|
|
366
|
+
def array(data=None, dtype=object):
|
|
367
|
+
return Array(data, dtype=dtype)
|
|
342
368
|
|
|
343
369
|
|
|
344
370
|
def aslist(data):
|
|
@@ -353,49 +379,65 @@ def aslist(data):
|
|
|
353
379
|
raise TypeError("Unable to convert to array type")
|
|
354
380
|
|
|
355
381
|
|
|
356
|
-
def asarray(data):
|
|
357
|
-
return Array(aslist(data))
|
|
382
|
+
def asarray(data, dtype=object):
|
|
383
|
+
return Array(aslist(data), dtype=dtype)
|
|
358
384
|
|
|
359
385
|
|
|
360
|
-
def full(shape:
|
|
386
|
+
def full(shape: Sequence, fill_value: Any, rtype: Callable = Array, dtype: type = object) -> Any:
|
|
361
387
|
def inner(data, length):
|
|
362
388
|
return fill_value if length == 0 else [inner(data[1:], length - 1) for _ in range(data[0])]
|
|
363
389
|
|
|
364
390
|
if isinstance(fill_value, list):
|
|
365
391
|
raise TypeError("The filled value cannot be a list")
|
|
392
|
+
if dtype is not object:
|
|
393
|
+
try:
|
|
394
|
+
fill_value = dtype(fill_value)
|
|
395
|
+
except (ValueError, TypeError):
|
|
396
|
+
pass
|
|
366
397
|
result = inner(shape, len(shape))
|
|
367
|
-
return result if rtype is list else rtype(result)
|
|
398
|
+
return result if rtype is list else rtype(result, dtype=dtype)
|
|
368
399
|
|
|
369
400
|
|
|
370
|
-
def full_like(a: Any, fill_value: Any, rtype: Callable = Array) -> Any:
|
|
401
|
+
def full_like(a: Any, fill_value: Any, rtype: Callable = Array, dtype: type = None) -> Any:
|
|
371
402
|
def inner(data):
|
|
372
403
|
return [inner(item) for item in data] if isinstance(data, list) else fill_value
|
|
373
404
|
|
|
374
405
|
if isinstance(fill_value, list):
|
|
375
406
|
raise TypeError("The filled value cannot be a list")
|
|
407
|
+
if dtype is None:
|
|
408
|
+
if isinstance(a, Array):
|
|
409
|
+
dtype = a.dtype
|
|
410
|
+
else:
|
|
411
|
+
dtype = object
|
|
376
412
|
if isinstance(a, Array):
|
|
377
413
|
a = a.data
|
|
414
|
+
if dtype is not object:
|
|
415
|
+
try:
|
|
416
|
+
fill_value = dtype(fill_value)
|
|
417
|
+
except (ValueError, TypeError):
|
|
418
|
+
pass
|
|
378
419
|
result = inner(a)
|
|
379
|
-
return result if rtype is list else rtype(result)
|
|
420
|
+
return result if rtype is list else rtype(result, dtype=dtype)
|
|
380
421
|
|
|
381
422
|
|
|
382
|
-
def zeros(shape:
|
|
383
|
-
return full(shape, 0, rtype)
|
|
423
|
+
def zeros(shape: Sequence, rtype: Callable = Array, dtype: type = object) -> Any:
|
|
424
|
+
return full(shape, 0, rtype, dtype)
|
|
384
425
|
|
|
385
426
|
|
|
386
|
-
def zeros_like(a: Any, rtype: Callable = Array) -> Any:
|
|
387
|
-
return full_like(a, 0, rtype)
|
|
427
|
+
def zeros_like(a: Any, rtype: Callable = Array, dtype: type = None) -> Any:
|
|
428
|
+
return full_like(a, 0, rtype, dtype)
|
|
388
429
|
|
|
389
430
|
|
|
390
|
-
def ones(shape:
|
|
391
|
-
return full(shape, 1, rtype)
|
|
431
|
+
def ones(shape: Sequence, rtype: Callable = Array, dtype: type = object) -> Any:
|
|
432
|
+
return full(shape, 1, rtype, dtype)
|
|
392
433
|
|
|
393
434
|
|
|
394
|
-
def ones_like(a: Any, rtype: Callable = Array) -> Any:
|
|
395
|
-
return full_like(a, 1, rtype)
|
|
435
|
+
def ones_like(a: Any, rtype: Callable = Array, dtype: type = None) -> Any:
|
|
436
|
+
return full_like(a, 1, rtype, dtype)
|
|
396
437
|
|
|
397
438
|
|
|
398
|
-
def fill(shape:
|
|
439
|
+
def fill(shape: Sequence, sequence: Sequence = None, repeat: bool = True, pad: Any = 0, rtype: Callable = Array,
|
|
440
|
+
dtype: type = object) -> Any:
|
|
399
441
|
pointer = -1
|
|
400
442
|
length = 1
|
|
401
443
|
for item in shape:
|
|
@@ -416,7 +458,9 @@ def fill(shape: arr, sequence: ite = None, repeat: bool = True, pad: Any = 0, rt
|
|
|
416
458
|
return [inner(_shape[1:], depth - 1) for _ in range(_shape[0])]
|
|
417
459
|
|
|
418
460
|
result = inner(shape, len(shape))
|
|
419
|
-
|
|
461
|
+
if rtype is list:
|
|
462
|
+
return result
|
|
463
|
+
return rtype(result, dtype=dtype)
|
|
420
464
|
|
|
421
465
|
|
|
422
466
|
def tensorproduct(*tensors: Array) -> Array:
|
|
@@ -428,7 +472,9 @@ def tensorproduct(*tensors: Array) -> Array:
|
|
|
428
472
|
def mul(a, b):
|
|
429
473
|
flattened_a = a.flatten()
|
|
430
474
|
flattened_b = b.flatten()
|
|
431
|
-
|
|
475
|
+
res_dtype = a.dtype if a.dtype is not object else b.dtype
|
|
476
|
+
data = fill(a.shape + b.shape, [i * j for i in flattened_a for j in flattened_b], rtype=list)
|
|
477
|
+
return Array(data, check=False, dtype=res_dtype)
|
|
432
478
|
|
|
433
479
|
first = tensors[0]
|
|
434
480
|
for second in tensors[1:]:
|
|
@@ -438,8 +484,7 @@ def tensorproduct(*tensors: Array) -> Array:
|
|
|
438
484
|
|
|
439
485
|
class BoolArray(Array):
|
|
440
486
|
def __init__(self, data=None, check=True):
|
|
441
|
-
|
|
442
|
-
super().__init__(apply(Array(data, check), bool, list), False)
|
|
487
|
+
super().__init__(data, check, dtype=bool)
|
|
443
488
|
|
|
444
489
|
def logic_op(self, other, func):
|
|
445
490
|
from .ufuncs import ufunc_helper
|