PyPyNum 1.17.1__py3-none-any.whl → 1.18.0__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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # PyPyNum
2
2
 
3
- PyPyNum is a multifunctional Python math lib. It includes modules for math, data analysis, array ops, crypto, physics,
4
- randomness, data prep, stats, solving eqns, image processing, interp, matrix calc, and high-precision math. Designed for
5
- scientific computing, data science, and machine learning, PyPyNum provides efficient and versatile tools.
3
+ PyPyNum is a versatile Python math lib. It features modules for math, data analysis, arrays, crypto, physics, RNG, data
4
+ proc, stats, eq solving, image proc, interp, matrix calc, and high-prec math. Designed for scientific computing, data
5
+ science, and ML, it offers efficient, general-purpose tools.
6
6
 
7
7
  ```
8
8
  ________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
@@ -19,7 +19,7 @@ scientific computing, data science, and machine learning, PyPyNum provides effic
19
19
  [![Downloads](https://static.pepy.tech/badge/pypynum/month)](https://pepy.tech/project/pypynum)
20
20
  [![Downloads](https://static.pepy.tech/badge/pypynum/week)](https://pepy.tech/project/pypynum)
21
21
 
22
- ## Version -> 1.17.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
22
+ ## PyPyNum | Version -> 1.18.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
23
23
 
24
24
  ![LOGO](PyPyNum.png)
25
25
 
@@ -30,7 +30,7 @@ The logo cannot be displayed on PyPI, it can be viewed in Gitee or GitHub.
30
30
  + Multi functional math library, similar to numpy, scipy, etc., designed specifically for PyPy interpreters and also
31
31
  supports other types of Python interpreters
32
32
  + Update versions periodically to add more practical features
33
- + If you need to contact, please add QQ number 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰), or through my email 2261748025@qq.com
33
+ + If you need to contact, please add QQ number 2261748025 (一只水晶兰), or through my email 2261748025@qq.com
34
34
 
35
35
  ```
36
36
  +++++++++++++++++++++++++++++++++++++++++
@@ -151,71 +151,64 @@ Python interpreter and run it!
151
151
  ```
152
152
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
153
153
 
154
- The `pypynum.images` module
155
- now encompasses three classes,
156
- expanding its image processing functionality.
157
- The original `PNG` class
158
- has been transformed to be based on
159
- the `BaseImage` class.
160
- This update includes a specific fix
161
- for the `read` method in `PNG`,
162
- addressing issues with reading
163
- large images.
164
- 1. `BaseImage`: A foundational class
165
- for image processing, offering
166
- basic methods like image creation,
167
- pixel access, and metadata retrieval.
168
- 2. `BMP`: A subclass of `BaseImage`,
169
- tailored for BMP image handling,
170
- providing specialized BMP functionalities.
171
- 3. `PNG`: The `PNG` class, now built on
172
- `BaseImage`, with an improved `read`
173
- method that solves the problem of
174
- reading large PNG files.
175
- This fix to the `read` method in `PNG`
176
- ensures efficient processing of large images,
177
- maintaining image quality and integrity.
178
- The module's enhanced capabilities
179
- make it more robust and user-friendly
180
- for handling substantial PNG files.
181
-
182
-
183
- <<< The following are some usage examples >>>
184
-
185
-
186
- # Import BMP and PNG classes
187
- from pypynum import BMP, PNG
188
-
189
- # Instantiate BMP class
190
- bmp_image = BMP()
191
- # Instantiate a BMP image with specified dimensions and color
192
- bmp_image.new(width=100, height=100, color=(255, 0, 0), color_mode="RGB", bit_depth=8)
193
- # Set pixel color at (50, 50) to blue
194
- bmp_image[50, 50] = (0, 0, 255)
195
- # Save the BMP image
196
- bmp_image.write("output_bmp.bmp")
197
- # Instantiate PNG class
198
- png_image = PNG()
199
- # Instantiate a PNG image with specified dimensions and color
200
- png_image.new(width=100, height=100, color=(0, 255, 0), color_mode="RGB", bit_depth=8)
201
- # Set pixel color at (50, 50) to yellow
202
- png_image[50, 50] = (255, 255, 0)
203
- # Save the PNG image
204
- png_image.write("output_png.png")
205
- # Create BMP reader to read the BMP image
206
- bmp_reader = BMP()
207
- # Read the BMP image from the file
208
- bmp_reader.read("output_bmp.bmp")
209
- # Print the BMP image and pixel at (50, 50)
210
- print("BMP Image:", bmp_reader)
211
- print("BMP Pixel at (50, 50):", bmp_reader[50, 50])
212
- # Create PNG reader to read the PNG image
213
- png_reader = PNG()
214
- # Read the PNG image from the file
215
- png_reader.read("output_png.png")
216
- # Print the PNG image and pixel at (50, 50)
217
- print("PNG Image:", png_reader)
218
- print("PNG Pixel at (50, 50):", png_reader[50, 50])
154
+ PyPyNum version 1.18.0 has undergone the following functional changes compared to version 1.17.2:
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`
219
212
 
220
213
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
221
214
  ```
@@ -274,7 +267,7 @@ PyPyNum
274
267
  │ ├── CLASS
275
268
  │ └── FUNCTION
276
269
  │ ├── atbash(text: str) -> str
277
- │ ├── base_64(text: str, decrypt: bool) -> str
270
+ │ ├── base_64(text: bytes, decrypt: bool) -> bytes
278
271
  │ ├── caesar(text: str, shift: int, decrypt: bool) -> str
279
272
  │ ├── hill256(text: bytes, key: list, decrypt: bool) -> bytes
280
273
  │ ├── ksa(key: bytes) -> list
@@ -377,7 +370,7 @@ PyPyNum
377
370
  │ ├── CLASS
378
371
  │ │ └── Group(object)/__init__(self: Any, data: Any, operation: Any) -> Any
379
372
  │ └── FUNCTION
380
- │ └── group(data: Any) -> Any
373
+ │ └── group(data: Any, operation: Any) -> Any
381
374
  ├── hypcmpnms
382
375
  │ ├── CLASS
383
376
  │ │ ├── Euler(object)/__init__(self: Any, y: typing.Union[int, float], p: typing.Union[int, float], r: typing.Union[int, float]) -> Any
@@ -392,9 +385,26 @@ PyPyNum
392
385
  │ ├── CLASS
393
386
  │ │ ├── BMP(pypynum.images.BaseImage)/__init__(self: Any) -> None
394
387
  │ │ ├── BaseImage(object)/__init__(self: Any) -> None
388
+ │ │ ├── JPEG(pypynum.images.BaseImage)/__init__(self: Any) -> None
395
389
  │ │ └── PNG(pypynum.images.BaseImage)/__init__(self: Any) -> None
396
390
  │ └── FUNCTION
397
- └── crc(data: Any, length: Any, init: Any, xor: Any) -> Any
391
+ ├── entropy(data: typing.Any) -> float
392
+ │ ├── jpeg_adjust_qtable(qtable: typing.Union[list, tuple], quality: int) -> list
393
+ │ ├── jpeg_category(data: typing.Any, reverse: bool) -> typing.Any
394
+ │ ├── jpeg_channel_encoding(matrix: list, quality: int, mode: int) -> tuple
395
+ │ ├── jpeg_chroma_dc_huff(data: typing.Any, reverse: bool) -> typing.Any
396
+ │ ├── jpeg_dct8x8(block: typing.Union[list, tuple], reverse: bool) -> list
397
+ │ ├── jpeg_decode_pixels(scan_data: bytes, lqtable: list, cqtable: list, width: int, height: int) -> list
398
+ │ ├── jpeg_encode_pixels(pixels: typing.Union[list, tuple], quality: int) -> tuple
399
+ │ ├── jpeg_luma_dc_huff(data: typing.Any, reverse: bool) -> typing.Any
400
+ │ ├── jpeg_rle_decoding(sequence: typing.Union[list, tuple]) -> list
401
+ │ ├── jpeg_rle_encoding(sequence: typing.Union[list, tuple]) -> list
402
+ │ ├── jpeg_split_pixels(matrix: list) -> list
403
+ │ ├── jpeg_zigzag(data: typing.Union[list, tuple], reverse: bool) -> list
404
+ │ ├── png_apply_filter(pixels: list, above_pixels: list, filter_type: int) -> list
405
+ │ ├── png_reverse_filter(pixels: list, above_pixels: list, filter_type: int) -> list
406
+ │ ├── rgb2ycbcr(weights: typing.Union[list, tuple]) -> tuple
407
+ │ └── ycbcr2rgb(weights: typing.Union[list, tuple]) -> tuple
398
408
  ├── interp
399
409
  │ ├── CLASS
400
410
  │ └── FUNCTION
@@ -419,6 +429,7 @@ PyPyNum
419
429
  │ ├── matmul2x2kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
420
430
  │ ├── matmul3x3kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
421
431
  │ ├── matmul4x4kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
432
+ │ ├── matmul8x8kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
422
433
  │ └── matpow2x2kernel(a: typing.Union[list, tuple], n: typing.Union[int, float, complex]) -> list
423
434
  ├── logics
424
435
  │ ├── CLASS
@@ -481,6 +492,7 @@ PyPyNum
481
492
  │ ├── cumprod(lst: typing.Union[list, tuple]) -> list
482
493
  │ ├── cumsum(lst: typing.Union[list, tuple]) -> list
483
494
  │ ├── deriv(f: Any, x: float, h: float, method: str, args: Any, kwargs: Any) -> Any
495
+ │ ├── dsigmoid(x: typing.Union[int, float]) -> float
484
496
  │ ├── erf(x: typing.Union[int, float]) -> float
485
497
  │ ├── exgcd(a: int, b: int) -> tuple
486
498
  │ ├── exp(x: typing.Union[int, float]) -> typing.Union[int, float]
@@ -524,7 +536,7 @@ PyPyNum
524
536
  │ ├── skew(data: typing.Union[list, tuple]) -> float
525
537
  │ ├── square_mean(numbers: typing.Union[list, tuple]) -> typing.Union[int, float, complex]
526
538
  │ ├── std(numbers: typing.Union[list, tuple], ddof: int) -> typing.Union[int, float, complex]
527
- │ ├── sumprod(arrays: typing.Union[list, tuple]) -> typing.Union[int, float, complex]
539
+ │ ├── sumprod(arrays: typing.Union[list, tuple], floating: bool) -> typing.Union[int, float, complex]
528
540
  │ ├── tan(x: typing.Union[int, float]) -> typing.Union[int, float]
529
541
  │ ├── tanh(x: typing.Union[int, float]) -> typing.Union[int, float]
530
542
  │ ├── totient(n: int) -> int
@@ -537,13 +549,14 @@ PyPyNum
537
549
  │ │ └── Matrix(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
538
550
  │ └── FUNCTION
539
551
  │ ├── cholesky(matrix: pypynum.matrices.Matrix, hermitian: bool) -> pypynum.matrices.Matrix
552
+ │ ├── dctmtx(n: int) -> pypynum.matrices.Matrix
540
553
  │ ├── diag(v: typing.Any, k: int, n: int, m: int) -> typing.Any
541
554
  │ ├── diag_indices(n: int, k: int, m: int) -> tuple
542
555
  │ ├── eigen(matrix: pypynum.matrices.Matrix) -> tuple
543
556
  │ ├── hessenberg(matrix: pypynum.matrices.Matrix) -> tuple
544
557
  │ ├── identity(n: int, m: int) -> pypynum.matrices.Matrix
545
558
  │ ├── lu(matrix: pypynum.matrices.Matrix) -> tuple
546
- │ ├── mat(data: Any) -> Any
559
+ │ ├── mat(data: typing.Any) -> pypynum.matrices.Matrix
547
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
548
561
  │ ├── perm_mat_indices(num_rows: int, num_cols: int, row_swaps: typing.Union[list, tuple], col_swaps: typing.Union[list, tuple]) -> tuple
549
562
  │ ├── qr(matrix: pypynum.matrices.Matrix, reduce: bool) -> tuple
@@ -591,8 +604,9 @@ PyPyNum
591
604
  │ ├── int2words(integer: int) -> str
592
605
  │ ├── parse_float(s: str) -> tuple
593
606
  │ ├── roman2int(roman_num: str) -> int
594
- │ ├── split_float(s: str) -> tuple
595
- └── str2int(string: str) -> int
607
+ │ ├── round_sigfig(number: str, n: int, scientific: bool) -> str
608
+ ├── str2int(string: str) -> int
609
+ │ └── words2int(words: str) -> int
596
610
  ├── plotting
597
611
  │ ├── CLASS
598
612
  │ └── FUNCTION
@@ -600,7 +614,7 @@ PyPyNum
600
614
  │ ├── binary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], error: Any, compare: Any, string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
601
615
  │ ├── c_unary(function: Any, projection: str, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
602
616
  │ ├── change(data: typing.Union[list, str]) -> typing.Union[list, str]
603
- │ ├── color(text: str, rgb: typing.Union[list, tuple]) -> str
617
+ │ ├── colortext(text: str, rgb: typing.Union[list, tuple]) -> str
604
618
  │ └── unary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
605
619
  ├── polys
606
620
  │ ├── CLASS
@@ -652,7 +666,7 @@ PyPyNum
652
666
  │ ├── pelllucas(n: int, single: bool) -> typing.Union[int, list]
653
667
  │ ├── perrin(n: int, single: bool) -> typing.Union[int, list]
654
668
  │ ├── recaman(n: int, single: bool) -> typing.Union[int, list]
655
- │ ├── stirling1(n: int) -> list
669
+ │ ├── stirling1(n: int, sign: bool) -> list
656
670
  │ ├── stirling2(n: int) -> list
657
671
  │ ├── sylvester(n: int, single: bool) -> typing.Union[int, list]
658
672
  │ ├── tetranacci(n: int, single: bool) -> typing.Union[int, list]
@@ -666,6 +680,8 @@ PyPyNum
666
680
  │ ├── besselj0(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
667
681
  │ ├── besselj1(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
668
682
  │ ├── besseljv(v: typing.Union[int, float], x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
683
+ │ ├── ellipe(m: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
684
+ │ ├── ellipk(m: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
669
685
  │ ├── hyp0f1(b0: typing.Union[int, float, complex], z: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
670
686
  │ ├── hyp1f1(a0: typing.Union[int, float, complex], b0: typing.Union[int, float, complex], z: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
671
687
  │ ├── hyp2f1(a0: typing.Union[int, float, complex], a1: typing.Union[int, float, complex], b0: typing.Union[int, float, complex], z: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
@@ -697,8 +713,12 @@ PyPyNum
697
713
  │ └── skewtest(data: list, two_tailed: bool) -> tuple
698
714
  ├── symbols
699
715
  │ ├── CLASS
716
+ │ │ └── Expr(object)/__init__(self: Any, tree: typing.Union[str, pypynum.trees.BinaryTree]) -> Any
700
717
  │ └── FUNCTION
701
- └── parse_expr(expr: str) -> list
718
+ ├── build_expr_tree(postfix_expr: list) -> pypynum.trees.BinaryTree
719
+ │ ├── infix2postfix(infix_expr: list) -> list
720
+ │ ├── parse_expr(expr: str) -> pypynum.symbols.Expr
721
+ │ └── tokenize(expr: str) -> list
702
722
  ├── tensors
703
723
  │ ├── CLASS
704
724
  │ │ └── Tensor(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
@@ -758,15 +778,15 @@ PyPyNum
758
778
  │ ├── apply(a: Any, func: Any, rtype: Any) -> Any
759
779
  │ ├── base_ufunc(arrays: Any, func: Any, args: Any, rtype: Any) -> Any
760
780
  │ ├── divide(x: Any, y: Any) -> Any
761
- │ ├── eq(x: Any, y: Any) -> Any
781
+ │ ├── equal(x: Any, y: Any) -> Any
762
782
  │ ├── floor_divide(x: Any, y: Any) -> Any
763
- │ ├── ge(x: Any, y: Any) -> Any
764
- │ ├── gt(x: Any, y: Any) -> Any
765
- │ ├── le(x: Any, y: Any) -> Any
766
- │ ├── lt(x: Any, y: Any) -> Any
783
+ │ ├── greater_equal(x: Any, y: Any) -> Any
784
+ │ ├── greater_than(x: Any, y: Any) -> Any
785
+ │ ├── less_equal(x: Any, y: Any) -> Any
786
+ │ ├── less_than(x: Any, y: Any) -> Any
767
787
  │ ├── modulo(x: Any, y: Any) -> Any
768
788
  │ ├── multiply(x: Any, y: Any) -> Any
769
- │ ├── ne(x: Any, y: Any) -> Any
789
+ │ ├── not_equal(x: Any, y: Any) -> Any
770
790
  │ ├── power(x: Any, y: Any, m: Any) -> Any
771
791
  │ ├── subtract(x: Any, y: Any) -> Any
772
792
  │ └── ufunc_helper(x: Any, y: Any, func: Any) -> Any
@@ -776,7 +796,8 @@ PyPyNum
776
796
  │ │ ├── IntervalSet(object)/__init__(self: Any, intervals: Any) -> Any
777
797
  │ │ ├── LinkedList(object)/__init__(self: Any) -> Any
778
798
  │ │ ├── LinkedListNode(object)/__init__(self: Any, value: Any, next_node: Any) -> Any
779
- │ │ └── OrderedSet(object)/__init__(self: Any, sequence: Any) -> Any
799
+ │ │ ├── OrderedSet(object)/__init__(self: Any, sequence: Any) -> Any
800
+ │ │ └── RadixInt(object)/__init__(self: Any, number: Any, base: Any) -> Any
780
801
  │ └── FUNCTION
781
802
  ├── vectors
782
803
  │ ├── CLASS
@@ -874,7 +895,6 @@ PyPyNum
874
895
  ├── 序列滚动(序列: typing.Iterator[typing.Any], 偏移: int) -> typing.Iterator[typing.Any]
875
896
  ├── 归一化(数据: typing.List[float], 目标: float) -> typing.List[float]
876
897
  ├── 扩展欧几里得算法(a: int, b: int) -> typing.Tuple[int, int, int]
877
- ├── 拆分浮点数字符串(字符串: str) -> tuple
878
898
  ├── 排列数(总数: int, 选取数: int) -> int
879
899
  ├── 数组(数据: list, 检查: bool) -> pypynum.arrays.Array
880
900
  ├── 整数转上标(标准字符串: str) -> str
pypynum/__init__.py CHANGED
@@ -11,9 +11,9 @@ r"""
11
11
  PyPyNum
12
12
  ==========
13
13
 
14
- PyPyNum is a Python library for math & science computations, covering algebra, calculus, stats, with data structures
15
- like matrices, vectors, tensors. It offers numerical tools, programs, and supports computational ops, functions,
16
- processing, simulation, & visualization in data science & ML, crucial for research, engineering, & data processing.
14
+ PyPyNum is a versatile Python math lib. It features modules for math, data analysis, arrays, crypto, physics, RNG,
15
+ data proc, stats, eq solving, image proc, interp, matrix calc, and high-prec math. Designed for scientific computing,
16
+ data science, and ML, it offers efficient, general-purpose tools.
17
17
 
18
18
  Copyright
19
19
  ==========
@@ -68,7 +68,7 @@ from .ufuncs import *
68
68
  from .utils import *
69
69
  from .vectors import *
70
70
 
71
- __version__ = "1.17.1"
71
+ __version__ = "1.18.0"
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
@@ -173,12 +173,37 @@ class Array:
173
173
  raise ValueError("Exponential and modulus must both be arrays or numbers")
174
174
 
175
175
  __radd__ = __add__
176
- __rsub__ = __sub__
177
176
  __rmul__ = __mul__
178
- __rtruediv__ = __truediv__
179
- __rfloordiv__ = __floordiv__
180
- __rmod__ = __mod__
181
- __rpow__ = __pow__
177
+
178
+ def __rsub__(self, other):
179
+ if isinstance(other, (int, float, complex)):
180
+ return fill(self.shape, [other - t for t in self.flatten()], rtype=type(self))
181
+ else:
182
+ raise ValueError("Another must be an array or number")
183
+
184
+ def __rtruediv__(self, other):
185
+ if isinstance(other, (int, float, complex)):
186
+ return fill(self.shape, [other / t for t in self.flatten()], rtype=type(self))
187
+ else:
188
+ raise ValueError("Another must be an array or number")
189
+
190
+ def __rfloordiv__(self, other):
191
+ if isinstance(other, (int, float, complex)):
192
+ return fill(self.shape, [other // t for t in self.flatten()], rtype=type(self))
193
+ else:
194
+ raise ValueError("Another must be an array or number")
195
+
196
+ def __rmod__(self, other):
197
+ if isinstance(other, (int, float, complex)):
198
+ return fill(self.shape, [other % t for t in self.flatten()], rtype=type(self))
199
+ else:
200
+ raise ValueError("Another must be an array or number")
201
+
202
+ def __rpow__(self, other):
203
+ if isinstance(other, (int, float, complex)):
204
+ return fill(self.shape, [other ** t for t in self.flatten()], rtype=type(self))
205
+ else:
206
+ raise ValueError("Exponential must be an array or number")
182
207
 
183
208
  def __gt__(self, other):
184
209
  return self.comparison(other, lambda x, y: x > y)
@@ -200,12 +225,12 @@ class Array:
200
225
 
201
226
  def comparison(self, other, func):
202
227
  from .ufuncs import apply, base_ufunc
203
- if isinstance(other, (int, float, complex)):
204
- return apply(self, lambda x: func(x, other), BoolArray)
205
- elif isinstance(other, Array):
228
+ if isinstance(other, Array):
206
229
  if self.shape != other.shape:
207
230
  raise ValueError("Shapes must be equal for element-wise comparison")
208
231
  return base_ufunc(self, other, func=func, rtype=BoolArray)
232
+ elif isinstance(other, (int, float, complex)):
233
+ return apply(self, lambda x: func(x, other), BoolArray)
209
234
  else:
210
235
  raise TypeError("Unsupported operand type(s) for comparison: '{}' and '{}'".format(type(self), type(other)))
211
236
 
@@ -376,7 +401,7 @@ def fill(shape: arr, sequence: ite = None, repeat: bool = True, pad: Any = 0, rt
376
401
  for item in shape:
377
402
  length *= item
378
403
  if sequence is None:
379
- sequence = list(range(length))
404
+ sequence = tuple(range(length))
380
405
  total = len(sequence)
381
406
  last = total - 1
382
407
 
pypynum/ciphers.py CHANGED
@@ -15,13 +15,13 @@ __MORSE_CODE = {
15
15
  __MORSE_CODE_REVERSE = {v: k for k, v in __MORSE_CODE.items()}
16
16
 
17
17
 
18
- def base_64(text: str, decrypt: bool = False) -> str:
19
- base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
18
+ def base_64(text: bytes, decrypt: bool = False) -> bytes:
19
+ base64_chars = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
20
20
  base64_index = {c: i for i, c in enumerate(base64_chars)}
21
- base64_padding = "="
21
+ base64_padding = b"="
22
22
 
23
23
  def base64_encode(data):
24
- encoded = ""
24
+ encoded = bytearray()
25
25
  remainder = len(data) % 3
26
26
  padding_len = 3 - remainder if remainder else 0
27
27
  for i in range(0, len(data) - remainder, 3):
@@ -29,18 +29,18 @@ def base_64(text: str, decrypt: bool = False) -> str:
29
29
  int_value = (chunk[0] << 16) + (chunk[1] << 8) + chunk[2]
30
30
  for j in range(4):
31
31
  bits = (int_value >> (6 * (3 - j))) & 0x3F
32
- encoded += base64_chars[bits]
32
+ encoded.append(base64_chars[bits])
33
33
  if padding_len:
34
34
  chunk = data[-remainder:]
35
35
  binary = "".join([format(i, "08b") for i in chunk]) + "0" * (6 - len(chunk) * 8 % 6)
36
- encoded += "".join([base64_chars[int(binary[j:j + 6], 2)] for j in range(
37
- 0, len(binary), 6)]) + base64_padding * (padding_len % 3)
38
- return encoded
36
+ encoded.extend([base64_chars[int(binary[j:j + 6], 2)] for j in range(0, len(binary), 6)])
37
+ encoded.extend(base64_padding * (padding_len % 3))
38
+ return bytes(encoded)
39
39
 
40
40
  def base64_decode(encoded):
41
- encoded = encoded.replace("\n", "").replace(" ", "")
41
+ encoded = encoded.replace(b"\n", b"").replace(b" ", b"")
42
42
  decoded = b""
43
- if not all([c in base64_chars or c == base64_padding for c in encoded]):
43
+ if not all([c in base64_chars or c == 61 for c in encoded]):
44
44
  raise ContentError
45
45
  position = encoded.find(base64_padding)
46
46
  padding_len = len(encoded) - position if position != -1 else 0
@@ -67,11 +67,9 @@ def base_64(text: str, decrypt: bool = False) -> str:
67
67
  return decoded
68
68
 
69
69
  if decrypt:
70
- decoded_bytes = base64_decode(text).decode("UTF-8")
71
- return decoded_bytes
70
+ return base64_decode(text)
72
71
  else:
73
- encoded_bytes = base64_encode(text.encode("UTF-8"))
74
- return encoded_bytes
72
+ return base64_encode(text)
75
73
 
76
74
 
77
75
  def atbash(text: str) -> str:
@@ -206,7 +204,6 @@ def playfair(text: str, key: str, decrypt: bool = False) -> str:
206
204
  def hill256(text: bytes, key: list, decrypt: bool = False) -> bytes:
207
205
  from .arrays import fill
208
206
  from .matrices import mat
209
-
210
207
  def decrypt_key(k):
211
208
  try:
212
209
  det = round(k.det())
pypynum/dists.py CHANGED
@@ -57,7 +57,7 @@ def cauchy_pdf(x, x0, gamma):
57
57
  Cauchy probability density function
58
58
 
59
59
  Example
60
- =========
60
+ ==========
61
61
  >>> cauchy_pdf(0, 0, 1)
62
62
  0.3183098861837907
63
63
  >>>
@@ -74,10 +74,12 @@ def cauchy_pdf(x, x0, gamma):
74
74
 
75
75
  def cauchy_cdf(x, x0, gamma):
76
76
  """
77
+ Introduction
78
+ ==========
77
79
  Cauchy cumulative distribution function
78
80
 
79
81
  Example
80
- =========
82
+ ==========
81
83
  >>> cauchy_cdf(0, 0, 1)
82
84
  0.5
83
85
  >>>
@@ -133,8 +135,8 @@ def chi2_cdf(x, df=1):
133
135
  :return: The probability density at x for the Chi-squared distribution with df degrees of freedom.
134
136
  """
135
137
  from math import gamma
136
- from .maths import lower_gamma
137
- return lower_gamma(df / 2, x / 2) / gamma(df / 2)
138
+ from .maths import lowergamma
139
+ return lowergamma(df / 2, x / 2) / gamma(df / 2)
138
140
 
139
141
 
140
142
  def expon_pdf(x, scale=1.0):
@@ -291,7 +293,7 @@ def invgauss_pdf(x, mu, lambda_, alpha):
291
293
  Inverse Gaussian (inverse normal) probability density function
292
294
 
293
295
  Example
294
- =========
296
+ ==========
295
297
  >>> invgauss_pdf(1, 1, 1, 1)
296
298
  0.3989422804014327
297
299
  >>>
@@ -317,7 +319,7 @@ def levy_pdf(x, c):
317
319
  Lévy probability density function
318
320
 
319
321
  Example
320
- =========
322
+ ==========
321
323
  >>> levy_pdf(1, 1)
322
324
  0.24197072451914337
323
325
  >>>
@@ -339,7 +341,7 @@ def log_logistic_pdf(x, alpha, beta):
339
341
  Log-logistic probability density function
340
342
 
341
343
  Example
342
- =========
344
+ ==========
343
345
  >>> log_logistic_pdf(1, 1, 1)
344
346
  0.25
345
347
  >>>
@@ -363,7 +365,7 @@ def log_logistic_cdf(x, alpha, beta):
363
365
  Log-logistic cumulative distribution function
364
366
 
365
367
  Example
366
- =========
368
+ ==========
367
369
  >>> log_logistic_cdf(1, 1, 1)
368
370
  0.5906161091496412
369
371
  >>>
@@ -387,7 +389,7 @@ def logistic_pdf(x, mu=0, s=1):
387
389
  Logistic probability density function
388
390
 
389
391
  Example
390
- =========
392
+ ==========
391
393
  >>> logistic_pdf(0, 0, 1)
392
394
  0.25
393
395
  >>>
@@ -409,7 +411,7 @@ def logistic_cdf(x, mu=0, s=1):
409
411
  Logistic cumulative distribution function
410
412
 
411
413
  Example
412
- =========
414
+ ==========
413
415
  >>> logistic_cdf(0, 0, 1)
414
416
  0.5
415
417
  >>>
@@ -502,7 +504,7 @@ def multinomial_pmf(k, n, p):
502
504
  Multinomial probability mass function
503
505
 
504
506
  Example
505
- =========
507
+ ==========
506
508
  >>> multinomial_pmf([2, 1, 0], 3, [0.5, 0.4, 0.1])
507
509
  0.30000000000000004
508
510
  >>>
@@ -636,7 +638,7 @@ def pareto_pdf(x, k, m):
636
638
  Pareto probability density function
637
639
 
638
640
  Example
639
- =========
641
+ ==========
640
642
  >>> pareto_pdf(10, 2, 5)
641
643
  0.00040000000000000013
642
644
  >>>
@@ -679,7 +681,7 @@ def rayleigh_pdf(x, sigma):
679
681
  Rayleigh probability density function
680
682
 
681
683
  Example
682
- =========
684
+ ==========
683
685
  >>> rayleigh_pdf(1, 1)
684
686
  0.6065306597126334
685
687
  >>>
@@ -840,7 +842,7 @@ def zipf_pmf(k, s, n):
840
842
  Zipf probability mass function
841
843
 
842
844
  Example
843
- =========
845
+ ==========
844
846
  >>> zipf_pmf(1, 1, 10)
845
847
  0.34141715214740553
846
848
  >>>