本文整理汇总了Python中pymor.vectorarrays.numpy.NumpyVectorSpace.make_array方法的典型用法代码示例。如果您正苦于以下问题:Python NumpyVectorSpace.make_array方法的具体用法?Python NumpyVectorSpace.make_array怎么用?Python NumpyVectorSpace.make_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymor.vectorarrays.numpy.NumpyVectorSpace
的用法示例。
在下文中一共展示了NumpyVectorSpace.make_array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: projected_to_subbasis
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def projected_to_subbasis(self, dim_range=None, dim_source=None, dim_collateral=None, name=None):
assert dim_source is None or dim_source <= self.source.dim
assert dim_range is None or dim_range <= self.range.dim
assert dim_collateral is None or dim_collateral <= self.restricted_operator.range.dim
if not isinstance(self.projected_collateral_basis.space, NumpyVectorSpace):
raise NotImplementedError
name = name or '{}_projected_to_subbasis'.format(self.name)
interpolation_matrix = self.interpolation_matrix[:dim_collateral, :dim_collateral]
if dim_collateral is not None:
restricted_operator, source_dofs = self.restricted_operator.restricted(np.arange(dim_collateral))
else:
restricted_operator = self.restricted_operator
old_pcb = self.projected_collateral_basis
projected_collateral_basis = NumpyVectorSpace.make_array(old_pcb.data[:dim_collateral, :dim_range],
old_pcb.space.id)
old_sbd = self.source_basis_dofs
source_basis_dofs = NumpyVectorSpace.make_array(old_sbd.data[:dim_source]) if dim_collateral is None \
else NumpyVectorSpace.make_array(old_sbd.data[:dim_source, source_dofs])
return ProjectedEmpiciralInterpolatedOperator(restricted_operator, interpolation_matrix,
source_basis_dofs, projected_collateral_basis, self.triangular,
self.source.id, solver_options=self.solver_options, name=name)
示例2: visualize
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def visualize(self, U, codim=2, **kwargs):
"""Visualize scalar data associated to the grid as a patch plot.
Parameters
----------
U
|NumPy array| of the data to visualize. If `U.dim == 2 and len(U) > 1`, the
data is visualized as a time series of plots. Alternatively, a tuple of
|Numpy arrays| can be provided, in which case a subplot is created for
each entry of the tuple. The lengths of all arrays have to agree.
codim
The codimension of the entities the data in `U` is attached to (either 0 or 2).
kwargs
See :func:`~pymor.gui.qt.visualize_patch`
"""
from pymor.gui.qt import visualize_patch
from pymor.vectorarrays.interfaces import VectorArrayInterface
from pymor.vectorarrays.numpy import NumpyVectorSpace, NumpyVectorArray
if isinstance(U, (np.ndarray, VectorArrayInterface)):
U = (U,)
assert all(isinstance(u, (np.ndarray, VectorArrayInterface)) for u in U)
U = tuple(NumpyVectorSpace.make_array(u) if isinstance(u, np.ndarray) else
u if isinstance(u, NumpyVectorArray) else
NumpyVectorSpace.make_array(u.data)
for u in U)
bounding_box = kwargs.pop('bounding_box', self.domain)
visualize_patch(self, U, codim=codim, bounding_box=bounding_box, **kwargs)
示例3: projected
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def projected(self, range_basis, source_basis, product=None, name=None):
assert source_basis is None or source_basis in self.source
assert range_basis is None or range_basis in self.range
assert product is None or product.source == product.range == self.range
if len(self.interpolation_dofs) == 0:
return ZeroOperator(self.source, self.range, self.name).projected(range_basis, source_basis, product, name)
elif not hasattr(self, 'restricted_operator') or source_basis is None:
return super().projected(range_basis, source_basis, product, name)
else:
name = name or self.name + '_projected'
if range_basis is not None:
if product is None:
projected_collateral_basis = NumpyVectorSpace.make_array(self.collateral_basis.dot(range_basis),
self.range.id)
else:
projected_collateral_basis = NumpyVectorSpace.make_array(product.apply2(self.collateral_basis,
range_basis),
self.range.id)
else:
projected_collateral_basis = self.collateral_basis
return ProjectedEmpiciralInterpolatedOperator(self.restricted_operator, self.interpolation_matrix,
NumpyVectorSpace.make_array(source_basis.components(self.source_dofs)),
projected_collateral_basis, self.triangular,
self.source.id, None, name)
示例4: save
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def save(self):
if not config.HAVE_PYVTK:
msg = QMessageBox(QMessageBox.Critical, 'Error', 'VTK output disabled. Pleas install pyvtk.')
msg.exec_()
return
filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0]
base_name = filename.split('.vtu')[0].split('.vtk')[0].split('.pvd')[0]
if base_name:
if len(self.U) == 1:
write_vtk(self.grid, NumpyVectorSpace.make_array(self.U[0]), base_name, codim=self.codim)
else:
for i, u in enumerate(self.U):
write_vtk(self.grid, NumpyVectorSpace.make_array(u), '{}-{}'.format(base_name, i),
codim=self.codim)
示例5: action_ProjectedEmpiciralInterpolatedOperator
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def action_ProjectedEmpiciralInterpolatedOperator(self, op):
if not isinstance(op.projected_collateral_basis.space, NumpyVectorSpace):
raise NotImplementedError
restricted_operator = op.restricted_operator
old_pcb = op.projected_collateral_basis
projected_collateral_basis = NumpyVectorSpace.make_array(old_pcb.to_numpy()[:, :self.dim_range],
old_pcb.space.id)
old_sbd = op.source_basis_dofs
source_basis_dofs = NumpyVectorSpace.make_array(old_sbd.to_numpy()[:self.dim_source])
return ProjectedEmpiciralInterpolatedOperator(restricted_operator, op.interpolation_matrix,
source_basis_dofs, projected_collateral_basis, op.triangular,
op.source.id, solver_options=op.solver_options, name=op.name)
示例6: test_to_matrix
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def test_to_matrix():
np.random.seed(0)
A = np.random.randn(2, 2)
B = np.random.randn(3, 3)
C = np.random.randn(3, 3)
X = np.bmat([[np.eye(2) + A, np.zeros((2, 3))], [np.zeros((3, 2)), B.dot(C.T)]])
C = sps.csc_matrix(C)
Aop = NumpyMatrixOperator(A)
Bop = NumpyMatrixOperator(B)
Cop = NumpyMatrixOperator(C)
Xop = BlockDiagonalOperator([LincombOperator([IdentityOperator(NumpyVectorSpace(2)), Aop],
[1, 1]), Concatenation(Bop, AdjointOperator(Cop))])
assert np.allclose(X, to_matrix(Xop))
assert np.allclose(X, to_matrix(Xop, format='csr').toarray())
np.random.seed(0)
V = np.random.randn(10, 2)
Vva = NumpyVectorSpace.make_array(V.T)
Vop = VectorArrayOperator(Vva)
assert np.allclose(V, to_matrix(Vop))
Vop = VectorArrayOperator(Vva, transposed=True)
assert np.allclose(V, to_matrix(Vop).T)
示例7: ComponentProjection
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
class ComponentProjection(OperatorBase):
"""|Operator| representing the projection of a |VectorArray| on some of its components.
Parameters
----------
components
List or 1D |NumPy array| of the indices of the vector
:meth:`~pymor.vectorarrays.interfaces.VectorArrayInterface.components` that ar
to be extracted by the operator.
source
Source |VectorSpace| of the operator.
name
Name of the operator.
"""
linear = True
def __init__(self, components, source, name=None):
assert all(0 <= c < source.dim for c in components)
self.components = np.array(components, dtype=np.int32)
self.range = NumpyVectorSpace(len(components))
self.source = source
self.name = name
def apply(self, U, mu=None):
assert U in self.source
return self.range.make_array(U.components(self.components))
def restricted(self, dofs):
assert all(0 <= c < self.range.dim for c in dofs)
source_dofs = self.components[dofs]
return IdentityOperator(NumpyVectorSpace(len(source_dofs))), source_dofs
示例8: with_cb_dim
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def with_cb_dim(self, dim):
assert dim <= self.restricted_operator.range.dim
interpolation_matrix = self.interpolation_matrix[:dim, :dim]
restricted_operator, source_dofs = self.restricted_operator.restricted(np.arange(dim))
old_pcb = self.projected_collateral_basis
projected_collateral_basis = NumpyVectorSpace.make_array(old_pcb.to_numpy()[:dim, :])
old_sbd = self.source_basis_dofs
source_basis_dofs = NumpyVectorSpace.make_array(old_sbd.to_numpy()[:, source_dofs])
return ProjectedEmpiciralInterpolatedOperator(restricted_operator, interpolation_matrix,
source_basis_dofs, projected_collateral_basis, self.triangular,
solver_options=self.solver_options, name=self.name)
示例9: restricted
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def restricted(self, dofs):
assert all(0 <= c < self.range.dim for c in dofs)
if not self.transposed:
restricted_value = NumpyVectorSpace.make_array(self._array.components(dofs))
return VectorArrayOperator(restricted_value, False), np.arange(self.source.dim, dtype=np.int32)
else:
raise NotImplementedError
示例10: action_EmpiricalInterpolatedOperator
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def action_EmpiricalInterpolatedOperator(self, op):
range_basis, source_basis, product = self.range_basis, self.source_basis, self.product
if len(op.interpolation_dofs) == 0:
return self.apply(ZeroOperator(op.range, op.source, op.name))
elif not hasattr(op, 'restricted_operator') or source_basis is None:
raise RuleNotMatchingError('Has no restricted operator or source_basis is None')
else:
if range_basis is not None:
projected_collateral_basis = NumpyVectorSpace.make_array(op.collateral_basis.inner(range_basis,
product),
op.range.id)
else:
projected_collateral_basis = op.collateral_basis
return ProjectedEmpiciralInterpolatedOperator(op.restricted_operator, op.interpolation_matrix,
NumpyVectorSpace.make_array(source_basis.dofs(op.source_dofs)),
projected_collateral_basis, op.triangular,
op.source.id, None, op.name)
示例11: reconstruct
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def reconstruct(self, U):
"""Reconstruct high-dimensional vector from reduced vector `U`."""
assert isinstance(U.space, NumpyVectorSpace)
UU = np.zeros((len(U), self.dim))
UU[:, :self.dim_subbasis] = U.data
UU = NumpyVectorSpace.make_array(UU, U.space.id)
if self.old_recontructor:
return self.old_recontructor.reconstruct(UU)
else:
return UU
示例12: test_to_matrix_VectorArrayOperator
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def test_to_matrix_VectorArrayOperator():
np.random.seed(0)
V = np.random.randn(10, 2)
Vva = NumpyVectorSpace.make_array(V.T)
Vop = VectorArrayOperator(Vva)
assert_type_and_allclose(V, Vop, 'dense')
Vop = VectorArrayOperator(Vva, adjoint=True)
assert_type_and_allclose(V.T, Vop, 'dense')
示例13: apply
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def apply(self, U, mu=None):
mu = self.parse_parameter(mu)
if len(self.interpolation_dofs) == 0:
return self.range.zeros(len(U))
if hasattr(self, 'restricted_operator'):
U_dofs = NumpyVectorSpace.make_array(U.dofs(self.source_dofs))
AU = self.restricted_operator.apply(U_dofs, mu=mu)
else:
AU = NumpyVectorSpace.make_array(self.operator.apply(U, mu=mu).dofs(self.interpolation_dofs))
try:
if self.triangular:
interpolation_coefficients = solve_triangular(self.interpolation_matrix, AU.to_numpy().T,
lower=True, unit_diagonal=True).T
else:
interpolation_coefficients = solve(self.interpolation_matrix, AU.to_numpy().T).T
except ValueError: # this exception occurs when AU contains NaNs ...
interpolation_coefficients = np.empty((len(AU), len(self.collateral_basis))) + np.nan
return self.collateral_basis.lincomb(interpolation_coefficients)
示例14: action_ConstantOperator
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def action_ConstantOperator(self, op):
range_basis, source_basis, product = self.range_basis, self.source_basis, self.product
if range_basis is not None:
projected_value = NumpyVectorSpace.make_array(range_basis.inner(op._value, product).T, op.range.id)
else:
projected_value = op._value
if source_basis is None:
return ConstantOperator(projected_value, op.source, name=op.name)
else:
return ConstantOperator(projected_value, NumpyVectorSpace(len(source_basis), op.source.id),
name=op.name)
示例15: apply_inverse
# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import make_array [as 别名]
def apply_inverse(self, V, mu=None, least_squares=False):
assert V in self.range
assert not self.functional and not self.vector
if V.dim == 0:
if self.source.dim == 0 and least_squares:
return self.source.make_array([np.zeros(0) for _ in range(len(V))])
else:
raise InversionError
op = NumpyMatrixOperator(self.matrix, solver_options=self.solver_options)
return self.source.make_array([op.apply_inverse(NumpyVectorSpace.make_array(v._array),
least_squares=least_squares).to_numpy().ravel()
for v in V._list])