當前位置: 首頁>>代碼示例>>Python>>正文


Python interface.aslinearoperator方法代碼示例

本文整理匯總了Python中scipy.sparse.linalg.interface.aslinearoperator方法的典型用法代碼示例。如果您正苦於以下問題:Python interface.aslinearoperator方法的具體用法?Python interface.aslinearoperator怎麽用?Python interface.aslinearoperator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.sparse.linalg.interface的用法示例。


在下文中一共展示了interface.aslinearoperator方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_basic

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def test_basic(self):

        for M in self.cases:
            A = interface.aslinearoperator(M)
            M,N = A.shape

            assert_equal(A.matvec(np.array([1,2,3])), [14,32])
            assert_equal(A.matvec(np.array([[1],[2],[3]])), [[14],[32]])

            assert_equal(A * np.array([1,2,3]), [14,32])
            assert_equal(A * np.array([[1],[2],[3]]), [[14],[32]])

            assert_equal(A.rmatvec(np.array([1,2])), [9,12,15])
            assert_equal(A.rmatvec(np.array([[1],[2]])), [[9],[12],[15]])

            assert_equal(
                    A.matmat(np.array([[1,4],[2,5],[3,6]])),
                    [[14,32],[32,77]])

            assert_equal(A * np.array([[1,4],[2,5],[3,6]]), [[14,32],[32,77]])

            if hasattr(M,'dtype'):
                assert_equal(A.dtype, M.dtype) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:test_interface.py

示例2: test_basic

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def test_basic(self):

        for M in self.cases:
            A = interface.aslinearoperator(M)
            M,N = A.shape

            assert_equal(A.matvec(np.array([1,2,3])), [14,32])
            assert_equal(A.matvec(np.array([[1],[2],[3]])), [[14],[32]])

            assert_equal(A * np.array([1,2,3]), [14,32])
            assert_equal(A * np.array([[1],[2],[3]]), [[14],[32]])

            assert_equal(A.rmatvec(np.array([1,2])), [9,12,15])
            assert_equal(A.rmatvec(np.array([[1],[2]])), [[9],[12],[15]])
            assert_equal(A.H.matvec(np.array([1,2])), [9,12,15])
            assert_equal(A.H.matvec(np.array([[1],[2]])), [[9],[12],[15]])

            assert_equal(
                    A.matmat(np.array([[1,4],[2,5],[3,6]])),
                    [[14,32],[32,77]])

            assert_equal(A * np.array([[1,4],[2,5],[3,6]]), [[14,32],[32,77]])

            if hasattr(M,'dtype'):
                assert_equal(A.dtype, M.dtype) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:27,代碼來源:test_interface.py

示例3: _aslinearoperator_with_dtype

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def _aslinearoperator_with_dtype(m):
    m = aslinearoperator(m)
    if not hasattr(m, 'dtype'):
        x = np.zeros(m.shape[1])
        m.dtype = (m * x).dtype
    return m 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:arpack.py

示例4: assertCompatibleSystem

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def assertCompatibleSystem(self, A, xtrue):
        Afun = aslinearoperator(A)
        b = Afun.matvec(xtrue)
        x = lsmr(A,b)[0]
        assert_almost_equal(norm(x - xtrue), 0, 6) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:7,代碼來源:test_lsmr.py

示例5: setUp

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def setUp(self):
        self.n = 10
        self.A = lowerBidiagonalMatrix(20,self.n)
        self.xtrue = transpose(arange(self.n,0,-1))
        self.Afun = aslinearoperator(self.A)
        self.b = self.Afun.matvec(self.xtrue)
        self.returnValues = lsmr(self.A,self.b) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:9,代碼來源:test_lsmr.py

示例6: lsmrtest

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def lsmrtest(m, n, damp):
    """Verbose testing of lsmr"""

    A = lowerBidiagonalMatrix(m,n)
    xtrue = arange(n,0,-1, dtype=float)
    Afun = aslinearoperator(A)

    b = Afun.matvec(xtrue)

    atol = 1.0e-7
    btol = 1.0e-7
    conlim = 1.0e+10
    itnlim = 10*n
    show = 1

    x, istop, itn, normr, normar, norma, conda, normx \
      = lsmr(A, b, damp, atol, btol, conlim, itnlim, show)

    j1 = min(n,5)
    j2 = max(n-4,1)
    print(' ')
    print('First elements of x:')
    str = ['%10.4f' % (xi) for xi in x[0:j1]]
    print(''.join(str))
    print(' ')
    print('Last  elements of x:')
    str = ['%10.4f' % (xi) for xi in x[j2-1:]]
    print(''.join(str))

    r = b - Afun.matvec(x)
    r2 = sqrt(norm(r)**2 + (damp*norm(x))**2)
    print(' ')
    str = 'normr (est.)  %17.10e' % (normr)
    str2 = 'normr (true)  %17.10e' % (r2)
    print(str)
    print(str2)
    print(' ') 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:39,代碼來源:test_lsmr.py

示例7: test_dot

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def test_dot(self):

        for M in self.cases:
            A = interface.aslinearoperator(M)
            M,N = A.shape

            assert_equal(A.dot(np.array([1,2,3])), [14,32])
            assert_equal(A.dot(np.array([[1],[2],[3]])), [[14],[32]])

            assert_equal(
                    A.dot(np.array([[1,4],[2,5],[3,6]])),
                    [[14,32],[32,77]]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:14,代碼來源:test_interface.py

示例8: assertCompatibleSystem

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def assertCompatibleSystem(self, A, xtrue):
        Afun = aslinearoperator(A)
        b = Afun.matvec(xtrue)
        x = lsmr(A, b)[0]
        assert_almost_equal(norm(x - xtrue), 0, decimal=5) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_lsmr.py

示例9: setup_method

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def setup_method(self):
        self.n = 10
        self.A = lowerBidiagonalMatrix(20,self.n)
        self.xtrue = transpose(arange(self.n,0,-1))
        self.Afun = aslinearoperator(self.A)
        self.b = self.Afun.matvec(self.xtrue)
        self.returnValues = lsmr(self.A,self.b) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:9,代碼來源:test_lsmr.py

示例10: test_dtypes_of_operator_sum

# 需要導入模塊: from scipy.sparse.linalg import interface [as 別名]
# 或者: from scipy.sparse.linalg.interface import aslinearoperator [as 別名]
def test_dtypes_of_operator_sum():
    # gh-6078

    mat_complex = np.random.rand(2,2) + 1j * np.random.rand(2,2)
    mat_real = np.random.rand(2,2)

    complex_operator = interface.aslinearoperator(mat_complex)
    real_operator = interface.aslinearoperator(mat_real)

    sum_complex = complex_operator + complex_operator
    sum_real = real_operator + real_operator

    assert_equal(sum_real.dtype, np.float64)
    assert_equal(sum_complex.dtype, np.complex128) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:16,代碼來源:test_interface.py


注:本文中的scipy.sparse.linalg.interface.aslinearoperator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。