pymor.vectorarrays package¶
Submodules¶
block module¶

class
pymor.vectorarrays.block.
BlockVectorArray
(blocks, copy=False)[source]¶ Bases:
pymor.vectorarrays.interfaces.VectorArrayInterface
VectorArray
where each vector is a direct sum of subvectors.Given a list of equal length
VectorArrays
blocks
, thisVectorArray
represents the direct sums of the vectors contained in the arrays.The
subtype
of the array will be the tuple(blocks[0].space, blocks[1].space, ..., blocks[1].space).
BlockVectorArray
can be used in conjunction withBlockOperator
.Parameters
 blocks
 The list of subarrays.
 copy
 If
True
, copy all arrays contained inblocks
.
Methods
Attributes
BlockVectorArray
data
,dim
,num_blocks
,subtype
VectorArrayInterface
space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

append
(other, o_ind=None, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
 other
 A
VectorArray
containing the vectors to be appended.  o_ind
 Indices of the vectors that are to be appended (see class documentation).
 remove_from_other
 If
True
, the appended vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy
(alpha, x, ind=None, x_ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self[ind] = alpha*x[x_ind] + self[ind]
If the length of
x
(x_ind
) is 1, the samex
vector is used for all vectors inself
. Otherwise, the lengths ofself
(ind
) andx
(x_ind
) have to agree. Ifalpha
is a scalar, eachx
vector is multiplied with the same factoralpha
. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the coefficients for eachx
vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inx
are multiplied.  x
 A
VectorArray
containing the xsummands.  ind
 Indices of the vectors of
self
that are to be added (see class documentation). Repeated indices are forbidden.  x_ind
 Indices of the vectors in
x
that are to be added (see class documentation). Repeated indices are allowed.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

copy
(ind=None, deep=False)[source]¶ Returns a copy of a subarray.
All
VectorArray
implementations in pyMOR have copyonwrite semantics: if not specified otherwise by settingdeep
toTrue
, 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 array are copied (i.e.ind
is specified).Parameters
 ind
 Indices of the vectors that are to be copied (see class documentation).
 deep
 Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray
.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

lincomb
(coefficients, ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
 coefficients
 A
NumPy array
of dimension 1 or 2 containing the linear coefficients.coefficients.shape[1]
has to agree withlen(self)
.  ind
 Indices of the vectors which are linear combined (see class documentation).
Returns
A
VectorArray
result
such thatresult[i] = ∑ self[j] * coefficients[i,j]in case
coefficients
is of dimension 2, otherwiselen(result) == 1
andresult[0] = ∑ self[j] * coefficients[j].

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

remove
(ind=None)[source]¶ Remove vectors from the array.
Parameters
 ind
 Indices of the vectors that are to be removed (see class documentation).

replace
(other, ind=None, o_ind=None, remove_from_other=False)[source]¶ Replace vectors of the array.
Parameters
 other
 A
VectorArray
containing the replacement vectors.  ind
 Indices of the vectors that are to be replaced (see class documentation). Repeated indices are forbidden.
 o_ind
 Indices of the replacement vectors (see class documentation).
len(ind)
has to agree withlen(o_ind)
. Repeated indices are allowed.  remove_from_other
 If
True
, the new vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

scal
(alpha, ind=None)[source]¶ BLAS SCAL operation (inplace scalar multiplication).
This method calculates
self[ind] = alpha*self[ind]
If
alpha
is a scalar, each vector is multiplied by this scalar. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the factors for each vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inself
are multiplied.  ind
 Indices of the vectors of
self
that are to be scaled (see class documentation). Repeated indices are forbidden.

sup_norm
(ind=None)[source]¶ The linfinity–norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.
constructions module¶

pymor.vectorarrays.constructions.
cat_arrays
(vector_arrays)[source]¶ Return a new
VectorArray
which a concatenation of the arrays invector_arrays
.
fenics module¶
interfaces module¶

class
pymor.vectorarrays.interfaces.
VectorArrayInterface
[source]¶ Bases:
pymor.core.interfaces.BasicInterface
Interface for vector arrays.
A vector array should be thought of as a list of (possibly highdimensional) 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 the interface.
It is moreover 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_norm
orgramian
will always returnNumPy arrays
.An implementation of the interface via
NumPy arrays
is 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,VectorArray
constructors should provide areserve
keyword argument which allows to specify to what size the array is assumed to grow.Most methods provide
ind
and/oro_ind
arguments which are used to specify on which vectors the method is supposed to operate. Ifind
(o_ind
) isNone
the whole array is selected. Otherwise,ind
can be a single index inrange(len(self))
, alist
of indices or a onedimensionalNumPy array
of indices. An index can be repeated in which case the corresponding vector is selected several times.Methods
Attributes
VectorArrayInterface
data
,dim
,space
,subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

data
¶ Implementors can provide a
data
property which returns aNumPy array
of shape(len(v), v.dim)
containing the data stored in the array. Access should be assumed to be slow and is mainly intended for debugging / visualization purposes or to once transfer data to pyMOR and further process it using NumPy. In the case ofNumpyVectorArray
, an actual view of the internally usedNumPy array
is returned, so changing it, will alter theVectorArray
. Thus, you cannot assume to own the data returned to you, in general.

dim
¶ The dimension of the vectors in the array.

space
¶ VectorSpace
array the array belongs to.

subtype
¶ Can be any Python object. Two arrays are compatible (e.g. can be added) if they are instances of the same class and have equal subtypes. A valid subtype has to be provided to
make_array
and the resulting array will be of that subtype. By default, the subtype of an array is simplyNone
. ForNumpyVectorArray
, the subtype is a single integer denoting the dimension of the array. Subtypes for other array classes could, e.g., include a socket for communication with a specific PDE solver instance.

__add__
(other)[source]¶ The pairwise sum of two
VectorArrays
.

__iadd__
(other)[source]¶ Inplace pairwise addition of
VectorArrays
.

__isub__
(other)[source]¶ Inplace pairwise difference of
VectorArrays
.

__radd__
(other)¶ The pairwise sum of two
VectorArrays
.

__sub__
(other)[source]¶ The pairwise difference of two
VectorArrays
.

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

append
(other, o_ind=None, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
 other
 A
VectorArray
containing the vectors to be appended.  o_ind
 Indices of the vectors that are to be appended (see class documentation).
 remove_from_other
 If
True
, the appended vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy
(alpha, x, ind=None, x_ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self[ind] = alpha*x[x_ind] + self[ind]
If the length of
x
(x_ind
) is 1, the samex
vector is used for all vectors inself
. Otherwise, the lengths ofself
(ind
) andx
(x_ind
) have to agree. Ifalpha
is a scalar, eachx
vector is multiplied with the same factoralpha
. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the coefficients for eachx
vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inx
are multiplied.  x
 A
VectorArray
containing the xsummands.  ind
 Indices of the vectors of
self
that are to be added (see class documentation). Repeated indices are forbidden.  x_ind
 Indices of the vectors in
x
that are to be added (see class documentation). Repeated indices are allowed.

check_ind
(ind)[source]¶ Check if
ind
is an admissable list of indices in the sense of the class documentation.

check_ind_unique
(ind)[source]¶ Check if
ind
is an admissable list of nonrepeated indices in the sense of the class documentation.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

copy
(ind=None, deep=False)[source]¶ Returns a copy of a subarray.
All
VectorArray
implementations in pyMOR have copyonwrite semantics: if not specified otherwise by settingdeep
toTrue
, 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 array are copied (i.e.ind
is specified).Parameters
 ind
 Indices of the vectors that are to be copied (see class documentation).
 deep
 Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray
.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

empty
(reserve=0)[source]¶ Create an empty
VectorArray
of the samesubtype
.Parameters
 reserve
 Hint for the backend to which length the array will grow.
Returns
An empty
VectorArray
.

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

lincomb
(coefficients, ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
 coefficients
 A
NumPy array
of dimension 1 or 2 containing the linear coefficients.coefficients.shape[1]
has to agree withlen(self)
.  ind
 Indices of the vectors which are linear combined (see class documentation).
Returns
A
VectorArray
result
such thatresult[i] = ∑ self[j] * coefficients[i,j]in case
coefficients
is of dimension 2, otherwiselen(result) == 1
andresult[0] = ∑ self[j] * coefficients[j].

classmethod
make_array
(subtype=None, count=0, reserve=0)[source]¶ Create a
VectorArray
of null vectors.Parameters
 subtype
 The
subtype
, the created array should have. What a valid subtype is, is determined by the respective array implementation.  count
 The number of null vectors to create. For
count == 0
, an empty array is returned.  reserve
 A hint for the backend to which length the array will grow.

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

remove
(ind=None)[source]¶ Remove vectors from the array.
Parameters
 ind
 Indices of the vectors that are to be removed (see class documentation).

replace
(other, ind=None, o_ind=None, remove_from_other=False)[source]¶ Replace vectors of the array.
Parameters
 other
 A
VectorArray
containing the replacement vectors.  ind
 Indices of the vectors that are to be replaced (see class documentation). Repeated indices are forbidden.
 o_ind
 Indices of the replacement vectors (see class documentation).
len(ind)
has to agree withlen(o_ind)
. Repeated indices are allowed.  remove_from_other
 If
True
, the new vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

scal
(alpha, ind=None)[source]¶ BLAS SCAL operation (inplace scalar multiplication).
This method calculates
self[ind] = alpha*self[ind]
If
alpha
is a scalar, each vector is multiplied by this scalar. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the factors for each vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inself
are multiplied.  ind
 Indices of the vectors of
self
that are to be scaled (see class documentation). Repeated indices are forbidden.

sup_norm
(ind=None)[source]¶ The linfinity–norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

zeros
(count=1)[source]¶ Create a
VectorArray
of null vectors of the samesubtype
.Parameters
 count
 The number of vectors.
Returns
A
VectorArray
containingcount
vectors whith each component zero.


class
pymor.vectorarrays.interfaces.
VectorSpace
(space_type, subtype=None)[source]¶ Bases:
pymor.core.interfaces.BasicInterface
Class describing a vector space.
A vector space is simply the combination of a
VectorArray
type and asubtype
. This data is exactly sufficient to construct new arrays using themake_array
method (see the implementation ofzeros
).A
VectorArray
U
is contained in a vector spacespace
, iftype(U) == space.type and U.subtype == space.subtype
Methods
Attributes
VectorSpace
dim
,subtype
,type
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

type
¶ The type of
VectorArrays
in the space.

subtype
¶ The subtype used to construct arrays of the given space.

__contains__
(other)[source]¶ A
VectorArray
is contained in the space, iff it is an instance of its type and has the same subtype.

__str__
()¶ x.__repr__() <==> repr(x)

empty
(reserve=0)[source]¶ Create an empty
VectorArray
Parameters
 reserve
 Hint for the backend to which length the array will grow.
Returns
An empty
VectorArray
.

zeros
(count=1)[source]¶ Create a
VectorArray
of null vectorsParameters
 count
 The number of vectors.
Returns
A
VectorArray
containingcount
vectors with each component zero.

list module¶

class
pymor.vectorarrays.list.
CopyOnWriteVector
[source]¶ Bases:
pymor.vectorarrays.list.VectorInterface
Methods
CopyOnWriteVector
axpy
,copy
,from_instance
,scal
VectorInterface
amax
,components
,dot
,l1_norm
,l2_norm
,make_zeros
,sup_norm
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,unlock
,__setattr__
Attributes
VectorInterface
dim
,subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

class
pymor.vectorarrays.list.
ListVectorArray
(vectors, subtype=(), copy=True)[source]¶ Bases:
pymor.vectorarrays.interfaces.VectorArrayInterface
VectorArray
implementation via a Python list of vectors.The
subtypes
aListVectorArray
can have are tuples(vector_type, vector_subtype)
wherevector_type
is a subclass ofVectorInterface
andvector_subtype
is a valid subtype forvector_type
.Parameters
Methods
Attributes
ListVectorArray
data
,dim
,subtype
VectorArrayInterface
space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

append
(other, o_ind=None, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
 other
 A
VectorArray
containing the vectors to be appended.  o_ind
 Indices of the vectors that are to be appended (see class documentation).
 remove_from_other
 If
True
, the appended vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy
(alpha, x, ind=None, x_ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self[ind] = alpha*x[x_ind] + self[ind]
If the length of
x
(x_ind
) is 1, the samex
vector is used for all vectors inself
. Otherwise, the lengths ofself
(ind
) andx
(x_ind
) have to agree. Ifalpha
is a scalar, eachx
vector is multiplied with the same factoralpha
. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the coefficients for eachx
vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inx
are multiplied.  x
 A
VectorArray
containing the xsummands.  ind
 Indices of the vectors of
self
that are to be added (see class documentation). Repeated indices are forbidden.  x_ind
 Indices of the vectors in
x
that are to be added (see class documentation). Repeated indices are allowed.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

copy
(ind=None, deep=False)[source]¶ Returns a copy of a subarray.
All
VectorArray
implementations in pyMOR have copyonwrite semantics: if not specified otherwise by settingdeep
toTrue
, 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 array are copied (i.e.ind
is specified).Parameters
 ind
 Indices of the vectors that are to be copied (see class documentation).
 deep
 Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray
.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

lincomb
(coefficients, ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
 coefficients
 A
NumPy array
of dimension 1 or 2 containing the linear coefficients.coefficients.shape[1]
has to agree withlen(self)
.  ind
 Indices of the vectors which are linear combined (see class documentation).
Returns
A
VectorArray
result
such thatresult[i] = ∑ self[j] * coefficients[i,j]in case
coefficients
is of dimension 2, otherwiselen(result) == 1
andresult[0] = ∑ self[j] * coefficients[j].

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

remove
(ind=None)[source]¶ Remove vectors from the array.
Parameters
 ind
 Indices of the vectors that are to be removed (see class documentation).

replace
(other, ind=None, o_ind=None, remove_from_other=False)[source]¶ Replace vectors of the array.
Parameters
 other
 A
VectorArray
containing the replacement vectors.  ind
 Indices of the vectors that are to be replaced (see class documentation). Repeated indices are forbidden.
 o_ind
 Indices of the replacement vectors (see class documentation).
len(ind)
has to agree withlen(o_ind)
. Repeated indices are allowed.  remove_from_other
 If
True
, the new vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

scal
(alpha, ind=None)[source]¶ BLAS SCAL operation (inplace scalar multiplication).
This method calculates
self[ind] = alpha*self[ind]
If
alpha
is a scalar, each vector is multiplied by this scalar. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the factors for each vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inself
are multiplied.  ind
 Indices of the vectors of
self
that are to be scaled (see class documentation). Repeated indices are forbidden.

sup_norm
(ind=None)[source]¶ The linfinity–norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.


class
pymor.vectorarrays.list.
NumpyVector
(instance, dtype=None, copy=False, order=None, subok=False)[source]¶ Bases:
pymor.vectorarrays.list.CopyOnWriteVector
Vector stored in a NumPy 1Darray.
Methods
NumpyVector
amax
,components
,dot
,from_instance
,l1_norm
,l2_norm
,make_zeros
CopyOnWriteVector
axpy
,copy
,scal
VectorInterface
sup_norm
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,unlock
,__setattr__
Attributes
NumpyVector
data
,dim
,subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

class
pymor.vectorarrays.list.
VectorInterface
[source]¶ Bases:
pymor.core.interfaces.BasicInterface
Interface for vectors.
This Interface is intended to be used in conjunction with
ListVectorArray
. All pyMOR algorithms operate onVectorArrays
instead of single vectors! All methods of the interface have a direct counterpart in theVectorArray
interface.Methods
VectorInterface
amax
,axpy
,components
,copy
,dot
,l1_norm
,l2_norm
,make_zeros
,scal
,sup_norm
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,unlock
,__setattr__
Attributes
VectorInterface
dim
,subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid
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
. Similar classes are provided for handling
Vectors
.
The implementations are based on the event loop provided
by pymor.tools.mpi
.

class
pymor.vectorarrays.mpi.
MPIVector
(cls, subtype, obj_id)[source]¶ Bases:
pymor.vectorarrays.list.VectorInterface
MPI distributed Vector.
Given a singlerank implementation of
VectorInterface
cls
, this wrapper class uses the event loop frompymor.tools.mpi
to build MPI distributed vector where on each MPI rank an instance ofcls
is used to manage the local data.Instances of
MPIVector
can be used on rank 0 in conjunction withListVectorArray
like any other (nondistributed) Vector class.Note, however, that the implementation of
cls
needs to be MPI aware. For instance,cls.dot
must perform the needed MPI communication to sum up the local inner products and return the sum on rank 0.Default implementations for all communication requiring interface methods are provided by
MPIVectorAutoComm
(also seeMPIVectorNoComm
).Note that resource cleanup is handled by
object.__del__
. Please be aware of the peculiarities of destructors in Python!Parameters
 cls
 The class of the
VectorInterface
implementation used on every MPI rank.  subtype
tuple
of the different subtypes ofcls
on the MPI ranks. Alternatively, the length of subtype may be 1, in which case the same subtype is assumed for all ranks. obj_id
ObjectId
of the MPI distributed instances ofcls
wrapped by this object.
Methods
MPIVector
amax
,axpy
,components
,copy
,dot
,l1_norm
,l2_norm
,make_zeros
,scal
VectorInterface
sup_norm
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,unlock
,__setattr__
Attributes
MPIVector
dim
,subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

class
pymor.vectorarrays.mpi.
MPIVectorArray
(cls, subtype, obj_id)[source]¶ Bases:
pymor.vectorarrays.interfaces.VectorArrayInterface
MPI distributed
VectorArray
.Given a singlerank
VectorArray
implementationcls
, this wrapper class uses the event loop frompymor.tools.mpi
to build MPI distributed vector arrays where on each MPI rank an instance ofcls
is used to manage the local data.Instances of
MPIVectorArray
can be used on rank 0 like any other (nondistributed)VectorArray
.Note, however, that the implementation of
cls
needs to be MPI aware. For instance,cls.dot
must 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!Parameters
 cls
 The class of the
VectorArray
implementation used on every MPI rank.  subtype
tuple
of the different subtypes ofcls
on the MPI ranks. Alternatively, the length of subtype may be 1, in which case the same subtype is assumed for all ranks. obj_id
ObjectId
of the MPI distributed instances ofcls
wrapped by this array.
Methods
Attributes
MPIVectorArray
dim
,subtype
VectorArrayInterface
data
,space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

append
(other, o_ind=None, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
 other
 A
VectorArray
containing the vectors to be appended.  o_ind
 Indices of the vectors that are to be appended (see class documentation).
 remove_from_other
 If
True
, the appended vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy
(alpha, x, ind=None, x_ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self[ind] = alpha*x[x_ind] + self[ind]
If the length of
x
(x_ind
) is 1, the samex
vector is used for all vectors inself
. Otherwise, the lengths ofself
(ind
) andx
(x_ind
) have to agree. Ifalpha
is a scalar, eachx
vector is multiplied with the same factoralpha
. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the coefficients for eachx
vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inx
are multiplied.  x
 A
VectorArray
containing the xsummands.  ind
 Indices of the vectors of
self
that are to be added (see class documentation). Repeated indices are forbidden.  x_ind
 Indices of the vectors in
x
that are to be added (see class documentation). Repeated indices are allowed.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

copy
(ind=None, deep=False)[source]¶ Returns a copy of a subarray.
All
VectorArray
implementations in pyMOR have copyonwrite semantics: if not specified otherwise by settingdeep
toTrue
, 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 array are copied (i.e.ind
is specified).Parameters
 ind
 Indices of the vectors that are to be copied (see class documentation).
 deep
 Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray
.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

lincomb
(coefficients, ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
 coefficients
 A
NumPy array
of dimension 1 or 2 containing the linear coefficients.coefficients.shape[1]
has to agree withlen(self)
.  ind
 Indices of the vectors which are linear combined (see class documentation).
Returns
A
VectorArray
result
such thatresult[i] = ∑ self[j] * coefficients[i,j]in case
coefficients
is of dimension 2, otherwiselen(result) == 1
andresult[0] = ∑ self[j] * coefficients[j].

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

remove
(ind=None)[source]¶ Remove vectors from the array.
Parameters
 ind
 Indices of the vectors that are to be removed (see class documentation).

replace
(other, ind=None, o_ind=None, remove_from_other=False)[source]¶ Replace vectors of the array.
Parameters
 other
 A
VectorArray
containing the replacement vectors.  ind
 Indices of the vectors that are to be replaced (see class documentation). Repeated indices are forbidden.
 o_ind
 Indices of the replacement vectors (see class documentation).
len(ind)
has to agree withlen(o_ind)
. Repeated indices are allowed.  remove_from_other
 If
True
, the new vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

scal
(alpha, ind=None)[source]¶ BLAS SCAL operation (inplace scalar multiplication).
This method calculates
self[ind] = alpha*self[ind]
If
alpha
is a scalar, each vector is multiplied by this scalar. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the factors for each vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inself
are multiplied.  ind
 Indices of the vectors of
self
that are to be scaled (see class documentation). Repeated indices are forbidden.

class
pymor.vectorarrays.mpi.
MPIVectorArrayAutoComm
(cls, subtype, obj_id)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorArray
MPI distributed
VectorArray
.This is a subclass of
MPIVectorArray
which 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 discretization these default implementations might lead to wrong results (for instance in the presence of shared DOFs).
Methods
Attributes
MPIVectorArrayAutoComm
dim
MPIVectorArray
subtype
VectorArrayInterface
data
,space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).


class
pymor.vectorarrays.mpi.
MPIVectorArrayNoComm
(cls, subtype, obj_id)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVectorArray
MPI distributed
VectorArray
.This is a subclass of
MPIVectorArray
which 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
MPIVectorArrayAutoComm
cannot be used either (for instance in the presence of shared DOFs).Methods
Attributes
MPIVectorArrayNoComm
dim
MPIVectorArray
subtype
VectorArrayInterface
data
,space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).


class
pymor.vectorarrays.mpi.
MPIVectorAutoComm
(cls, subtype, obj_id)[source]¶ Bases:
pymor.vectorarrays.mpi.MPIVector
MPI distributed Vector.
This is a subclass of
MPIVector
which provides default implementations for all communication requiring interface methods for the case when the wrapped vector is not MPI aware.Note, however, that depending on the discretization these default implementations might lead to wrong results (for instance in the presence of shared DOFs).
Methods
MPIVectorAutoComm
amax
,components
,dot
,l1_norm
,l2_norm
MPIVector
axpy
,copy
,make_zeros
,scal
VectorInterface
sup_norm
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,unlock
,__setattr__
Attributes
MPIVectorAutoComm
dim
MPIVector
subtype
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

class
pymor.vectorarrays.mpi.
MPIVectorNoComm
[source]¶ Bases:
object
MPI distributed Vector.
This is a subclass of
MPIVector
which overrides all communication requiring interface methods to raiseNotImplementedError
.This is mainly useful as a security measure when wrapping vectors for which simply calling the respective method on the wrapped vectors would lead to wrong results and
MPIVectorAutoComm
cannot be used either (for instance in the presence of shared DOFs).Methods
MPIVectorNoComm
amax
,components
,dot
,l1_norm
,l2_norm
,pairwise_dot
Attributes
MPIVectorNoComm
dim
numpy module¶

class
pymor.vectorarrays.numpy.
NumpyVectorArray
(instance, dtype=None, copy=False, order=None, subok=False)[source]¶ Bases:
pymor.vectorarrays.interfaces.VectorArrayInterface
VectorArray
implementation viaNumPy arrays
.This is the default
VectorArray
type used by allOperators
in pyMOR’s discretization toolkit. Moreover, all reducedOperators
are based onNumpyVectorArray
.Note that this class is just a thin wrapper around the underlying
NumPy array
. Thus, while operations likeaxpy
ordot
will be quite efficient, removing or appending vectors will be costly.Methods
Attributes
NumpyVectorArray
data
,dim
,imag
,real
,subtype
VectorArrayInterface
space
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

amax
(ind=None)[source]¶ The maximum absolute value of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose maximum absolute value is to be calculated (see class documentation).
Returns
 max_ind
NumPy array
containing for each vector an index at which the maximum is attained. max_val
NumPy array
containing for each vector the maximum absolute value of its components.

append
(other, o_ind=None, remove_from_other=False)[source]¶ Append vectors to the array.
Parameters
 other
 A
VectorArray
containing the vectors to be appended.  o_ind
 Indices of the vectors that are to be appended (see class documentation).
 remove_from_other
 If
True
, the appended vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

axpy
(alpha, x, ind=None, x_ind=None)[source]¶ BLAS AXPY operation.
This method forms the sum
self[ind] = alpha*x[x_ind] + self[ind]
If the length of
x
(x_ind
) is 1, the samex
vector is used for all vectors inself
. Otherwise, the lengths ofself
(ind
) andx
(x_ind
) have to agree. Ifalpha
is a scalar, eachx
vector is multiplied with the same factoralpha
. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the coefficients for eachx
vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inx
are multiplied.  x
 A
VectorArray
containing the xsummands.  ind
 Indices of the vectors of
self
that are to be added (see class documentation). Repeated indices are forbidden.  x_ind
 Indices of the vectors in
x
that are to be added (see class documentation). Repeated indices are allowed.

components
(component_indices, ind=None)[source]¶ Extract components of the vectors contained in the array.
Parameters
 component_indices
 List or 1D
NumPy array
of indices of the vector components that are to be returned.  ind
 Indices of the vectors whose components are to be retrieved (see class documentation).
Returns
A
NumPy array
result
such thatresult[i, j]
is thecomponent_indices[j]
th component of theind[i]
th vector of the array.

copy
(ind=None, deep=False)[source]¶ Returns a copy of a subarray.
All
VectorArray
implementations in pyMOR have copyonwrite semantics: if not specified otherwise by settingdeep
toTrue
, 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 array are copied (i.e.ind
is specified).Parameters
 ind
 Indices of the vectors that are to be copied (see class documentation).
 deep
 Ensure that an actual copy of the array data is made (see above).
Returns
A copy of the
VectorArray
.

dot
(other, ind=None, o_ind=None)[source]¶ Returns the inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

l1_norm
(ind=None)[source]¶ The l1norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

l2_norm
(ind=None)[source]¶ The l2norms of the vectors contained in the array.
Parameters
 ind
 Indices of the vectors whose norms are to be calculated (see class documentation).
Returns
A
NumPy array
result
such thatresult[i]
contains the norm ofself[ind[i]]
.

lincomb
(coefficients, ind=None)[source]¶ Returns linear combinations of the vectors contained in the array.
Parameters
 coefficients
 A
NumPy array
of dimension 1 or 2 containing the linear coefficients.coefficients.shape[1]
has to agree withlen(self)
.  ind
 Indices of the vectors which are linear combined (see class documentation).
Returns
A
VectorArray
result
such thatresult[i] = ∑ self[j] * coefficients[i,j]in case
coefficients
is of dimension 2, otherwiselen(result) == 1
andresult[0] = ∑ self[j] * coefficients[j].

pairwise_dot
(other, ind=None, o_ind=None)[source]¶ Returns the pairwise inner products between
VectorArray
elements.Parameters
 other
 A
VectorArray
containing the second factors.  ind
 Indices of the vectors whose inner products are to be taken (see class documentation).
 o_ind
 Indices of the vectors in
other
whose inner products are to be taken (see class documentation).

remove
(ind=None)[source]¶ Remove vectors from the array.
Parameters
 ind
 Indices of the vectors that are to be removed (see class documentation).

replace
(other, ind=None, o_ind=None, remove_from_other=False)[source]¶ Replace vectors of the array.
Parameters
 other
 A
VectorArray
containing the replacement vectors.  ind
 Indices of the vectors that are to be replaced (see class documentation). Repeated indices are forbidden.
 o_ind
 Indices of the replacement vectors (see class documentation).
len(ind)
has to agree withlen(o_ind)
. Repeated indices are allowed.  remove_from_other
 If
True
, the new vectors are removed fromother
. For listlike implementations this can be used to prevent unnecessary copies of the involved vectors.

scal
(alpha, ind=None)[source]¶ BLAS SCAL operation (inplace scalar multiplication).
This method calculates
self[ind] = alpha*self[ind]
If
alpha
is a scalar, each vector is multiplied by this scalar. Otherwise,alpha
has to be a onedimensionalNumPy array
of the same length asself
(ind
) containing the factors for each vector.Parameters
 alpha
 The scalar coefficient or onedimensional
NumPy array
of coefficients with which the vectors inself
are multiplied.  ind
 Indices of the vectors of
self
that are to be scaled (see class documentation). Repeated indices are forbidden.


pymor.vectorarrays.numpy.
NumpyVectorSpace
(dim)[source]¶ Shorthand for
VectorSpace
(NumpyVectorArray, dim)
.