本文整理汇总了Python中pymor.vectorarrays.numpy.NumpyVectorSpace.to_numpy方法的典型用法代码示例。如果您正苦于以下问题:Python NumpyVectorSpace.to_numpy方法的具体用法?Python NumpyVectorSpace.to_numpy怎么用?Python NumpyVectorSpace.to_numpy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymor.vectorarrays.numpy.NumpyVectorSpace
的用法示例。
在下文中一共展示了NumpyVectorSpace.to_numpy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_complex
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import to_numpy [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_numpy(C)
# lincombs
assert not np.iscomplexobj((Iop * 1 + Bop * 1).assemble().matrix)
assert not np.iscomplexobj((Aop * 1 + Bop * 1).assemble().matrix)
assert np.iscomplexobj((Aop * (1+0j) + Bop * (1+0j)).assemble().matrix)
assert np.iscomplexobj((Aop * 1j + Bop * 1).assemble().matrix)
assert np.iscomplexobj((Bop * 1 + Aop * 1j).assemble().matrix)
# apply_inverse
assert not np.iscomplexobj(Aop.apply_inverse(Cva).to_numpy())
assert np.iscomplexobj((Aop * 1j).apply_inverse(Cva).to_numpy())
assert np.iscomplexobj((Aop * 1 + Bop * 1j).assemble().apply_inverse(Cva).to_numpy())
assert np.iscomplexobj(Aop.apply_inverse(Cva * 1j).to_numpy())
# 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_numpy(D)
assert not np.iscomplexobj(va.to_numpy())
assert np.iscomplexobj(Dva.to_numpy())
va.append(Dva[o_ind])
assert np.iscomplexobj(va.to_numpy())
# scal
assert not np.iscomplexobj(Cva.to_numpy())
assert np.iscomplexobj((Cva * 1j).to_numpy())
assert np.iscomplexobj((Cva * (1 + 0j)).to_numpy())
# axpy
assert not np.iscomplexobj(Cva.to_numpy())
Cva[0].axpy(1, Dva)
assert np.iscomplexobj(Cva.to_numpy())
Cva = NumpyVectorSpace.from_numpy(C)
assert not np.iscomplexobj(Cva.to_numpy())
Cva[0].axpy(1j, Dva)
assert np.iscomplexobj(Cva.to_numpy())