pymor.vectorarrays package¶
Submodules¶
block module¶
-
class
pymor.vectorarrays.block.BlockVectorArray(blocks, space)[source]¶ Bases:
pymor.vectorarrays.interface.VectorArrayVectorArraywhere each vector is a direct sum of sub-vectors.Given a list of equal length
VectorArraysblocks, thisVectorArrayrepresents the direct sums of the vectors contained in the arrays. The associatedVectorSpaceisBlockVectorSpace.BlockVectorArraycan be used in conjunction withBlockOperator.Methods
amax,append,axpy,block,conj,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scal,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
copy(deep=False)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
property
imag¶ Imaginary part.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
lincomb(coefficients)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
property
real¶ Real part.
-
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
sup_norm()[source]¶ The l-infinity-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
to_numpy(ensure_copy=False)[source]¶ Return (len(self), self.dim) NumPy Array with the data stored in the array.
Parameters
- ensure_copy
If
False, modifying the returnedNumPy arraymight alter the originalVectorArray. IfTruealways a copy of the array data is made.
-
-
class
pymor.vectorarrays.block.BlockVectorArrayView(base, ind)[source]¶ Bases:
pymor.vectorarrays.block.BlockVectorArrayMethods
amax,append,axpy,block,conj,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scal,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
-
class
pymor.vectorarrays.block.BlockVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.interface.VectorSpaceVectorSpaceofBlockVectorArrays.A
BlockVectorSpaceis defined by theVectorSpacesof the individual subblocks which constitute a given array. In particular for a given :class`BlockVectorArray`U, we have the identity(U.blocks[0].space, U.blocks[1].space, ..., U.blocks[-1].space) == U.space.
Parameters
- subspaces
The tuple defined above.
Methods
from_numpy,make_array,make_block_diagonal_array,zerosAttributes
-
from_numpy(data, ensure_copy=False)[source]¶ Create a
VectorArrayfrom aNumPy arrayNote that this method will not be supported by all vector space implementations.
Parameters
- data
NumPyarray of shape(len, dim)wherelenis the number of vectors anddimtheir dimension.- ensure_copy
If
False, modifying the returnedVectorArraymight alter the originalNumPy array. IfTruealways a copy of the array data is made.
Returns
A
VectorArraywithdataas data.
-
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectorsParameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.
constructions module¶
-
pymor.vectorarrays.constructions.cat_arrays(vector_arrays)[source]¶ Return a new
VectorArraywhich is a concatenation of the arrays invector_arrays.
interface module¶
-
class
pymor.vectorarrays.interface.VectorArray[source]¶ Bases:
pymor.core.base.BasicObjectInterface for vector arrays.
A vector array should be thought of as a list of (possibly high-dimensional) vectors. While the vectors themselves will be inaccessible in general (e.g. because they are managed by an external PDE solver code), operations on the vectors like addition can be performed via this interface.
It is assumed that the number of vectors is small enough such that scalar data associated to each vector can be handled on the Python side. As such, methods like
l2_normorgramianwill always returnNumPy arrays.An implementation of the
VectorArrayviaNumPy arraysis given byNumpyVectorArray. In general, it is the implementors decision how memory is allocated internally (e.g. continuous block of memory vs. list of pointers to the individual vectors.) Thus, no general assumptions can be made on the costs of operations like appending to or removing vectors from the array. As a hint for ‘continuous block of memory’ implementations,zerosprovides areservekeyword argument which allows to specify to what size the array is assumed to grow.As with
NumPy array,VectorArrayscan be indexed with numbers, slices and lists or one-dimensionalNumPy arrays. Indexing will always return a newVectorArraywhich acts as a view into the original data. Thus, if the indexed array is modified viascaloraxpy, the vectors in the original array will be changed. Indices may be negative, in which case the vector is selected by counting from the end of the array. Moreover indices can be repeated, in which case the corresponding vector is selected several times. The resulting view will be immutable, however.Note
It is disallowed to append vectors to a
VectorArrayview or to remove vectors from it. Removing vectors from an array with existing views will lead to undefined behavior of these views. As such, it is generally advisable to make acopyof a view for long term storage. Sincecopyhas copy-on-write semantics, this will usually cause little overhead.Methods
amax,append,axpy,check_ind,check_ind_unique,conj,copy,dofs,dot,empty,full,gramian,inner,l1_norm,l2_norm,l2_norm2,len_ind,len_ind_unique,lincomb,norm,norm2,normalize_ind,ones,pairwise_dot,pairwise_inner,random,scal,sub_index,sup_norm,to_numpy,zeros,__delitem__,__getitem__,__len__Attributes
-
dim¶ The dimension of the vectors in the array.
-
is_view¶ Trueif the array is a view obtained by indexing another array.
-
space¶ The
VectorSpacethe array belongs to.
-
abstract
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
abstract
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
abstract
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
abstract
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
check_ind(ind)[source]¶ Check if
indis an admissible list of indices in the sense of the class documentation.
-
check_ind_unique(ind)[source]¶ Check if
indis an admissible list of non-repeated indices in the sense of the class documentation.
-
abstract
copy(deep=False)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
abstract
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
abstract
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
empty(reserve=0)[source]¶ Create an empty
VectorArrayof the sameVectorSpace.This is a shorthand for
self.space.zeros(0, reserve).Parameters
- reserve
Hint for the backend to which length the array will grow.
Returns
An empty
VectorArray.
-
full(value, count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to the same value.This is a shorthand for
self.space.full(value, count, reserve).Parameters
- value
The value each DOF should be set to.
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set tovalue.
-
property
imag¶ Imaginary part.
-
inner(other, product=None)[source]¶ Inner products w.r.t. given product
Operator.Equivalent to
self.dot(other)ifproductis None, else equivalent toproduct.apply2(self, other).
-
abstract
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
abstract
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
abstract
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
abstract
lincomb(coefficients)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
norm(product=None, tol=1e-10, raise_complex=True)[source]¶ Norm w.r.t. given inner product
Operator.Equivalent to
self.l2_norm()ifproductis None, else equivalent tonp.sqrt(product.pairwise_apply2(self, self)). Ifraise_complexisTrue, aValueErrorexception is raised if there are complex norm squares of absolute value larger thantol.Defaults
tol, raise_complex (see
pymor.core.defaults)
-
norm2(product=None, tol=1e-10, raise_complex=True)[source]¶ Squared norm w.r.t. given inner product
Operator.Equivalent to
self.l2_norm2()ifproductis None, else equivalent toproduct.pairwise_apply2(self, self). Ifraise_complexisTrue, aValueErrorexception is raised if there are complex norm squares of absolute value larger thantol.Defaults
tol, raise_complex (see
pymor.core.defaults)
-
normalize_ind(ind)[source]¶ Normalize given indices such that they are independent of the array length.
-
ones(count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors of the sameVectorSpacewith all DOFs set to one.This is a shorthand for
self.space.full(1., count, reserve).Parameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set to one.
-
abstract
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
pairwise_inner(other, product=None)[source]¶ Pairwise inner products w.r.t. given product
Operator.Equivalent to
self.pairwise_dot(other)ifproductis None, else equivalent toproduct.pairwise_apply2(self, other).
-
random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]¶ Create a
VectorArrayof vectors with random entries.This is a shorthand for
self.space.random(count, distribution, radom_state, seed, **kwargs).Supported random distributions:
'uniform': Uniform distribution in half-open interval [`low`, `high`). 'normal': Normal (Gaussian) distribution with mean `loc` and standard deviation `scale`.Note that not all random distributions are necessarily implemented by all
VectorSpaceimplementations.Parameters
- count
The number of vectors.
- distribution
Random distribution to use (
'uniform','normal').- low
Lower bound for
'uniform'distribution (defaults to0).- high
Upper bound for
'uniform'distribution (defaults to1).- loc
Mean for
'normal'distribution (defaults to0).- scale
Standard deviation for
'normal'distribution (defaults to1).- random_state
RandomStateto use for sampling. IfNone, a new random state is generated usingseedas random seed, or thedefaultrandom state is used.- seed
If not
None, a new radom state with this seed is used.- reserve
Hint for the backend to which length the array will grow.
-
property
real¶ Real part.
-
abstract
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
sup_norm()[source]¶ The l-infinity-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
to_numpy(ensure_copy=False)[source]¶ Return (len(self), self.dim) NumPy Array with the data stored in the array.
Parameters
- ensure_copy
If
False, modifying the returnedNumPy arraymight alter the originalVectorArray. IfTruealways a copy of the array data is made.
-
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectors of the sameVectorSpace.This is a shorthand for
self.space.zeros(count, reserve).Parameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set to zero.
-
-
class
pymor.vectorarrays.interface.VectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.core.base.ImmutableObjectClass describing a vector space.
Vector spaces act as factories for
VectorArraysof vectors contained in them. As such, they hold all data necessary to createVectorArraysof a given type (e.g. the dimension of the vectors, or a socket for communication with an external PDE solver).New
VectorArraysof null vectors are created viazeros. Themake_arraymethod builds a newVectorArrayfrom given raw data of the underlying linear algebra backend (e.g. aNumPy arrayin the case ofNumpyVectorSpace). Some vector spaces can create newVectorArraysfrom a givenNumPy arrayvia thefrom_numpymethod.Each vector space has a string
idto distinguish mathematically different spaces appearing in the formulation of a given problem.Vector spaces can be compared for equality via the
==and!=operators. To test if a givenVectorArrayis an element of the space, theinoperator can be used.Methods
empty,from_data,from_numpy,full,make_array,ones,random,zerosAttributes
-
id¶ None, or a string describing the mathematical identity of the vector space (for instance to distinguish different components in an equation system).
-
dim¶ The dimension (number of degrees of freedom) of the vectors contained in the space.
-
is_scalar¶ Equivalent to
isinstance(space, NumpyVectorSpace) and space.dim == 1 and space.id is None.
-
empty(reserve=0)[source]¶ Create an empty
VectorArrayThis is a shorthand for
self.zeros(0, reserve).Parameters
- reserve
Hint for the backend to which length the array will grow.
Returns
An empty
VectorArray.
-
from_numpy(data, ensure_copy=False)[source]¶ Create a
VectorArrayfrom aNumPy arrayNote that this method will not be supported by all vector space implementations.
Parameters
- data
NumPyarray of shape(len, dim)wherelenis the number of vectors anddimtheir dimension.- ensure_copy
If
False, modifying the returnedVectorArraymight alter the originalNumPy array. IfTruealways a copy of the array data is made.
Returns
A
VectorArraywithdataas data.
-
full(value, count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to the same value.Parameters
- value
The value each DOF should be set to.
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set tovalue.
-
abstract
make_array(**kwargs)[source]¶ Create a
VectorArrayfrom raw data.This method is used in the implementation of
OperatorsandModelsto create newVectorArraysfrom raw data of the underlying solver backends. The ownership of the data is transferred to the newly created array.The exact signature of this method depends on the wrapped solver backend.
-
ones(count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to one.This is a shorthand for
self.full(1., count, reserve).Parameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set to one.
-
random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]¶ Create a
VectorArrayof vectors with random entries.Supported random distributions:
'uniform': Uniform distribution in half-open interval [`low`, `high`). 'normal': Normal (Gaussian) distribution with mean `loc` and standard deviation `scale`.Note that not all random distributions are necessarily implemented by all
VectorSpaceimplementations.Parameters
- count
The number of vectors.
- distribution
Random distribution to use (
'uniform','normal').- low
Lower bound for
'uniform'distribution (defaults to0).- high
Upper bound for
'uniform'distribution (defaults to1).- loc
Mean for
'normal'distribution (defaults to0).- scale
Standard deviation for
'normal'distribution (defaults to1).- random_state
RandomStateto use for sampling. IfNone, a new random state is generated usingseedas random seed, or thedefaultrandom state is used.- seed
If not
None, a new random state with this seed is used.- reserve
Hint for the backend to which length the array will grow.
-
abstract
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectorsParameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.
-
list module¶
-
class
pymor.vectorarrays.list.ComplexifiedListVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.list.ListVectorSpaceMethods
full_vector,make_vector,random_vector,real_full_vector,real_make_vector,real_random_vector,real_vector_from_numpy,real_zero_vector,vector_from_numpy,zero_vectorfrom_numpy,full,make_array,ones,ones_vector,random,space_from_dim,space_from_vector_obj,zerosempty,from_dataAttributes
-
complexified_vector_type¶ alias of
ComplexifiedVector
-
-
class
pymor.vectorarrays.list.ComplexifiedVector(real_part, imag_part)[source]¶ Bases:
pymor.vectorarrays.list.VectorMethods
amax,axpy,conj,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,scal,sup_norm,to_numpyAttributes
imag,real
-
class
pymor.vectorarrays.list.CopyOnWriteVector[source]¶ Bases:
pymor.vectorarrays.list.VectorMethods
axpy,copy,from_instance,scalamax,conj,dofs,dot,l1_norm,l2_norm,l2_norm2,sup_normAttributes
imag,real
-
class
pymor.vectorarrays.list.ListVectorArray(vectors, space)[source]¶ Bases:
pymor.vectorarrays.interface.VectorArrayVectorArrayimplemented as a Python list of vectors.This
VectorArrayimplementation is the first choice when creating pyMOR wrappers for external solvers which are based on single vector objects. In order to do so, a wrapping subclass ofVectorhas to be provided on which the implementation ofListVectorArraywill operate. The associatedVectorSpaceis a subclass ofListVectorSpace.For an example, see
NumpyVector,NumpyListVectorSpaceorFenicsVector,FenicsVectorSpace.Methods
amax,append,axpy,conj,copy,dofs,dot,gramian,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scal,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
copy(deep=False)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
property
imag¶ Imaginary part.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
lincomb(coefficients)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
property
real¶ Real part.
-
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
sup_norm()[source]¶ The l-infinity-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
to_numpy(ensure_copy=False)[source]¶ Return (len(self), self.dim) NumPy Array with the data stored in the array.
Parameters
- ensure_copy
If
False, modifying the returnedNumPy arraymight alter the originalVectorArray. IfTruealways a copy of the array data is made.
-
-
class
pymor.vectorarrays.list.ListVectorArrayView(base, ind)[source]¶ Bases:
pymor.vectorarrays.list.ListVectorArrayMethods
amax,conj,copy,dofs,dot,gramian,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
data,dim-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
-
class
pymor.vectorarrays.list.ListVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.interface.VectorSpaceVectorSpaceofListVectorArrays.Methods
from_numpy,full,full_vector,make_array,make_vector,ones,ones_vector,random,random_vector,space_from_dim,space_from_vector_obj,vector_from_numpy,zero_vector,zerosempty,from_dataAttributes
-
full(value, count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to the same value.Parameters
- value
The value each DOF should be set to.
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set tovalue.
-
ones(count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to one.This is a shorthand for
self.full(1., count, reserve).Parameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set to one.
-
random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]¶ Create a
VectorArrayof vectors with random entries.Supported random distributions:
'uniform': Uniform distribution in half-open interval [`low`, `high`). 'normal': Normal (Gaussian) distribution with mean `loc` and standard deviation `scale`.Note that not all random distributions are necessarily implemented by all
VectorSpaceimplementations.Parameters
- count
The number of vectors.
- distribution
Random distribution to use (
'uniform','normal').- low
Lower bound for
'uniform'distribution (defaults to0).- high
Upper bound for
'uniform'distribution (defaults to1).- loc
Mean for
'normal'distribution (defaults to0).- scale
Standard deviation for
'normal'distribution (defaults to1).- random_state
RandomStateto use for sampling. IfNone, a new random state is generated usingseedas random seed, or thedefaultrandom state is used.- seed
If not
None, a new random state with this seed is used.- reserve
Hint for the backend to which length the array will grow.
-
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectorsParameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.
-
-
class
pymor.vectorarrays.list.NumpyListVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.list.ListVectorSpaceMethods
full_vector,make_vector,ones_vector,space_from_dim,space_from_vector_obj,vector_from_numpy,zero_vectorfrom_numpy,full,make_array,ones,random,random_vector,zerosempty,from_dataAttributes
-
class
pymor.vectorarrays.list.NumpyVector(array)[source]¶ Bases:
pymor.vectorarrays.list.CopyOnWriteVectorVector stored in a NumPy 1D-array.
Methods
amax,conj,dofs,dot,from_instance,l1_norm,l2_norm,l2_norm2,to_numpyaxpy,copy,scalsup_normAttributes
dim,imag,real
-
class
pymor.vectorarrays.list.Vector[source]¶ Bases:
pymor.core.base.BasicObjectInterface for vectors used in conjunction with
ListVectorArray.This interface must be satisfied by the individual entries of the vector
listmanaged byListVectorArray. All interface methods have a direct counterpart in theVectorArrayinterface.Methods
amax,axpy,conj,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,scal,sup_normAttributes
imag,real
mpi module¶
Wrapper classes for building MPI distributed VectorArrays.
This module contains several wrapper classes which allow to
transform single rank VectorArrays into MPI distributed
VectorArrays which can be used on rank 0 like ordinary
VectorArrays.
The implementations are based on the event loop provided
by pymor.tools.mpi.
-
class
pymor.vectorarrays.mpi.MPIVectorArray(obj_id, space)[source]¶ Bases:
pymor.vectorarrays.interface.VectorArrayMPI distributed
VectorArray.Given a local
VectorArrayon each MPI rank, this wrapper class uses the event loop frompymor.tools.mpito build a global MPI distributed vector array from these local arrays.Instances of
MPIVectorArraycan be used on rank 0 like any other (non-distributed)VectorArray.Note, however, that the implementation of the local VectorArrays needs to be MPI aware. For instance,
cls.dotmust perform the needed MPI communication to sum up the local inner products and return the sums on rank 0.Default implementations for all communication requiring interface methods are provided by
MPIVectorArrayAutoComm(also seeMPIVectorArrayNoComm).Note that resource cleanup is handled by
object.__del__. Please be aware of the peculiarities of destructors in Python!The associated
VectorSpaceisMPIVectorSpace.Methods
amax,append,axpy,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scalcheck_ind,check_ind_unique,conj,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,sup_norm,to_numpy,zerosAttributes
-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
copy(deep=False)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
lincomb(coefficients)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
-
class
pymor.vectorarrays.mpi.MPIVectorArrayAutoComm(obj_id, space)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorArrayMPI distributed
VectorArray.This is a subclass of
MPIVectorArraywhich provides default implementations for all communication requiring interface methods for the case when the wrapped array is not MPI aware.Note, however, that depending on the model these default implementations might lead to wrong results (for instance in the presence of shared DOFs).
The associated
VectorSpaceisMPIVectorSpaceAutoComm.Methods
check_ind,check_ind_unique,conj,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,sup_norm,to_numpy,zerosAttributes
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
-
class
pymor.vectorarrays.mpi.MPIVectorArrayNoComm(obj_id, space)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorArrayMPI distributed
VectorArray.This is a subclass of
MPIVectorArraywhich overrides all communication requiring interface methods to raiseNotImplementedError.This is mainly useful as a security measure when wrapping arrays for which simply calling the respective method on the wrapped arrays would lead to wrong results and
MPIVectorArrayAutoCommcannot be used either (for instance in the presence of shared DOFs).The associated
VectorSpaceisMPIVectorSpaceNoComm.Methods
check_ind,check_ind_unique,conj,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,sup_norm,to_numpy,zerosAttributes
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
-
class
pymor.vectorarrays.mpi.MPIVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.interface.VectorSpaceVectorSpaceofMPIVectorArrays.Parameters
- local_spaces
tupleof the differentVectorSpacesof the localVectorArrayson the MPI ranks. Alternatively, the length oflocal_spacesmay be 1, in which case the sameVectorSpaceis assumed for all ranks.
Methods
empty,from_data,from_numpy,full,ones,randomAttributes
-
array_type¶ alias of
MPIVectorArray
-
make_array(obj_id)[source]¶ Create array from rank-local
VectorArrayinstances.Parameters
- obj_id
ObjectIdof the MPI distributed instances ofclswrapped by this array.
Returns
The newly created : class:
MPIVectorArray.
-
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectorsParameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.
-
class
pymor.vectorarrays.mpi.MPIVectorSpaceAutoComm(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorSpaceVectorSpaceforMPIVectorArrayAutoComm.Methods
empty,from_data,from_numpy,full,ones,randomAttributes
-
array_type¶ alias of
MPIVectorArrayAutoComm
-
-
class
pymor.vectorarrays.mpi.MPIVectorSpaceNoComm(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorSpaceVectorSpaceforMPIVectorArrayNoComm.Methods
empty,from_data,from_numpy,full,ones,randomAttributes
-
array_type¶ alias of
MPIVectorArrayNoComm
-
-
class
pymor.vectorarrays.mpi.RegisteredLocalSpace[source]¶ Bases:
intMethods
intbit_length,conjugate,from_bytes,to_bytes,__ceil__,__floor__,__new__,__round__,__sizeof__,__trunc__Attributes
intdenominator,imag,numerator,real
numpy module¶
-
class
pymor.vectorarrays.numpy.NumpyVectorArray(array, space)[source]¶ Bases:
pymor.vectorarrays.interface.VectorArrayVectorArrayimplementation viaNumPy arrays.This is the default
VectorArraytype used by allOperatorsin pyMOR’s discretization toolkit. Moreover, all reducedOperatorsare based onNumpyVectorArray.This class is just a thin wrapper around the underlying
NumPy array. Thus, while operations likeaxpyordotwill be quite efficient, removing or appending vectors will be costly.Warning
This class is not intended to be instantiated directly. Use the associated
VectorSpaceinstead.Methods
amax,append,axpy,conj,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scal,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
amax(*, _ind=None)[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x, *, _ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
copy(deep=False, *, _ind=None)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
dofs(dof_indices, *, _ind=None)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other, *, _ind=None)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
property
imag¶ Imaginary part.
-
l1_norm(*, _ind=None)[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm(*, _ind=None)[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2(*, _ind=None)[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
lincomb(coefficients, *, _ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
pairwise_dot(other, *, _ind=None)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
property
real¶ Real part.
-
scal(alpha, *, _ind=None)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
sup_norm(*, _ind=None)[source]¶ The l-infinity-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
to_numpy(ensure_copy=False)[source]¶ Return (len(self), self.dim) NumPy Array with the data stored in the array.
Parameters
- ensure_copy
If
False, modifying the returnedNumPy arraymight alter the originalVectorArray. IfTruealways a copy of the array data is made.
-
-
class
pymor.vectorarrays.numpy.NumpyVectorArrayView(array, ind)[source]¶ Bases:
pymor.vectorarrays.numpy.NumpyVectorArrayMethods
amax,append,axpy,copy,dofs,dot,l1_norm,l2_norm,l2_norm2,lincomb,pairwise_dot,scal,sup_norm,to_numpycheck_ind,check_ind_unique,empty,full,gramian,inner,len_ind,len_ind_unique,norm,norm2,normalize_ind,ones,pairwise_inner,random,sub_index,zerosAttributes
-
__getitem__(ind)[source]¶ Return a
VectorArrayview onto a subset of the vectors in the array.
-
amax()[source]¶ The maximum absolute value of the DOFs contained in the array.
Returns
- max_ind
NumPy arraycontaining for each vector a DOF index at which the maximum is attained.- max_val
NumPy arraycontaining for each vector the maximum absolute value of its DOFs.
-
append(other, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
- other
A
VectorArraycontaining the vectors to be appended.- remove_from_other
If
True, the appended vectors are removed fromother. For list-like implementations this can be used to prevent unnecessary copies of the involved vectors.
-
axpy(alpha, x)[source]¶ BLAS AXPY operation.
This method forms the sum
self = alpha*x + self
If the length of
xis 1, the samexvector is used for all vectors inself. Otherwise, the lengths ofselfandxhave to agree. Ifalphais a scalar, eachxvector is multiplied with the same factoralpha. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the coefficients for eachxvector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inxare multiplied.- x
A
VectorArraycontaining the x-summands.
-
copy(deep=False)[source]¶ Returns a copy of the array.
All
VectorArrayimplementations in pyMOR have copy-on-write semantics: if not specified otherwise by settingdeeptoTrue, the returned copy will hold a handle to the same array data as the original array, and a deep copy of the data will only be performed when one of the arrays is modified.Note that for
NumpyVectorArray, a deep copy is always performed when only some vectors in the array are copied.Parameters
- deep
Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray.
-
dofs(dof_indices)[source]¶ Extract DOFs of the vectors contained in the array.
Parameters
- dof_indices
List or 1D
NumPy arrayof indices of the DOFs that are to be returned.
Returns
A
NumPy arrayresultsuch thatresult[i, j]is thedof_indices[j]-th DOF of thei-th vector of the array.
-
dot(other)[source]¶ Returns the inner products between
VectorArrayelements.In the case of complex numbers, this is antilinear in the first argument, i.e. in ‘self’. Complex conjugation is done in the first argument because most numerical software in the community handles it this way: Numpy, DUNE, FEniCS, Eigen, Matlab and BLAS do complex conjugation in the first argument, only PetSc and deal.ii do complex conjugation in the second argument.
Parameters
- other
A
VectorArraycontaining the second factors.
-
l1_norm()[source]¶ The l1-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm()[source]¶ The l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
l2_norm2()[source]¶ The squared l2-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
lincomb(coefficients)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
- coefficients
A
NumPy arrayof dimension 1 or 2 containing the linear coefficients.coefficients.shape[-1]has to agree withlen(self).
Returns
A
VectorArrayresultsuch thatresult[i] = ∑ self[j] * coefficients[i,j]
in case
coefficientsis of dimension 2, otherwiselen(result) == 1andresult[0] = ∑ self[j] * coefficients[j].
-
pairwise_dot(other)[source]¶ Returns the pairwise inner products between
VectorArrayelements.Parameters
- other
A
VectorArraycontaining the second factors.
-
scal(alpha)[source]¶ BLAS SCAL operation (in-place scalar multiplication).
This method calculates
self = alpha*self
If
alphais a scalar, each vector is multiplied by this scalar. Otherwise,alphahas to be a one-dimensionalNumPy arrayof the same length asselfcontaining the factors for each vector.Parameters
- alpha
The scalar coefficient or one-dimensional
NumPy arrayof coefficients with which the vectors inselfare multiplied.
-
sup_norm()[source]¶ The l-infinity-norms of the vectors contained in the array.
Returns
A
NumPy arrayresultsuch thatresult[i]contains the norm ofself[i].
-
to_numpy(ensure_copy=False)[source]¶ Return (len(self), self.dim) NumPy Array with the data stored in the array.
Parameters
- ensure_copy
If
False, modifying the returnedNumPy arraymight alter the originalVectorArray. IfTruealways a copy of the array data is made.
-
-
class
pymor.vectorarrays.numpy.NumpyVectorSpace(*args, **kwargs)[source]¶ Bases:
pymor.vectorarrays.interface.VectorSpaceVectorSpaceofNumpyVectorArrays.Parameters
- dim
The dimension of the vectors contained in the space.
- id
See
id.
Methods
from_file,from_numpy,full,make_array,random,zerosAttributes
-
full(value, count=1, reserve=0)[source]¶ Create a
VectorArrayof vectors with all DOFs set to the same value.Parameters
- value
The value each DOF should be set to.
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each DOF set tovalue.
-
property
is_scalar¶ bool(x) -> bool
Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
-
random(count=1, distribution='uniform', random_state=None, seed=None, reserve=0, **kwargs)[source]¶ Create a
VectorArrayof vectors with random entries.Supported random distributions:
'uniform': Uniform distribution in half-open interval [`low`, `high`). 'normal': Normal (Gaussian) distribution with mean `loc` and standard deviation `scale`.Note that not all random distributions are necessarily implemented by all
VectorSpaceimplementations.Parameters
- count
The number of vectors.
- distribution
Random distribution to use (
'uniform','normal').- low
Lower bound for
'uniform'distribution (defaults to0).- high
Upper bound for
'uniform'distribution (defaults to1).- loc
Mean for
'normal'distribution (defaults to0).- scale
Standard deviation for
'normal'distribution (defaults to1).- random_state
RandomStateto use for sampling. IfNone, a new random state is generated usingseedas random seed, or thedefaultrandom state is used.- seed
If not
None, a new random state with this seed is used.- reserve
Hint for the backend to which length the array will grow.
-
zeros(count=1, reserve=0)[source]¶ Create a
VectorArrayof null vectorsParameters
- count
The number of vectors.
- reserve
Hint for the backend to which length the array will grow.
Returns
A
VectorArraycontainingcountvectors with each component zero.