PyPyNum 1.17.2__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.2 | 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,51 +151,64 @@ Python interpreter and run it!
151
151
  ```
152
152
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
153
153
 
154
- Fixed some known issues.
154
+ PyPyNum version 1.18.0 has undergone the following functional changes compared to version 1.17.2:
155
155
 
156
- !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
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`).
157
203
 
158
- The pypynum.utils module has recently introduced a new class
159
- called RadixInt. This class is designed to facilitate the
160
- representation and manipulation of integers in various bases,
161
- ranging from base 2 to base 36.
162
-
163
- The RadixInt class within the pypynum.utils module provides a
164
- robust way to work with integers in custom bases. It allows
165
- users to initialize instances with either a decimal number or a
166
- string representation of a number in the desired base. The class
167
- supports conversion between different bases, as well as basic
168
- arithmetic operations that can be performed on integers
169
- represented in various bases.
170
-
171
-
172
- <<< The following are some usage examples >>>
173
-
174
-
175
- from pypynum import RadixInt
176
-
177
- # Base-2 and base-10 numbers
178
- binary_num = RadixInt("1010", 2)
179
- decimal_num = RadixInt(10, 10)
180
- print(binary_num) # Output: (1010)_{2}
181
- print(decimal_num) # Output: (10)_{10}
182
- binary_to_octal = RadixInt("1010", 2).to_base(8)
183
- print(binary_to_octal) # Output: (12)_{8}
184
- # Addition
185
- result_add = binary_num + decimal_num
186
- print(result_add) # Output: (20)_{10}
187
- # Base-8 and base-10 numbers
188
- octal_num = RadixInt("123", 8)
189
- decimal_num = RadixInt(5, 10)
190
- # Subtraction
191
- result_sub = octal_num - decimal_num
192
- print(result_sub) # Output: (78)_{10}
193
- # Base-16 and base-2 numbers
194
- hex_num = RadixInt("1A", 16)
195
- binary_num = RadixInt("11", 2)
196
- # Multiplication
197
- result_mul = hex_num * binary_num
198
- print(result_mul) # Output: (78)_{10}
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`
199
212
 
200
213
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
201
214
  ```
@@ -254,7 +267,7 @@ PyPyNum
254
267
  │ ├── CLASS
255
268
  │ └── FUNCTION
256
269
  │ ├── atbash(text: str) -> str
257
- │ ├── base_64(text: str, decrypt: bool) -> str
270
+ │ ├── base_64(text: bytes, decrypt: bool) -> bytes
258
271
  │ ├── caesar(text: str, shift: int, decrypt: bool) -> str
259
272
  │ ├── hill256(text: bytes, key: list, decrypt: bool) -> bytes
260
273
  │ ├── ksa(key: bytes) -> list
@@ -357,7 +370,7 @@ PyPyNum
357
370
  │ ├── CLASS
358
371
  │ │ └── Group(object)/__init__(self: Any, data: Any, operation: Any) -> Any
359
372
  │ └── FUNCTION
360
- │ └── group(data: Any) -> Any
373
+ │ └── group(data: Any, operation: Any) -> Any
361
374
  ├── hypcmpnms
362
375
  │ ├── CLASS
363
376
  │ │ ├── Euler(object)/__init__(self: Any, y: typing.Union[int, float], p: typing.Union[int, float], r: typing.Union[int, float]) -> Any
@@ -372,9 +385,26 @@ PyPyNum
372
385
  │ ├── CLASS
373
386
  │ │ ├── BMP(pypynum.images.BaseImage)/__init__(self: Any) -> None
374
387
  │ │ ├── BaseImage(object)/__init__(self: Any) -> None
388
+ │ │ ├── JPEG(pypynum.images.BaseImage)/__init__(self: Any) -> None
375
389
  │ │ └── PNG(pypynum.images.BaseImage)/__init__(self: Any) -> None
376
390
  │ └── FUNCTION
377
- └── 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
378
408
  ├── interp
379
409
  │ ├── CLASS
380
410
  │ └── FUNCTION
@@ -399,6 +429,7 @@ PyPyNum
399
429
  │ ├── matmul2x2kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
400
430
  │ ├── matmul3x3kernel(a: typing.Union[list, tuple], b: typing.Union[list, tuple]) -> list
401
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
402
433
  │ └── matpow2x2kernel(a: typing.Union[list, tuple], n: typing.Union[int, float, complex]) -> list
403
434
  ├── logics
404
435
  │ ├── CLASS
@@ -461,6 +492,7 @@ PyPyNum
461
492
  │ ├── cumprod(lst: typing.Union[list, tuple]) -> list
462
493
  │ ├── cumsum(lst: typing.Union[list, tuple]) -> list
463
494
  │ ├── deriv(f: Any, x: float, h: float, method: str, args: Any, kwargs: Any) -> Any
495
+ │ ├── dsigmoid(x: typing.Union[int, float]) -> float
464
496
  │ ├── erf(x: typing.Union[int, float]) -> float
465
497
  │ ├── exgcd(a: int, b: int) -> tuple
466
498
  │ ├── exp(x: typing.Union[int, float]) -> typing.Union[int, float]
@@ -504,7 +536,7 @@ PyPyNum
504
536
  │ ├── skew(data: typing.Union[list, tuple]) -> float
505
537
  │ ├── square_mean(numbers: typing.Union[list, tuple]) -> typing.Union[int, float, complex]
506
538
  │ ├── std(numbers: typing.Union[list, tuple], ddof: int) -> typing.Union[int, float, complex]
507
- │ ├── 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]
508
540
  │ ├── tan(x: typing.Union[int, float]) -> typing.Union[int, float]
509
541
  │ ├── tanh(x: typing.Union[int, float]) -> typing.Union[int, float]
510
542
  │ ├── totient(n: int) -> int
@@ -517,13 +549,14 @@ PyPyNum
517
549
  │ │ └── Matrix(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
518
550
  │ └── FUNCTION
519
551
  │ ├── cholesky(matrix: pypynum.matrices.Matrix, hermitian: bool) -> pypynum.matrices.Matrix
552
+ │ ├── dctmtx(n: int) -> pypynum.matrices.Matrix
520
553
  │ ├── diag(v: typing.Any, k: int, n: int, m: int) -> typing.Any
521
554
  │ ├── diag_indices(n: int, k: int, m: int) -> tuple
522
555
  │ ├── eigen(matrix: pypynum.matrices.Matrix) -> tuple
523
556
  │ ├── hessenberg(matrix: pypynum.matrices.Matrix) -> tuple
524
557
  │ ├── identity(n: int, m: int) -> pypynum.matrices.Matrix
525
558
  │ ├── lu(matrix: pypynum.matrices.Matrix) -> tuple
526
- │ ├── mat(data: Any) -> Any
559
+ │ ├── mat(data: typing.Any) -> pypynum.matrices.Matrix
527
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
528
561
  │ ├── perm_mat_indices(num_rows: int, num_cols: int, row_swaps: typing.Union[list, tuple], col_swaps: typing.Union[list, tuple]) -> tuple
529
562
  │ ├── qr(matrix: pypynum.matrices.Matrix, reduce: bool) -> tuple
@@ -571,8 +604,9 @@ PyPyNum
571
604
  │ ├── int2words(integer: int) -> str
572
605
  │ ├── parse_float(s: str) -> tuple
573
606
  │ ├── roman2int(roman_num: str) -> int
574
- │ ├── split_float(s: str) -> tuple
575
- └── str2int(string: str) -> int
607
+ │ ├── round_sigfig(number: str, n: int, scientific: bool) -> str
608
+ ├── str2int(string: str) -> int
609
+ │ └── words2int(words: str) -> int
576
610
  ├── plotting
577
611
  │ ├── CLASS
578
612
  │ └── FUNCTION
@@ -580,7 +614,7 @@ PyPyNum
580
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]
581
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]
582
616
  │ ├── change(data: typing.Union[list, str]) -> typing.Union[list, str]
583
- │ ├── color(text: str, rgb: typing.Union[list, tuple]) -> str
617
+ │ ├── colortext(text: str, rgb: typing.Union[list, tuple]) -> str
584
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]
585
619
  ├── polys
586
620
  │ ├── CLASS
@@ -632,7 +666,7 @@ PyPyNum
632
666
  │ ├── pelllucas(n: int, single: bool) -> typing.Union[int, list]
633
667
  │ ├── perrin(n: int, single: bool) -> typing.Union[int, list]
634
668
  │ ├── recaman(n: int, single: bool) -> typing.Union[int, list]
635
- │ ├── stirling1(n: int) -> list
669
+ │ ├── stirling1(n: int, sign: bool) -> list
636
670
  │ ├── stirling2(n: int) -> list
637
671
  │ ├── sylvester(n: int, single: bool) -> typing.Union[int, list]
638
672
  │ ├── tetranacci(n: int, single: bool) -> typing.Union[int, list]
@@ -646,6 +680,8 @@ PyPyNum
646
680
  │ ├── besselj0(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
647
681
  │ ├── besselj1(x: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
648
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]
649
685
  │ ├── hyp0f1(b0: typing.Union[int, float, complex], z: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
650
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]
651
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]
@@ -677,8 +713,12 @@ PyPyNum
677
713
  │ └── skewtest(data: list, two_tailed: bool) -> tuple
678
714
  ├── symbols
679
715
  │ ├── CLASS
716
+ │ │ └── Expr(object)/__init__(self: Any, tree: typing.Union[str, pypynum.trees.BinaryTree]) -> Any
680
717
  │ └── FUNCTION
681
- └── 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
682
722
  ├── tensors
683
723
  │ ├── CLASS
684
724
  │ │ └── Tensor(pypynum.arrays.Array)/__init__(self: Any, data: Any, check: Any) -> Any
@@ -738,15 +778,15 @@ PyPyNum
738
778
  │ ├── apply(a: Any, func: Any, rtype: Any) -> Any
739
779
  │ ├── base_ufunc(arrays: Any, func: Any, args: Any, rtype: Any) -> Any
740
780
  │ ├── divide(x: Any, y: Any) -> Any
741
- │ ├── eq(x: Any, y: Any) -> Any
781
+ │ ├── equal(x: Any, y: Any) -> Any
742
782
  │ ├── floor_divide(x: Any, y: Any) -> Any
743
- │ ├── ge(x: Any, y: Any) -> Any
744
- │ ├── gt(x: Any, y: Any) -> Any
745
- │ ├── le(x: Any, y: Any) -> Any
746
- │ ├── 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
747
787
  │ ├── modulo(x: Any, y: Any) -> Any
748
788
  │ ├── multiply(x: Any, y: Any) -> Any
749
- │ ├── ne(x: Any, y: Any) -> Any
789
+ │ ├── not_equal(x: Any, y: Any) -> Any
750
790
  │ ├── power(x: Any, y: Any, m: Any) -> Any
751
791
  │ ├── subtract(x: Any, y: Any) -> Any
752
792
  │ └── ufunc_helper(x: Any, y: Any, func: Any) -> Any
@@ -756,7 +796,8 @@ PyPyNum
756
796
  │ │ ├── IntervalSet(object)/__init__(self: Any, intervals: Any) -> Any
757
797
  │ │ ├── LinkedList(object)/__init__(self: Any) -> Any
758
798
  │ │ ├── LinkedListNode(object)/__init__(self: Any, value: Any, next_node: Any) -> Any
759
- │ │ └── 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
760
801
  │ └── FUNCTION
761
802
  ├── vectors
762
803
  │ ├── CLASS
@@ -854,7 +895,6 @@ PyPyNum
854
895
  ├── 序列滚动(序列: typing.Iterator[typing.Any], 偏移: int) -> typing.Iterator[typing.Any]
855
896
  ├── 归一化(数据: typing.List[float], 目标: float) -> typing.List[float]
856
897
  ├── 扩展欧几里得算法(a: int, b: int) -> typing.Tuple[int, int, int]
857
- ├── 拆分浮点数字符串(字符串: str) -> tuple
858
898
  ├── 排列数(总数: int, 选取数: int) -> int
859
899
  ├── 数组(数据: list, 检查: bool) -> pypynum.arrays.Array
860
900
  ├── 整数转上标(标准字符串: str) -> str
pypynum/__init__.py CHANGED
@@ -11,9 +11,9 @@ r"""
11
11
  PyPyNum
12
12
  ==========
13
13
 
14
- PyPyNum is a multifunctional Python math lib. It includes modules for math, data analysis, array ops, crypto,
15
- physics, randomness, data prep, stats, solving eqns, image processing, interp, matrix calc, and high-precision math.
16
- Designed for scientific computing, data science, and machine learning, PyPyNum provides efficient and versatile tools.
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.2"
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())