def test_construction(self): a = self.Matrix.__class__(4) if a.nRows() != 0 or a.nCols() != 4: error('constructor 1') b = self.Matrix.__class__(a) if b.nRows() != 0 or b.nCols() != 4: error('constructor 2A') if (a.toDense() != b.toDense()).any(): error('constructor 2B') m = _RGEN.randint(1,10) n = _RGEN.randint(5,10) a = self.Matrix.__class__(n) x = _RGEN.randint(0,2,(m,n)) x[m//2] = numpy.zeros((n)) for i in range(m): a.appendSparseRow(numpy.where(x[i] > 0)[0].tolist()) b = self.Matrix.__class__(a) if (a.toDense() != b.toDense()).any(): error('copy constructor') c = self.Matrix.__class__(x) if (c.toDense() != x).any(): error('constructor from numpy array') s = c.toCSR() d = self.Matrix.__class__(s) if (d.toDense() != x).any(): error('constructor from csr string') # Test construction from a SM a = _RGEN.randint(0,10,(3,4)) a[2] = 0 a[:,3] = 0 a = SM32(a) b = SM_01_32_32(a) a = a.toDense() w = numpy.where(a > 0) a[w] = 1 if (a != b.toDense()).any(): error('construction from SM')
def setUp(self): self.Matrix = SM_01_32_32(1)