Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisRalli committed Mar 18, 2024
1 parent 00bf47d commit 60c6a32
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions symmer/operators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def numba_binary_matmal_GF2(A: np.array, B: np.array) -> np.array:
acc ^= A[i, k] & B[k, j]
C[i, j] = acc
return C
g

@nb.njit('(bool_[:,::1],bool_[:,::1])', fastmath=True, cache=True)
def numba_dot_matmal_GF2(A, B):
"""
Expand All @@ -75,40 +75,7 @@ def numba_dot_matmal_GF2(A, B):
return np.asarray(np.dot(np.asarray(A, dtype = np.float64),
np.asarray(B, dtype = np.float64)
)%2,
dtype = np.bool_)

"""
custom GF(2) multiplication using numba. i.e. C = (A@B) mod 2.
Note function uses fact that multiplication over GF2 doesn't require sums for each matrix element in C
instead it uses and AND operation (same as elementwise multiplicaiton of row,col pairs)
followed by XOR operation (same as taking sum of row,col multiplied pairs)
Args:
A (np.array): numpy boolean array
B (np.array): numpy boolean array
Returns:
C (np.array): numpy boolean array of (A@B) mod 2
"""
C = np.empty((A.shape[0], B.shape[1]), dtype=np.bool_)
for i in nb.prange(C.shape[0]):
for j in range(C.shape[1]):

## logical version 1 (slower)
# C[i, j] = bool(np.sum(np.logical_and(A[i, :], B[:, j]))%2)

# # logical version 2 (slower)
# parity = False
# for bit in np.logical_and(A[i, :], B[:, j]):
# parity^=bit
# C[i, j] = parity

## faster loop
acc = False
for k in range(B.shape[0]):
acc ^= A[i, k] & B[k, j]
C[i, j] = acc
return C
dtype = np.bool_)

def symplectic_to_string(symp_vec) -> str:
"""
Expand Down

0 comments on commit 60c6a32

Please sign in to comment.