Skip to content

Commit

Permalink
Bugfix: calculation of reduced row echelon from
Browse files Browse the repository at this point in the history
  • Loading branch information
renezander90 committed Nov 18, 2024
1 parent 8135c88 commit 34dbac6
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/qrisp/operators/qubit/commutativity_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def gaussian_elimination_mod2(matrix, type='row', reduced=False, show_pivots=Fal

# Backward elimination (optional, for reduced row echelon form)
if reduced:
for i in range(min(rows, columns) - 1, -1, -1):
for j in range(i - 1, -1, -1):
if matrix[j, i] == 1:
matrix[j] = (matrix[j] + matrix[i]) % 2
for row, col in enumerate(pivots):
for i in range(row):
if matrix[i][col] == 1:
matrix[i] = (matrix[row] + matrix[i]) % 2


elif type=='column':
Expand All @@ -145,14 +145,14 @@ def gaussian_elimination_mod2(matrix, type='row', reduced=False, show_pivots=Fal
matrix[:,j] = (matrix[:,j] + matrix[:,column_index]) % 2

row_index+=1
column_index+=1
column_index+=1

# Backward elimination (optional, for column row echelon form)
# Backward elimination (optional, for reduced row echelon form)
if reduced:
for i in range(min(rows, columns) - 1, -1, -1):
for j in range(i - 1, -1, -1):
if matrix[j, i] == 1:
matrix[:,j] = (matrix[:,j] + matrix[:,i]) % 2
for col, row in enumerate(pivots):
for i in range(col):
if matrix[row][i] == 1:
matrix[:,i] = (matrix[:,col] + matrix[:,i]) % 2

if show_pivots:
return matrix, pivots
Expand Down

0 comments on commit 34dbac6

Please sign in to comment.