BlockVector
Methods specific to pyomo.contrib.pynumero.sparse.block_vector.BlockVector
:
Attributes specific to pyomo.contrib.pynumero.sparse.block_vector.BlockVector
:
NumPy compatible methods:
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:
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:
- _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:
- 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.