BlockVector
Methods specific to pyomo.contrib.pynumero.sparse.block_vector.BlockVector
:
Attributes specific to pyomo.contrib.pynumero.sparse.block_vector.BlockVector
:
NumPy compatible methods:
- numpy.ndarray.dot()
- numpy.ndarray.sum()
- numpy.ndarray.all()
- numpy.ndarray.any()
- numpy.ndarray.max()
- numpy.ndarray.astype()
- numpy.ndarray.clip()
- numpy.ndarray.compress()
- numpy.ndarray.conj()
- numpy.ndarray.conjugate()
- numpy.ndarray.nonzero()
- numpy.ndarray.ptp()
- numpy.ndarray.round()
- numpy.ndarray.std()
- numpy.ndarray.var()
- numpy.ndarray.tofile()
- numpy.ndarray.min()
- numpy.ndarray.mean()
- numpy.ndarray.prod()
- numpy.ndarray.fill()
- numpy.ndarray.tolist()
- numpy.ndarray.flatten()
- numpy.ndarray.ravel()
- numpy.ndarray.argmax()
- numpy.ndarray.argmin()
- numpy.ndarray.cumprod()
- numpy.ndarray.cumsum()
- numpy.ndarray.copy()
For example,
>>> import numpy as np
>>> from pyomo.contrib.pynumero.sparse import BlockVector
>>> v = BlockVector(2)
>>> v.set_block(0, np.random.normal(size=100))
>>> v.set_block(1, np.random.normal(size=30))
>>> avg = v.mean()
NumPy compatible functions:
- numpy.log10()
- numpy.sin()
- numpy.cos()
- numpy.exp()
- numpy.ceil()
- numpy.floor()
- numpy.tan()
- numpy.arctan()
- numpy.arcsin()
- numpy.arccos()
- numpy.sinh()
- numpy.cosh()
- numpy.abs()
- numpy.tanh()
- numpy.arccosh()
- numpy.arcsinh()
- numpy.arctanh()
- numpy.fabs()
- numpy.sqrt()
- numpy.log()
- numpy.log2()
- numpy.absolute()
- numpy.isfinite()
- numpy.isinf()
- numpy.isnan()
- numpy.log1p()
- numpy.logical_not()
- numpy.expm1()
- numpy.exp2()
- numpy.sign()
- numpy.rint()
- numpy.square()
- numpy.positive()
- numpy.negative()
- numpy.rad2deg()
- numpy.deg2rad()
- numpy.conjugate()
- numpy.reciprocal()
- numpy.signbit()
- numpy.add()
- numpy.multiply()
- numpy.divide()
- numpy.subtract()
- numpy.greater()
- numpy.greater_equal()
- numpy.less()
- numpy.less_equal()
- numpy.not_equal()
- numpy.maximum()
- numpy.minimum()
- numpy.fmax()
- numpy.fmin()
- numpy.equal()
- numpy.logical_and()
- numpy.logical_or()
- numpy.logical_xor()
- numpy.logaddexp()
- numpy.logaddexp2()
- numpy.remainder()
- numpy.heaviside()
- numpy.hypot()
For example,
>>> import numpy as np
>>> from pyomo.contrib.pynumero.sparse import BlockVector
>>> v = BlockVector(2)
>>> v.set_block(0, np.random.normal(size=100))
>>> v.set_block(1, np.random.normal(size=30))
>>> inf_norm = np.max(np.abs(v))
-
class
pyomo.contrib.pynumero.sparse.block_vector.
BlockVector
(nblocks)[source] Structured vector interface. This interface can be used to perform operations on vectors composed by vectors. For example,
>>> import numpy as np >>> from pyomo.contrib.pynumero.sparse import BlockVector >>> bv = BlockVector(3) >>> v0 = np.ones(3) >>> v1 = v0*2 >>> v2 = np.random.normal(size=4) >>> bv.set_block(0, v0) >>> bv.set_block(1, v1) >>> bv.set_block(2, v2) >>> bv2 = BlockVector(2) >>> bv2.set_block(0, v0) >>> bv2.set_block(1, bv)
-
_brow_lengths
1D-Array of size nblocks that specifies the length of each entry in the block vector
Type: numpy.ndarray
-
_undefined_brows
A set of block indices for which the blocks are still None (i.e., the dimensions have not yet ben set). Operations with BlockVectors require all entries to be different than None.
Type: set
Parameters: nblocks (int) – The number of blocks in the BlockVector -
-
BlockVector.
set_block
(key, value)[source] Set a block. The value can be a NumPy array or another BlockVector.
Parameters: - key (int) – This is the block index
- value – This is the block. It can be a NumPy array or another BlockVector.
-
BlockVector.
get_block
(key)[source] Access a block.
Parameters: key (int) – This is the block index Returns: block – The block corresponding to the index key. Return type: np.ndarray or BlockVector
-
BlockVector.
block_sizes
(copy=True)[source] Returns 1D-Array with sizes of individual blocks in this BlockVector
-
BlockVector.
copyfrom
(other)[source] Copy entries of other vector into this vector
Parameters: other (BlockVector or numpy.ndarray) – vector to be copied to this BlockVector Return type: None
-
BlockVector.
copyto
(other)[source] Copy entries of this BlockVector into other
Parameters: other (BlockVector or numpy.ndarray) – Return type: None
-
BlockVector.
set_blocks
(blocks)[source] Assigns vectors in blocks
Parameters: blocks (list) – list of numpy.ndarrays and/or BlockVectors Return type: None
-
property
BlockVector.
nblocks
Returns the number of blocks.
-
property
BlockVector.
bshape
Returns the number of blocks in this BlockVector in a tuple.
-
property
BlockVector.
has_none
Indicate if this BlockVector has any none entries.