# HG changeset patch # User Jason Sachs # Date 1381502001 25200 # Node ID 98a169f5c39daa88142b4d0aad9977a78563cbae # Parent 8df570382e18c104ec9130b1e40316c0567157bf made gauss-jordan routine report which columns fail (more information on exception) diff --git a/src/libgf2/gf2.py b/src/libgf2/gf2.py --- a/src/libgf2/gf2.py +++ b/src/libgf2/gf2.py @@ -45,6 +45,7 @@ else: C[:,n:] = b + fails = [] for j in xrange(n): # Find pivot p = None @@ -53,7 +54,8 @@ p = i break if p is None: - raise ValueError('singular matrix') + fails.append(j) + continue if p != j: C[p,:],C[j,:] = np.copy(C[j,:]),np.copy(C[p,:]) for i in range(n): @@ -61,6 +63,8 @@ continue if C[i,j] != 0: C[i,:] ^= C[j,:] + if len(fails) > 0: + raise ValueError('singular matrix: missing indices = %s' % fails) x = C[:,n:] return x @@ -83,12 +87,17 @@ def _degree(poly): return _bitlen(poly)-1 -def _bitsOf(p): - def helper(p): - while p != 0: - yield p & 1 - p >>= 1 - return tuple(helper(p)) +def _bitsOf(p,n=None): + def helper(p,n): + if n is None: + while p != 0: + yield p & 1 + p >>= 1 + else: + for _ in range(n): + yield p & 1 + p >>= 1 + return tuple(helper(p,n)) def _gf2mul(x,y): z = 0 diff --git a/src/libgf2/lfsr.py b/src/libgf2/lfsr.py --- a/src/libgf2/lfsr.py +++ b/src/libgf2/lfsr.py @@ -146,8 +146,4 @@ c2 = lfsrAnalyzer.coefficientsFromState(s) print 'c=%d, s=%s, c2=%d' % (c,s,c2) - # 48-bit - poly2 = 0x10000000000b7 - lfsrAnalyzer2 = LFSRAnalyzer(poly2) - for c in [0x101,0x220,0x404,0x880]: - print '{0:b} --> timeshift={1:d}'.format(c,lfsrAnalyzer.timeshiftFromCoefficients(c)) \ No newline at end of file + \ No newline at end of file