当前位置: 首页>>代码示例>>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;未经允许,请勿转载。