mirror of
https://github.com/jjaldridge2009/Project_Xs.git
synced 2024-08-17 22:39:37 +02:00
Update calc.py
bugfix (issue : S may not always be regular matrix.)
This commit is contained in:
parent
e2245865fc
commit
a896da65b3
29
src/calc.py
29
src/calc.py
@ -27,13 +27,13 @@ def getTrans():
|
|||||||
|
|
||||||
return trans
|
return trans
|
||||||
|
|
||||||
def getS(intervals):
|
def getS(intervals,rows = 39):
|
||||||
intervals = intervals[:32]
|
intervals = intervals[:rows]
|
||||||
t = getTrans()
|
t = getTrans()
|
||||||
t_ = getTrans()
|
t_ = getTrans()
|
||||||
|
|
||||||
s = np.zeros((128,128),"uint8")
|
s = np.zeros((4*rows,128),"uint8")
|
||||||
for i in range(32):
|
for i in range(rows):
|
||||||
s[4*i:4*(i+1)] = t[-4:]
|
s[4*i:4*(i+1)] = t[-4:]
|
||||||
for j in range(intervals[i]):
|
for j in range(intervals[i]):
|
||||||
t = t@t_%2
|
t = t@t_%2
|
||||||
@ -64,39 +64,40 @@ def getS_munchlax(intervals):
|
|||||||
|
|
||||||
def gauss_jordan(mat,observed:list):
|
def gauss_jordan(mat,observed:list):
|
||||||
r,c = mat.shape
|
r,c = mat.shape
|
||||||
assert r==c
|
|
||||||
|
|
||||||
n = r
|
|
||||||
bitmat = [list2bitvec(mat[i]) for i in range(r)]
|
bitmat = [list2bitvec(mat[i]) for i in range(r)]
|
||||||
|
|
||||||
res = [d for d in observed]
|
res = [d for d in observed]
|
||||||
#forward elimination
|
#forward elimination
|
||||||
pivot = 0
|
pivot = 0
|
||||||
for i in range(n):
|
for i in range(c):
|
||||||
isfound = False
|
isfound = False
|
||||||
for j in range(i,n):
|
for j in range(i,r):
|
||||||
if isfound:
|
if isfound:
|
||||||
check = 1<<(n-i-1)
|
check = 1<<(c-i-1)
|
||||||
if bitmat[j]&check==check:
|
if bitmat[j]&check==check:
|
||||||
bitmat[j] ^= bitmat[pivot]
|
bitmat[j] ^= bitmat[pivot]
|
||||||
res[j] ^= res[pivot]
|
res[j] ^= res[pivot]
|
||||||
else:
|
else:
|
||||||
check = 1<<(n-i-1)
|
check = 1<<(c-i-1)
|
||||||
if bitmat[j]&check==check:
|
if bitmat[j]&check==check:
|
||||||
isfound = True
|
isfound = True
|
||||||
bitmat[j],bitmat[pivot] = bitmat[pivot],bitmat[j]
|
bitmat[j],bitmat[pivot] = bitmat[pivot],bitmat[j]
|
||||||
res[j],res[pivot] = res[pivot],res[j]
|
res[j],res[pivot] = res[pivot],res[j]
|
||||||
if isfound:
|
if isfound:
|
||||||
pivot += 1
|
pivot += 1
|
||||||
|
for i in range(c):
|
||||||
|
check = 1<<(c-i-1)
|
||||||
|
assert bitmat[i]&check>0
|
||||||
|
|
||||||
#backward assignment
|
#backward assignment
|
||||||
for i in range(1,n)[::-1]:
|
for i in range(1,c)[::-1]:
|
||||||
check = 1<<(n-i-1)
|
check = 1<<(c-i-1)
|
||||||
for j in range(i)[::-1]:
|
for j in range(i)[::-1]:
|
||||||
if bitmat[j]&check==check:
|
if bitmat[j]&check==check:
|
||||||
bitmat[j] ^= bitmat[i]
|
bitmat[j] ^= bitmat[i]
|
||||||
res[j] ^= res[i]
|
res[j] ^= res[i]
|
||||||
return res
|
return res[:c]
|
||||||
|
|
||||||
def getInverse(mat):
|
def getInverse(mat):
|
||||||
r,c = mat.shape
|
r,c = mat.shape
|
||||||
@ -148,7 +149,7 @@ def reverseStates(rawblinks:list, intervals:list)->int:
|
|||||||
for b in rawblinks:
|
for b in rawblinks:
|
||||||
blinks.extend([0,0,0])
|
blinks.extend([0,0,0])
|
||||||
blinks.append(b)
|
blinks.append(b)
|
||||||
blinks = blinks[:128]
|
|
||||||
#print(blinks)
|
#print(blinks)
|
||||||
s = getS(intervals)
|
s = getS(intervals)
|
||||||
lst_result = gauss_jordan(s, blinks)
|
lst_result = gauss_jordan(s, blinks)
|
||||||
|
Loading…
Reference in New Issue
Block a user