Ejemplo n.º 1
0
      def testRandomMat(self):
          eps = 2.2204460492503131E-16
          n = 30; m = 60; k = 30

          for i in range(100):
              A = spmatrix_util.ll_mat_rand(n, k, 0.9)
              B = spmatrix_util.ll_mat_rand(k, m, 0.4)
              C = spmatrix.matrixmultiply(A, B)
              t = numpy.zeros(k, 'd')
              y1 = numpy.zeros(n, 'd')
              y2 = numpy.zeros(n, 'd')
              for s in range(10):
                  x = RandomArray.random((m, ))
                  C.matvec(x, y1)
                  B.matvec(x, t)
                  A.matvec(t, y2)
                  self.failUnless(math.sqrt(numpy.dot(y1 - y2, y1 - y2)) < eps * n*m*k)
Ejemplo n.º 2
0
 def testSubmatrix(self):
     n = self.n
     Psym = poisson.poisson1d_sym(n)
     P = poisson.poisson1d(n)
     for i in range(n):
         P[i,i] = 4.0
         Psym[i,i] = 4.0
     # read and test diagonal blocks
     for i in range(n):
         self.failUnless(llmat_isEqual(self.A[n*i:n*(i+1),n*i:n*(i+1)], P))
         self.failUnless(llmat_isEqual(self.S[n*i:n*(i+1),n*i:n*(i+1)], P))
         self.failUnless(llmat_isEqual(self.A[n*i:n*(i+1),n*i:n*(i+1)], Psym))
         self.failUnless(llmat_isEqual(self.S[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get diagonal blocks
     R = spmatrix_util.ll_mat_rand(n*n, n*n, 0.01) # random matrix
     for i in range(n):
         R[n*i:n*(i+1),n*i:n*(i+1)] = P
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], P))
         R[n*i:n*(i+1),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get off-diagonal blocks
     for i in range(n-1):
         R[n*i:n*(i+1),n*(i+1):n*(i+2)] = P
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*(i+1):n*(i+2)], P))
         R[n*i:n*(i+1),n*(i+1):n*(i+2)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*(i+1):n*(i+2)], Psym))
     # store and get diagonal blocks in symmetric matrix
     R = spmatrix.ll_mat_sym(n*n)
     for i in range(n):
         R[n*i:n*(i+1),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*i:n*(i+1),n*i:n*(i+1)], Psym))
     # store and get off-diagonal blocks in symmetric matrix
     for i in range(n-1):
         R[n*(i+1):n*(i+2),n*i:n*(i+1)] = P
         self.failUnless(llmat_isEqual(R[n*(i+1):n*(i+2),n*i:n*(i+1)], P))
         R[n*(i+1):n*(i+2),n*i:n*(i+1)] = Psym
         self.failUnless(llmat_isEqual(R[n*(i+1):n*(i+2),n*i:n*(i+1)], Psym))
Ejemplo n.º 3
0
printMatrix(Atemp)

print 'Matrix with rows 7 and 8 and deleted:'
mask = Numeric.ones(n, 'l')
mask[7:9] = 0
Atemp.delete_rows(mask)
printMatrix(Atemp)
print Atemp.delete_rows.__doc__

print 'deleting rows and column'

Atemp = As.copy()
print 'original matrix:'
printMatrix(Atemp)

print 'Matrix with rows/cols 7 and 8 and deleted:'
mask = Numeric.ones(n, 'l')
mask[7:9] = 0
Atemp.delete_rowcols(mask)
printMatrix(Atemp)

nn = 100
R = spmatrix_util.ll_mat_rand(nn, nn, 0.3)
##print R.nnz
for i in range(nn - 5):
    mask = Numeric.ones(nn, 'l')
    mask[0] = 0
    R.delete_rowcols(mask)
    nn -= 1
##print R
Ejemplo n.º 4
0
printMatrix(Atemp)

print 'Matrix with rows 7 and 8 and deleted:'
mask = Numeric.ones(n, 'l')
mask[7:9] = 0
Atemp.delete_rows(mask)
printMatrix(Atemp)
print Atemp.delete_rows.__doc__

print 'deleting rows and column'

Atemp = As.copy()
print 'original matrix:'
printMatrix(Atemp)

print 'Matrix with rows/cols 7 and 8 and deleted:'
mask = Numeric.ones(n, 'l')
mask[7:9] = 0
Atemp.delete_rowcols(mask)
printMatrix(Atemp)

nn = 100
R = spmatrix_util.ll_mat_rand(nn, nn, 0.3)
##print R.nnz
for i in range(nn-5):
    mask = Numeric.ones(nn, 'l')
    mask[0] = 0
    R.delete_rowcols(mask)
    nn -= 1
##print R