当前位置: 首页>>代码示例>>Python>>正文


Python NumpyVectorSpace.from_data方法代码示例

本文整理汇总了Python中pymor.vectorarrays.numpy.NumpyVectorSpace.from_data方法的典型用法代码示例。如果您正苦于以下问题:Python NumpyVectorSpace.from_data方法的具体用法?Python NumpyVectorSpace.from_data怎么用?Python NumpyVectorSpace.from_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymor.vectorarrays.numpy.NumpyVectorSpace的用法示例。


在下文中一共展示了NumpyVectorSpace.from_data方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_ext

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_ext(extension_alg):
    size = 5
    ident = np.identity(size)
    current = ident[0]
    for i in range(1, size):
        c = NumpyVectorSpace.from_data(current)
        n, _ = extension_alg(c, NumpyVectorSpace.from_data(ident[i]))
        assert np.allclose(n.data, ident[0:i+1])
        current = ident[0:i+1]
开发者ID:,项目名称:,代码行数:11,代码来源:

示例2: test_axpy

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_axpy():
    x = NumpyVectorSpace.from_data(np.array([1.]))
    y = NumpyVectorSpace.from_data(np.array([1.]))
    y.axpy(1 + 1j, x)
    assert y.data[0, 0] == 2 + 1j

    x = NumpyVectorSpace.from_data(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_data(np.array([1.]))
    y.axpy(-1, x)
    assert y.data[0, 0] == -1j
开发者ID:,项目名称:,代码行数:12,代码来源:

示例3: test_complex

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_complex():
    np.random.seed(0)
    I = np.eye(5)
    A = np.random.randn(5, 5)
    B = np.random.randn(5, 5)
    C = np.random.randn(3, 5)

    Iop = NumpyMatrixOperator(I)
    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)
    Cva = NumpyVectorSpace.from_data(C)

    # assemble_lincomb
    assert not np.iscomplexobj(Aop.assemble_lincomb((Iop, Bop), (1, 1))._matrix)
    assert not np.iscomplexobj(Aop.assemble_lincomb((Aop, Bop), (1, 1))._matrix)
    assert not np.iscomplexobj(Aop.assemble_lincomb((Aop, Bop), (1 + 0j, 1 + 0j))._matrix)
    assert np.iscomplexobj(Aop.assemble_lincomb((Aop, Bop), (1j, 1))._matrix)
    assert np.iscomplexobj(Aop.assemble_lincomb((Bop, Aop), (1, 1j))._matrix)

    # apply_inverse
    assert not np.iscomplexobj(Aop.apply_inverse(Cva).data)
    assert np.iscomplexobj((Aop * 1j).apply_inverse(Cva).data)
    assert np.iscomplexobj(Aop.assemble_lincomb((Aop, Bop), (1, 1j)).apply_inverse(Cva).data)
    assert np.iscomplexobj(Aop.apply_inverse(Cva * 1j).data)

    # append
    for rsrv in (0, 10):
        for o_ind in (slice(None), [0]):
            va = NumpyVectorSpace(5).empty(reserve=rsrv)
            va.append(Cva)
            D = np.random.randn(1, 5) + 1j * np.random.randn(1, 5)
            Dva = NumpyVectorSpace.from_data(D)

            assert not np.iscomplexobj(va.data)
            assert np.iscomplexobj(Dva.data)
            va.append(Dva[o_ind])
            assert np.iscomplexobj(va.data)

    # scal
    assert not np.iscomplexobj(Cva.data)
    assert np.iscomplexobj((Cva * 1j).data)
    assert np.iscomplexobj((Cva * (1 + 0j)).data)

    # axpy
    assert not np.iscomplexobj(Cva.data)
    Cva[0].axpy(1, Dva)
    assert np.iscomplexobj(Cva.data)

    Cva = NumpyVectorSpace.from_data(C)
    assert not np.iscomplexobj(Cva.data)
    Cva[0].axpy(1j, Dva)
    assert np.iscomplexobj(Cva.data)
开发者ID:,项目名称:,代码行数:54,代码来源:

示例4: test_blk_diag_apply_inverse

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_blk_diag_apply_inverse():
    np.random.seed(0)

    A = np.random.randn(2, 2)
    B = np.random.randn(3, 3)
    C = spla.block_diag(A, B)
    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)
    Cop = BlockDiagonalOperator((Aop, Bop))

    v1 = np.random.randn(2)
    v2 = np.random.randn(3)
    v = np.hstack((v1, v2))
    v1va = NumpyVectorSpace.from_data(v1)
    v2va = NumpyVectorSpace.from_data(v2)
    vva = BlockVectorSpace.make_array((v1va, v2va))

    wva = Cop.apply_inverse(vva)
    w = np.hstack((wva.block(0).data, wva.block(1).data))
    assert np.allclose(spla.solve(C, v), w)
开发者ID:,项目名称:,代码行数:22,代码来源:

示例5: test_scal

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_scal():
    v = np.array([[1, 2, 3],
                  [4, 5, 6]], dtype=float)
    v = NumpyVectorSpace.from_data(v)
    v.scal(1j)

    k = 0
    for i in range(2):
        for j in range(3):
            k += 1
            assert v.data[i, j] == k * 1j
开发者ID:,项目名称:,代码行数:13,代码来源:

示例6: test_vtkio

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_vtkio(rect_or_tria_grid):
    grid = rect_or_tria_grid
    steps = 4
    for dim in range(1, 2):
        for codim, data in enumerate((NumpyVectorSpace.from_data(np.zeros((steps, grid.size(c)))) for c in range(grid.dim+1))):
            with NamedTemporaryFile('wb') as out:
                if codim == 1:
                    with pytest.raises(NotImplementedError):
                        write_vtk(grid, data, out.name, codim=codim)
                else:
                    write_vtk(grid, data, out.name, codim=codim)
开发者ID:,项目名称:,代码行数:13,代码来源:

示例7: test_apply_transpose

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_apply_transpose():
    np.random.seed(0)

    A11 = np.random.randn(2, 3)
    A12 = np.random.randn(2, 4)
    A21 = np.zeros((5, 3))
    A22 = np.random.randn(5, 4)
    A = np.vstack((np.hstack((A11, A12)),
                   np.hstack((A21, A22))))
    A11op = NumpyMatrixOperator(A11)
    A12op = NumpyMatrixOperator(A12)
    A22op = NumpyMatrixOperator(A22)
    Aop = BlockOperator(np.array([[A11op, A12op], [None, A22op]]))

    v1 = np.random.randn(2)
    v2 = np.random.randn(5)
    v = np.hstack((v1, v2))
    v1va = NumpyVectorSpace.from_data(v1)
    v2va = NumpyVectorSpace.from_data(v2)
    vva = BlockVectorSpace.make_array((v1va, v2va))

    wva = Aop.apply_transpose(vva)
    w = np.hstack((wva.block(0).data, wva.block(1).data))
    assert np.allclose(A.T.dot(v), w)
开发者ID:,项目名称:,代码行数:26,代码来源:

示例8: test_real_imag

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_real_imag():
    A = np.array([[1 + 2j, 3 + 4j],
                  [5 + 6j, 7 + 8j],
                  [9 + 10j, 11 + 12j]])
    Ava = NumpyVectorSpace.from_data(A)
    Bva = Ava.real
    Cva = Ava.imag

    k = 0
    for i in range(3):
        for j in range(2):
            k += 1
            assert Bva.data[i, j] == k
            k += 1
            assert Cva.data[i, j] == k
开发者ID:,项目名称:,代码行数:17,代码来源:

示例9: _newton

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def _newton(order, **kwargs):
    mop = MonomOperator(order)
    rhs = NumpyVectorSpace.from_data([0.0])
    guess = NumpyVectorSpace.from_data([1.0])
    return newton(mop, rhs, initial_guess=guess, **kwargs)
开发者ID:,项目名称:,代码行数:7,代码来源:

示例10: numpy_vector_array_factory

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def numpy_vector_array_factory(length, dim, seed):
    np.random.seed(seed)
    return NumpyVectorSpace.from_data(np.random.random((length, dim)))
开发者ID:,项目名称:,代码行数:5,代码来源:

示例11: test_pairwise_dot

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_pairwise_dot():
    x = NumpyVectorSpace.from_data(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_data(np.array([1 - 1j]))
    z = x.pairwise_dot(y)
    assert z == 2j
开发者ID:,项目名称:,代码行数:7,代码来源:

示例12: test_dot

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_data [as 别名]
def test_dot():
    x = NumpyVectorSpace.from_data(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_data(np.array([1 - 1j]))
    z = x.dot(y)
    assert z[0, 0] == 2j
开发者ID:,项目名称:,代码行数:7,代码来源:


注:本文中的pymor.vectorarrays.numpy.NumpyVectorSpace.from_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。