コード例 #1
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #2
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #3
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #4
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #5
0
ファイル: MFModel.py プロジェクト: neerajg/sdap
 def matrixFactorization_graphlab(self,rows,cols,r,c,algo):
     if platform.system() == 'Windows':
         base_dir = 'D:'
     elif platform.system() == 'Linux':
         base_dir = '/workspace'
                         
     # Pull out the sparse sub-matrix for current co-cluster
     #print r,c
     Y_sparse = self.coo_submatrix_pull(rows,cols)
     # Convert Data into Matrix Market format and write the Training data to file
     Y_mm_file_name = base_dir + '/sdap/data/temp/mf'
     # Remove the current files in .../data/temp/
     #cmd = "rm -f" + base_dir + "/sdap/data/temp/*"
     #os.system(cmd)
     if os.path.isdir(base_dir + "/sdap/data/temp/"):
         shutil.rmtree(base_dir + "/sdap/data/temp/")
     os.mkdir(base_dir + "/sdap/data/temp/")
     Y_mm_file = open(Y_mm_file_name,'w')
     mm.mmwrite(Y_mm_file,Y_sparse,comment="")
     
     # Call Matrix Factorization code
     cmd = "~/graphlabapi/release/demoapps/pmf/pmf "+ Y_mm_file_name +" --matrixmarket=true --D="+str(self.D)+" --lambda="+str(self.lambda_reg)+" --minval=0.5 --maxval=5.0 --ncpus=16 --max_iter=50 --threshold=1e-6"
     subprocess.call(cmd,shell=True)#,stdout=subprocess.PIPE,stderr=subprocess.STDOUT) #TO DO replace 
     #os.system(cmd)
 
     # Read all the files for the output Latent Factors and return Us and Vs
     U,V = self.readLatentFactors(base_dir)
     #print U.shape, len(rows)
     #print V.shape, len(cols)
     #import sys
     #sys.exit()
     
     return U,V        
コード例 #6
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #7
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #8
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #9
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #10
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #11
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #12
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #13
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)
コード例 #14
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #15
0
ファイル: test_mmio.py プロジェクト: hitej/meta-core
 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)
コード例 #16
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #17
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #18
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #19
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #20
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #21
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #22
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #23
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #24
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #25
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 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)
コード例 #26
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
 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)
コード例 #27
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())
コード例 #28
0
ファイル: test_mmio.py プロジェクト: minrk/scipy
 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)
コード例 #29
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
 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())
コード例 #30
0
ファイル: test_mmio.py プロジェクト: AndreI11/SatStressGui
    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)
コード例 #31
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)
コード例 #32
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    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)
コード例 #33
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)
コード例 #34
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    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)
コード例 #35
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)
コード例 #36
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    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)
コード例 #37
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)
コード例 #38
0
ファイル: nmf.py プロジェクト: kimjingu/nonnegfac-python
def _mmio_example(m=100, n=100, k=10):
    print ('\nTesting mmio read and write ...\n')
    import scipy.io.mmio as mmio

    W_org = random.rand(m, k)
    H_org = random.rand(n, k)
    X = W_org.dot(H_org.T)
    X[random.rand(m, n) < 0.5] = 0
    X_sparse = sps.csr_matrix(X)

    filename = '_temp_mmio.mtx'
    mmio.mmwrite(filename, X_sparse)
    A = mmio.mmread(filename)

    alg = NMF_ANLS_BLOCKPIVOT()
    rslt = alg.run(X_sparse, k, max_iter=50)
コード例 #39
0
ファイル: test_mmio.py プロジェクト: hainm/scipy
 def test_precision(self):
     test_values = [pi] + [10 ** (i) for i in range(0, -10, -1)]
     test_precisions = range(1, 10)
     for value in test_values:
         for precision in test_precisions:
             # construct sparse matrix with test value at last main diagonal
             n = 10 ** precision + 1
             A = scipy.sparse.dok_matrix((n, n))
             A[n - 1, n - 1] = value
             # write matrix with test precision and read again
             mmwrite(self.fn, A, precision=precision)
             A = scipy.io.mmread(self.fn)
             # check for right entries in matrix
             assert_array_equal(A.row, [n - 1])
             assert_array_equal(A.col, [n - 1])
             assert_array_almost_equal(A.data, [float("%%.%dg" % precision % value)])
コード例 #40
0
ファイル: nmf.py プロジェクト: lomereiter/nonnegfac-python
def _mmio_example(m=100, n=100, k=10):
    print '\nTesting mmio read and write ...\n'
    import scipy.io.mmio as mmio

    W_org = random.rand(m, k)
    H_org = random.rand(n, k)
    X = W_org.dot(H_org.T)
    X[random.rand(n, k) < 0.5] = 0
    X_sparse = sps.csr_matrix(X)

    filename = '_temp_mmio.mtx'
    mmio.mmwrite(filename, X_sparse)
    A = mmio.mmread(filename)

    alg = NMF_ANLS_BLOCKPIVOT()
    rslt = alg.run(X_sparse, k, max_iter=50)
コード例 #41
0
ファイル: test_mmio.py プロジェクト: Aathi410/Pro123
 def test_precision(self):
     test_values = [pi] + [10**(i) for i in range(0, -10, -1)]
     test_precisions = range(1, 10)
     for value in test_values:
         for precision in test_precisions:
             # construct sparse matrix with test value at last main diagonal
             n = 10**precision + 1
             A = scipy.sparse.dok_matrix((n, n))
             A[n - 1, n - 1] = value
             # write matrix with test precision and read again
             mmwrite(self.fn, A, precision=precision)
             A = scipy.io.mmread(self.fn)
             # check for right entries in matrix
             assert_array_equal(A.row, [n - 1])
             assert_array_equal(A.col, [n - 1])
             assert_allclose(A.data, [float('%%.%dg' % precision % value)])
コード例 #42
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    def test_sparse_formats(self):
        mats = []

        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])
        mats.append(scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5)))

        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])
        mats.append(scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5)))

        for mat in mats:
            expected = mat.todense()
            for fmt in ['csr', 'csc', 'coo']:
                fn = mktemp(dir=self.tmpdir)  # safe, we own tmpdir
                mmwrite(fn, mat.asformat(fmt))

                result = mmread(fn).todense()
                assert_array_almost_equal(result, expected)
コード例 #43
0
    def test_sparse_formats(self):
        mats = []

        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])
        mats.append(scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5)))

        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])
        mats.append(scipy.sparse.coo_matrix((V, (I, J)), shape=(5, 5)))

        for mat in mats:
            expected = mat.todense()
            for fmt in ['csr', 'csc', 'coo']:
                fn = mktemp(dir=self.tmpdir)  # safe, we own tmpdir
                mmwrite(fn, mat.asformat(fmt))

                result = mmread(fn).todense()
                assert_array_almost_equal(result, expected)
コード例 #44
0
    def test_bzip2_py3(self):
        # test if fix for #2152 works
        try:
            # bz2 module isn't always built when building Python.
            import bz2
        except:
            return
        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)

        fn_bzip2 = "%s.bz2" % self.fn
        with open(self.fn, 'rb') as f_in:
            f_out = bz2.BZ2File(fn_bzip2, 'wb')
            f_out.write(f_in.read())
            f_out.close()

        a = mmread(fn_bzip2).todense()
        assert_array_almost_equal(a, b.todense())
コード例 #45
0
    def test_gzip_py3(self):
        # test if fix for #2152 works
        try:
            # gzip module can be missing from Python installation
            import gzip
        except:
            return
        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)

        fn_gzip = "%s.gz" % self.fn
        with open(self.fn, 'rb') as f_in:
            f_out = gzip.open(fn_gzip, 'wb')
            f_out.write(f_in.read())
            f_out.close()

        a = mmread(fn_gzip).todense()
        assert_array_almost_equal(a, b.todense())
コード例 #46
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    def test_gzip_py3(self):
        # test if fix for #2152 works
        try:
            # gzip module can be missing from Python installation
            import gzip
        except ImportError:
            return
        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)

        fn_gzip = "%s.gz" % self.fn
        with open(self.fn, 'rb') as f_in:
            f_out = gzip.open(fn_gzip, 'wb')
            f_out.write(f_in.read())
            f_out.close()

        a = mmread(fn_gzip).todense()
        assert_array_almost_equal(a, b.todense())
コード例 #47
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
    def test_bzip2_py3(self):
        # test if fix for #2152 works
        try:
            # bz2 module isn't always built when building Python.
            import bz2
        except ImportError:
            return
        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)

        fn_bzip2 = "%s.bz2" % self.fn
        with open(self.fn, 'rb') as f_in:
            f_out = bz2.BZ2File(fn_bzip2, 'wb')
            f_out.write(f_in.read())
            f_out.close()

        a = mmread(fn_bzip2).todense()
        assert_array_almost_equal(a, b.todense())
コード例 #48
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)
コード例 #49
0
    def exportMmf(self, filename):
        """Exports the matrix to a Matrix Market file of the given `filename`.
        """
        from scipy.io import mmio

        mmio.mmwrite(filename, self.matrix)
コード例 #50
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())
コード例 #51
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
 def check(self, a, info):
     mmwrite(self.fn, a)
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_array_almost_equal(a, b)
コード例 #52
0
ファイル: test_mmio.py プロジェクト: Kitchi/scipy
 def check_exact(self, a, info):
     mmwrite(self.fn, a)
     assert_equal(mminfo(self.fn), info)
     b = mmread(self.fn)
     assert_equal(a, b)