Exemplo n.º 1
0
 def test_simple_hermitian(self):
     a = [[1, 2 + 3j], [2 - 3j, 4]]
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, 'array', 'complex', 'hermitian'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 2
0
 def test_simple_hermitian(self):
     a = [[1,2+3j],[2-3j,4]]
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,2,4,'array','complex','hermitian'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 3
0
 def test_simple_rectangular_real(self):
     a = [[1, 2], [3.5, 4], [5, 6]]
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (3, 2, 6, 'array', 'real', 'general'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 4
0
 def check_read(self, example, a, info):
     f = open(self.fn, 'w')
     f.write(example)
     f.close()
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 5
0
 def test_simple_skew_symmetric_float(self):
     a = array([[1, 2], [-2.0, 4]], "f")
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, "array", "real", "skew-symmetric"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 6
0
 def test_simple_skew_symmetric(self):
     a = [[1, 2], [-2, 4]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, "array", "integer", "skew-symmetric"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 7
0
 def test_simple_complex(self):
     a = [[1, 2], [3, 4j]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, "array", "complex", "general"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 8
0
 def test_simple_rectangular_real(self):
     a = [[1, 2], [3.5, 4], [5, 6]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (3, 2, 6, "array", "real", "general"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 9
0
 def test_simple_hermitian(self):
     a = [[1, 2 + 3j], [2 - 3j, 4]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, "array", "complex", "hermitian"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 10
0
 def test_simple_real(self):
     a = [[1, 2], [3, 4.0]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, 'array', 'real', 'general'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 11
0
 def test_simple_complex(self):
     a = [[1, 2], [3, 4j]]
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, 'array', 'complex', 'general'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 12
0
def main():
    if (len(sys.argv) != 2):
        print "Usage: " + sys.argv[0] + " matrix-name"
        sys.exit(0)
    # end if

    matrixName = sys.argv[1] + ".mtx"
    mm = open(sys.argv[1] + '.mm', 'w')
    outputName = sys.argv[1] + ".png"
    #outputName=sys.argv[1]+ ".pdf"

    (n, n, nz, void, fld, symm) = mminfo(matrixName)

    A = mmread(matrixName).tocsr().tocoo()

    # creating a file in coo format
    #print n, n, A.size
    mm.write(str(n) + ' ' + str(n) + ' ' + str(A.size) + '\n')
    for i in range(A.size):
        mm.write(
            str(A.row[i]) + ' ' + str(A.col[i]) + ' ' + str(A.data[i]) + '\n')
        #print A.row[i]+1, A.col[i]+1 , A.data[i]
    # end for
    #print repr(A)
    #print A.col
    #print A.size
    # end of creating a file in coo format

    #pylab.title("Matrix :" + matrixName, fontsize=22)
    pylab.title("Matrix: " + sys.argv[1] + ", n:" + str(n) + ", nz:" +
                str(A.size) + '\n',
                fontsize=10)
    pylab.spy(A, marker='.', markersize=1)
    pylab.savefig(outputName, format=None)
Exemplo n.º 13
0
 def test_simple_rectangular(self):
     a = [[1,2,3],[4,5,6]]
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,3,6,'array','integer','general'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 14
0
 def test_simple_skew_symmetric_float(self):
     a = array([[1, 2], [-2.0, 4]], 'f')
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, 'array', 'real', 'skew-symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 15
0
 def test_simple_symmetric(self):
     a = [[1, 2], [2, 4]]
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 2, 4, 'array', 'integer', 'symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 16
0
 def test_simple_skew_symmetric(self):
     a = [[1,2],[-2,4]]
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,2,4,'array','integer','skew-symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 17
0
 def test_simple_skew_symmetric_float(self):
     a = array([[1,2],[-2.0,4]],'f')
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,2,4,'array','real','skew-symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 18
0
 def test_simple_rectangular_real(self):
     a = [[1,2],[3.5,4],[5,6]]
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(3,2,6,'array','real','general'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 19
0
 def test_simple_complex(self):
     a = [[1,2],[3,4j]]
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,2,4,'array','complex','general'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 20
0
 def test_simple_rectangular(self):
     a = [[1, 2, 3], [4, 5, 6]]
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 3, 6, "array", "integer", "general"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 21
0
 def check_read(self, example, a, info):
     f = open(self.fn, 'w')
     f.write(example)
     f.close()
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 22
0
 def test_simple_rectangular(self):
     a = [[1, 2, 3], [4, 5, 6]]
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (2, 3, 6, 'array', 'integer', 'general'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 23
0
 def test_simple_real(self):
     a = [[1,2],[3,4.0]]
     fn = self.fn
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(2,2,4,'array','real','general'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 24
0
 def test_random_rect_real(self):
     sz = (20,15)
     a = rand(*sz)
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(20,15,300,'array','real','general'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 25
0
 def test_random_rect_real(self):
     sz = (20, 15)
     a = rand(*sz)
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (20, 15, 300, "array", "real", "general"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 26
0
 def test_random_rect_real(self):
     sz = (20, 15)
     a = rand(*sz)
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (20, 15, 300, 'array', 'real', 'general'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 27
0
 def test_random_symmetric_real(self):
     sz = (20,20)
     a = rand(*sz)
     a = a + transpose(a)
     fn = mktemp()
     mmwrite(fn,a)
     assert_equal(mminfo(fn),(20,20,400,'array','real','symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a,b)
Exemplo n.º 28
0
 def test_random_symmetric_real(self):
     sz = (20, 20)
     a = rand(*sz)
     a = a + transpose(a)
     fn = mktemp()
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (20, 20, 400, 'array', 'real', 'symmetric'))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 29
0
 def test_read_symmetric(self):
     fn = self.fn
     f = open(fn, "w")
     f.write(_symmetric_example)
     f.close()
     assert_equal(mminfo(fn), (5, 5, 7, "coordinate", "real", "symmetric"))
     a = [[1, 0, 0, 0, 0], [0, 10.5, 0, 250.5, 0], [0, 0, 0.015, 0, 0], [0, 250.5, 0, -280, 8], [0, 0, 0, 8, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 30
0
 def test_random_symmetric_real(self):
     sz = (20, 20)
     a = rand(*sz)
     a = a + transpose(a)
     fn = self.fn
     mmwrite(fn, a)
     assert_equal(mminfo(fn), (20, 20, 400, "array", "real", "symmetric"))
     b = mmread(fn)
     assert_array_almost_equal(a, b)
Exemplo n.º 31
0
 def test_simple_pattern(self):
     a = scipy.sparse.csr_matrix([[0, 1.5], [3.0, 2.5]])
     p = np.zeros_like(a.todense())
     p[a.todense() > 0] = 1
     info = (2, 2, 3, 'coordinate', 'pattern', 'general')
     mmwrite(self.fn, a, field='pattern')
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_array_almost_equal(p, b.todense())
Exemplo n.º 32
0
 def test_read_symmetric_pattern(self):
     fn = self.fn
     f = open(fn, "w")
     f.write(_symmetric_pattern_example)
     f.close()
     assert_equal(mminfo(fn), (5, 5, 7, "coordinate", "pattern", "symmetric"))
     a = [[1, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 1], [0, 0, 0, 1, 1]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 33
0
 def test_simple_pattern(self):
     a = scipy.sparse.csr_matrix([[0, 1.5], [3.0, 2.5]])
     p = np.zeros_like(a.todense())
     p[a.todense() > 0] = 1
     info = (2, 2, 3, 'coordinate', 'pattern', 'general')
     mmwrite(self.fn, a, field='pattern')
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_array_almost_equal(p, b.todense())
Exemplo n.º 34
0
 def test_read_general(self):
     fn = self.fn
     f = open(fn, "w")
     f.write(_general_example)
     f.close()
     assert_equal(mminfo(fn), (5, 5, 8, "coordinate", "real", "general"))
     a = [[1, 0, 0, 6, 0], [0, 10.5, 0, 0, 0], [0, 0, 0.015, 0, 0], [0, 250.5, 0, -280, 33.32], [0, 0, 0, 0, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 35
0
 def test_read_symmetric(self):
     fn = self.fn
     f = open(fn, 'w')
     f.write(_symmetric_example)
     f.close()
     assert_equal(mminfo(fn), (5, 5, 7, 'coordinate', 'real', 'symmetric'))
     a = [[1, 0, 0, 0, 0], [0, 10.5, 0, 250.5, 0], [0, 0, .015, 0, 0],
          [0, 250.5, 0, -280, 8], [0, 0, 0, 8, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 36
0
 def test_read_general(self):
     fn = self.fn
     f = open(fn, 'w')
     f.write(_general_example)
     f.close()
     assert_equal(mminfo(fn), (5, 5, 8, 'coordinate', 'real', 'general'))
     a = [[1, 0, 0, 6, 0], [0, 10.5, 0, 0, 0], [0, 0, .015, 0, 0],
          [0, 250.5, 0, -280, 33.32], [0, 0, 0, 0, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 37
0
    def test_empty_write_read(self):
        # http://projects.scipy.org/scipy/ticket/883

        b = scipy.sparse.coo_matrix((10, 10))
        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (10, 10, 0, 'coordinate', 'real', 'symmetric'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 38
0
    def test_empty_write_read(self):
        #http://projects.scipy.org/scipy/ticket/883

        b = scipy.sparse.coo_matrix((10,10))
        fn = mktemp()
        mmwrite(fn,b)

        assert_equal(mminfo(fn),(10,10,0,'coordinate','real','general'))
        a = b.todense()
        b = mmread(fn).todense()
        assert_array_almost_equal(a,b)
Exemplo n.º 39
0
    def test_empty_write_read(self):
        # https://github.com/scipy/scipy/issues/1410 (Trac #883)

        b = scipy.sparse.coo_matrix((10, 10))
        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (10, 10, 0, 'coordinate', 'real', 'symmetric'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 40
0
 def test_read_symmetric_pattern(self):
     fn = self.fn
     f = open(fn, 'w')
     f.write(_symmetric_pattern_example)
     f.close()
     assert_equal(mminfo(fn),
                  (5, 5, 7, 'coordinate', 'pattern', 'symmetric'))
     a = [[1, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0],
          [0, 1, 0, 1, 1], [0, 0, 0, 1, 1]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 41
0
    def test_empty_write_read(self):
        # https://github.com/scipy/scipy/issues/1410 (Trac #883)

        b = scipy.sparse.coo_matrix((10, 10))
        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (10, 10, 0, 'coordinate', 'real', 'symmetric'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 42
0
 def check_read(self, example, a, info, dense, over32, over64):
     with open(self.fn, 'w') as f:
         f.write(example)
     assert_equal(mminfo(self.fn), info)
     if (over32 and (np.intp(0).itemsize < 8)) or over64:
         assert_raises(OverflowError, mmread, self.fn)
     else:
         b = mmread(self.fn)
         if not dense:
             b = b.todense()
         assert_equal(a, b)
Exemplo n.º 43
0
 def check_read(self, example, a, info, dense, over32, over64):
     with open(self.fn, 'w') as f:
         f.write(example)
     assert_equal(mminfo(self.fn), info)
     if (over32 and (np.intp(0).itemsize < 8)) or over64:
         assert_raises(OverflowError, mmread, self.fn)
     else:
         b = mmread(self.fn)
         if not dense:
             b = b.todense()
         assert_equal(a, b)
Exemplo n.º 44
0
 def test_read_hermitian(self):
     fn = self.fn
     f = open(fn, 'w')
     f.write(_hermitian_example)
     f.close()
     assert_equal(mminfo(fn),
                  (5, 5, 7, 'coordinate', 'complex', 'hermitian'))
     a = [[1, 0, 0, 0, 0], [0, 10.5, 0, 250.5 - 22.22j, 0],
          [0, 0, .015, 0, 0], [0, 250.5 + 22.22j, 0, -280, -33.32j],
          [0, 0, 0, 33.32j, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 45
0
 def test_read_skew(self):
     """read a skew-symmetric matrix"""
     fn = mktemp()
     f = open(fn, 'w')
     f.write(_skew_example)
     f.close()
     assert_equal(mminfo(fn),
                  (5, 5, 7, 'coordinate', 'real', 'skew-symmetric'))
     a = [[1, 0, 0, 0, 0], [0, 10.5, 0, -250.5, 0], [0, 0, .015, 0, 0],
          [0, 250.5, 0, -280, 0], [0, 0, 0, 0, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a, b)
Exemplo n.º 46
0
 def test_read_general(self):
     fn = mktemp()
     f = open(fn,'w')
     f.write(_general_example)
     f.close()
     assert_equal(mminfo(fn),(5,5,8,'coordinate','real','general'))
     a = [[1, 0, 0, 6, 0],
          [0, 10.5, 0, 0, 0],
          [0, 0, .015, 0, 0],
          [0, 250.5, 0, -280, 33.32],
          [0, 0, 0, 0, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a,b)
Exemplo n.º 47
0
 def test_read_symmetric_pattern(self):
     fn = mktemp()
     f = open(fn,'w')
     f.write(_symmetric_pattern_example)
     f.close()
     assert_equal(mminfo(fn),(5,5,7,'coordinate','pattern','symmetric'))
     a = [[1, 0, 0, 0, 0],
          [0, 1, 0, 1, 0],
          [0, 0, 1, 0, 0],
          [0, 1, 0, 1, 1],
          [0, 0, 0, 1, 1]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a,b)
Exemplo n.º 48
0
 def test_read_hermitian(self):
     fn = self.fn
     f = open(fn,'w')
     f.write(_hermitian_example)
     f.close()
     assert_equal(mminfo(fn),(5,5,7,'coordinate','complex','hermitian'))
     a = [[1, 0, 0, 0, 0],
          [0, 10.5, 0, 250.5 - 22.22j, 0],
          [0, 0, .015, 0, 0],
          [0, 250.5 + 22.22j, 0, -280, -33.32j],
          [0, 0, 0, 33.32j, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a,b)
Exemplo n.º 49
0
 def test_read_skew(self):
     fn = self.fn
     f = open(fn,'w')
     f.write(_skew_example)
     f.close()
     assert_equal(mminfo(fn),(5,5,7,'coordinate','real','skew-symmetric'))
     a = [[1, 0, 0, 0, 0],
          [0, 10.5, 0, -250.5, 0],
          [0, 0, .015, 0, 0],
          [0, 250.5, 0, -280, 0],
          [0, 0, 0, 0, 12]]
     b = mmread(fn).todense()
     assert_array_almost_equal(a,b)
Exemplo n.º 50
0
    def test_real_write_read(self):
        I = array([0, 0, 1, 2, 3, 3, 3, 4])
        J = array([0, 3, 1, 2, 1, 3, 4, 4])
        V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0])

        b = scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5))

        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (5, 5, 8, 'coordinate', 'real', 'general'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 51
0
    def test_real_write_read(self):
        I = array([0, 0, 1, 2, 3, 3, 3, 4])
        J = array([0, 3, 1, 2, 1, 3, 4, 4])
        V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0])

        b = scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5))

        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (5, 5, 8, 'coordinate', 'real', 'general'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 52
0
    def test_complex_write_read(self):
        I = array([0, 0, 1, 2, 3, 3, 3, 4])
        J = array([0, 3, 1, 2, 1, 3, 4, 4])
        V = array([1.0 + 3j, 6.0 + 2j, 10.50 + 0.9j, 0.015 + -4.4j,
                   250.5 + 0j, -280.0 + 5j, 33.32 + 6.4j, 12.00 + 0.8j])

        b = scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5))

        mmwrite(self.fn, b)

        assert_equal(mminfo(self.fn),
                     (5, 5, 8, 'coordinate', 'complex', 'general'))
        a = b.todense()
        b = mmread(self.fn).todense()
        assert_array_almost_equal(a, b)
Exemplo n.º 53
0
Arquivo: spmv.py Projeto: nehaap/spmv
def multiply(fname):
    mat = mmread(fname)
    rows, cols, nnzs = mminfo(fname)[0:3]
    vec = np.ones((rows, 1), dtype=np.int)

    matcoo = mat.tocoo()
    start1 = timeit.default_timer()
    matcoo.dot(vec)
    stop1 = timeit.default_timer()
    t1 = (stop1 - start1) * math.pow(10, 6)

    matcsr = mat.tocsr()
    start2 = timeit.default_timer()
    matcsr.dot(vec)
    stop2 = timeit.default_timer()
    t2 = (stop2 - start2) * math.pow(10, 6)

    matcsc = mat.tocsc()
    start3 = timeit.default_timer()
    matcsc.dot(vec)
    stop3 = timeit.default_timer()
    t3 = (stop3 - start3) * math.pow(10, 6)

    matlil = mat.tolil()
    start4 = timeit.default_timer()
    matlil.dot(vec)
    stop4 = timeit.default_timer()
    t4 = (stop4 - start4) * math.pow(10, 6)

    matdia = mat.todia()
    start5 = timeit.default_timer()
    matdia.dot(vec)
    stop5 = timeit.default_timer()
    t5 = (stop5 - start5) * math.pow(10, 6)

    matdok = mat.todok()
    start6 = timeit.default_timer()
    matdok.dot(vec)
    stop6 = timeit.default_timer()
    t6 = (stop6 - start6) * math.pow(10, 6)

    return rows, cols, nnzs, t1, t2, t3, t4, t5, t6
Exemplo n.º 54
0
def generate_mm_and_plot(matrixname):
    matrixName=matrixname+ ".mtx"
    mm = open(matrixname +'.mm', 'w')
    outputName=matrixname + ".png"
    #outputName=matrixname + ".pdf"
    
    (n,n,nz,void,fld,symm) = mminfo(matrixName)
    A = mmread(matrixName).tocsr().tocoo()
    
    # creating a file in coo format    
    #print n, n, A.size
    mm.write( str(n) + ' ' + str(n) + ' ' + str(A.size) + '\n')
    for i in range(A.size):
        mm.write(  str(A.row[i])+ ' ' + str(A.col[i])+ ' ' + str(A.data[i])+  '\n')
        #print A.row[i]+1, A.col[i]+1 , A.data[i]
    # end for    
    #print repr(A)
    #print A.col
    #print A.size
    # end of creating a file in coo format    
    #pylab.title("Matrix :" + matrixname, fontsize=22)
    pylab.title("Matrix: " + matrixname + ", n:" + str(n) + ", nz:" + str(A.size) + '\n' ,fontsize=10 )
    pylab.spy(A,marker='.',markersize=1)
    pylab.savefig(outputName,format=None)
Exemplo n.º 55
0
    conf = SparkConf().setAppName("SparseMultiplication").setMaster("local[4]")
    sc = SparkContext(conf=conf)
    sqlContext = SQLContext(sc)
    print("Successfully imported Spark")

except ImportError as e:
    print("Can not import Spark", e)
    sys.exit(1)
"""if __name__ == "__main__":
    def myFunc(s):
        words = s.split("\n")
        return len(words)"""

fname = '/Users/nehapulipati/Downloads/bcsstk01.mtx'
mat = mmread(fname)
sp_rows, sp_cols, nnzs = mminfo(fname)[0:3]
newmat = mat.tocsc()
sm3 = scipy.sparse.rand(3, 2, density=0.2, format='csc')
rand_mat = scipy.sparse.rand(sp_cols, sp_cols, density=0.2, format='csc')
value1 = newmat.data
col_index1 = newmat.indices
row_pointers1 = newmat.indptr

value2 = rand_mat.data
col_index2 = rand_mat.indices
row_pointers2 = rand_mat.indptr

start2 = timeit.default_timer()
just = newmat * rand_mat
stop2 = timeit.default_timer()
t2 = (stop2 - start2)
Exemplo n.º 56
0
 def check_exact(self, a, info):
     mmwrite(self.fn, a)
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_equal(a, b)
Exemplo n.º 57
0
 def check(self, a, info):
     mmwrite(self.fn, a)
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_array_almost_equal(a.todense(), b.todense())