blindscrambler 0.1.0__cp39-abi3-macosx_11_0_arm64.whl → 0.1.1__cp39-abi3-macosx_11_0_arm64.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.
@@ -1,2 +1,2 @@
1
1
  from .discrete import diff
2
- __all__ = ['diff']
2
+ __all__ = ['diff']
@@ -0,0 +1,2 @@
1
+ from .elementary import float_equality, rowswap, rowscale, rowreplacement, rref
2
+ __all__ = ["float_equality", "rowswap", "rowscale", "rowreplacement", "rref"]
@@ -0,0 +1,138 @@
1
+ # Metadata:
2
+ # Author: Syed Raza
3
+ # email: sar0033@uah.edu
4
+
5
+ # import statements
6
+ import torch # type: ignore
7
+ tol = 1e-7
8
+
9
+ # This is the program to perform matrix operations on pytorch based arrays/matrices
10
+
11
+ def float_equality(n1, n2):
12
+ """
13
+ Params:
14
+ (1) n1 -- type torch.float32
15
+ the first number for equality check
16
+ (2) n2 -- type torch.float32
17
+ the second number for equality check
18
+ (3) tol -- the tolerance for float equality
19
+
20
+ Returns:
21
+ true if they are equal
22
+ False if they are not
23
+ """
24
+ return abs(n1 - n2) < tol
25
+
26
+
27
+ def rowswap(M, src, trg):
28
+ """
29
+ Params: (1) A Pytorch based matrix -- M,
30
+ (2) index of type int the source row -- src,
31
+ (3) Index of type int target row -- trg
32
+
33
+ Returns: Returns the matrix after swapping the content of source row with the target row
34
+ """
35
+ # swap the rows you wanted:
36
+ M[[src, trg]] = M[[trg, src]]
37
+
38
+ return M
39
+
40
+ def rowscale(M, src, sca):
41
+ """
42
+ Params:
43
+ (1) A Pytorch based matrix -- M
44
+ (2) index (type int) of the row to be scaled -- src
45
+ (2) scaling factor of type int -- sca
46
+ """
47
+ M[src] *= sca
48
+
49
+ return M
50
+
51
+ def rowreplacement(M, r1, r2, sca1, sca2):
52
+ """
53
+ Params:
54
+ (1) M -- type Pytorch tensor
55
+ This is the matrix where we are applying the row replacement
56
+ (2) r1 -- type int
57
+ The index of the first row
58
+ (3) r2 -- type int
59
+ The index of the second row
60
+ (4) sca1 -- type int
61
+ the scaling factor row 1
62
+ (5) sca2 -- type int
63
+ the scalikng factor row 2
64
+
65
+ Returns:
66
+ The matrix but with finished row replacement
67
+ """
68
+ # clone the matrix, so we do not change the matrix in place
69
+ M1 = M.clone()
70
+
71
+ # scale both rows in the clone
72
+ M1 = rowscale(M1, r1, sca1)
73
+ M1 = rowscale(M1, r2, sca2)
74
+
75
+ # perform row-replacement
76
+ M[r1] = M1[r1] + M1[r2]
77
+
78
+ # return M
79
+ return M
80
+
81
+ # A routine for converting matrices into reduced row echelon form:
82
+ def rref(M):
83
+ """
84
+ Params: M -- type Pytorch tensor
85
+ This is the matrix where we are trying to convert into Row Echelon form
86
+ Returns: M -- type Pytorch tensor
87
+ The row echelon version of the matix the was inputed. It used the functions generated
88
+ in this module: float inequality, rowswap, rowreplacement, and rowscale
89
+ """
90
+ # get the rows and the columns
91
+ nrow = M.shape[0]
92
+ ncol = M.shape[1]
93
+
94
+ # The workflow is given as follows:
95
+
96
+ row = 0
97
+ for col in range(ncol):
98
+ if row >= nrow:
99
+ break
100
+ # (a) if there is a zero in the row, rowswap with a new row
101
+ if float_equality(M[row, col], 0):
102
+ # go through rest of the rows
103
+ for k in range(row, nrow):
104
+ if not float_equality(M[k, col], 0):
105
+ rowswap(M, k, row) # this is the row that includes the pivot
106
+ break # break rowswapping first time this happens
107
+
108
+ # (b) use row scale to make the pivot element 1
109
+ if not float_equality(M[row, col], 0):
110
+ rowscale(M, row, 1 / M[row, col])
111
+
112
+ # (c) make everything below zero using row_replacement function
113
+ for r in range(row + 1, nrow):
114
+ if not float_equality(M[r, col], 0):
115
+ mul = - M[r, col] / M[row, col]
116
+ rowreplacement(M, r, row, 1.0, mul)
117
+
118
+ row += 1
119
+
120
+ # scale the last row separately:
121
+ last = nrow - 1
122
+ for col in range(ncol):
123
+ if not float_equality(M[last, col], 0.0):
124
+ rowscale(M, last, 1 / M[last, col])
125
+
126
+ # make really smal numbers resulting due to floating point operations zero
127
+ # before returning the matrix
128
+ M[torch.abs(M) < 1e-5] = 0.0
129
+
130
+ return M
131
+
132
+ # main function for testing the code and analyzing the reuslts:
133
+ if __name__ == "__main__":
134
+ M = torch.tensor([[0, 3, -6, 6, 4], [3, -7, 8, -5, 8], [3, -9, 12, -9, 6]], dtype = torch.float32)
135
+
136
+ # testing phase of the rref function:
137
+ M = rref(M)
138
+ print(M)
@@ -1,6 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: blindscrambler
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
+ Requires-Dist: numpy>=2.3.3
5
+ Requires-Dist: torch>=2.8.0
4
6
  Requires-Dist: twine>=6.1.0
5
7
  Summary: Add your description here
6
8
  Author-email: blindscramblergh <blindscrambler@gmail.com>
@@ -0,0 +1,11 @@
1
+ blindscrambler-0.1.1.dist-info/METADATA,sha256=FR7WqZiu_Xu4IeyqrDTLdGZtNP4ojMLHK55VO6H3rkA,373
2
+ blindscrambler-0.1.1.dist-info/WHEEL,sha256=DLqF2HZq4W_umZdP6RnfAuqhmtX_UrV4mkqrSIMhipE,102
3
+ blindscrambler/__init__.py,sha256=N6o-PTyGSlQ4ny1UA4ByeNenVF-wCTALnyP4WJ8PGas,98
4
+ blindscrambler/_core.abi3.so,sha256=OG585R2Nb-fp_sH7C6qCpxzKDFG6hKWqIkwWvB6n0II,440336
5
+ blindscrambler/_core.pyi,sha256=b6oJaUXUzEzqUE5rpqefV06hl8o_JCU8pgKgIIzQgmc,33
6
+ blindscrambler/differential/__init__.py,sha256=INnk5rX2ae6mG5yynAQYKzpQ0BYsHquUhA9ZzbPVLm8,45
7
+ blindscrambler/differential/discrete.py,sha256=mPJg6YrDVuXK-dLXgb_VDqKl1IvKfSKahMA_rRTVKQY,369
8
+ blindscrambler/matrix/__init__.py,sha256=qlItVU8AVj_mP2NUJ3gor-lsovxk3Wxf5tUfKynoUbg,157
9
+ blindscrambler/matrix/elementary.py,sha256=hArZLiBTA_vW1EZ0RniECf6ybJiJxO7KNuVHb_TZFQU,3987
10
+ blindscrambler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ blindscrambler-0.1.1.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- blindscrambler-0.1.0.dist-info/METADATA,sha256=KxZRLgUTtGWxx_i4NS1ibY__4Crkn9geJzY_2eAIj5E,317
2
- blindscrambler-0.1.0.dist-info/WHEEL,sha256=DLqF2HZq4W_umZdP6RnfAuqhmtX_UrV4mkqrSIMhipE,102
3
- blindscrambler/__init__.py,sha256=N6o-PTyGSlQ4ny1UA4ByeNenVF-wCTALnyP4WJ8PGas,98
4
- blindscrambler/_core.abi3.so,sha256=OG585R2Nb-fp_sH7C6qCpxzKDFG6hKWqIkwWvB6n0II,440336
5
- blindscrambler/_core.pyi,sha256=b6oJaUXUzEzqUE5rpqefV06hl8o_JCU8pgKgIIzQgmc,33
6
- blindscrambler/differential/__init__.py,sha256=wthVEgnKH3fg_e8fjcWu5DRIJsy6LSAfd8Jntn-JiJ4,46
7
- blindscrambler/differential/discrete.py,sha256=mPJg6YrDVuXK-dLXgb_VDqKl1IvKfSKahMA_rRTVKQY,369
8
- blindscrambler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- blindscrambler-0.1.0.dist-info/RECORD,,