block_vector

Implementation of a general “block vector”

The pyomo.contrib.pynumero.sparse.block_vector module includes methods that extend linear algebra operations in numpy for case of structured problems where linear algebra operations present an inherent block structure. This interface consider vectors of the form:

\[v = [v_1, v_2, v_3, ... , v_n]\]

where v_i are numpy arrays of dimension 1

Contents

Methods specific to BlockVector:

Attributes specific to 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:

  • log10()

  • sin()

  • cos()

  • exp()

  • ceil()

  • floor()

  • tan()

  • arctan()

  • arcsin()

  • arccos()

  • sinh()

  • cosh()

  • abs()

  • tanh()

  • arccosh()

  • arcsinh()

  • arctanh()

  • fabs()

  • sqrt()

  • log()

  • log2()

  • absolute()

  • isfinite()

  • isinf()

  • isnan()

  • log1p()

  • logical_not()

  • expm1()

  • exp2()

  • sign()

  • rint()

  • square()

  • positive()

  • negative()

  • rad2deg()

  • deg2rad()

  • conjugate()

  • reciprocal()

  • signbit()

  • add()

  • multiply()

  • divide()

  • subtract()

  • greater()

  • greater_equal()

  • less()

  • less_equal()

  • not_equal()

  • maximum()

  • minimum()

  • fmax()

  • fmin()

  • equal()

  • logical_and()

  • logical_or()

  • logical_xor()

  • logaddexp()

  • logaddexp2()

  • remainder()

  • heaviside()

  • 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))

BlockVector(nblocks)

Structured vector interface.

BlockVector.set_block(key, value)

Set a block.

BlockVector.get_block(key)

Access a block.

BlockVector.block_sizes([copy])

Returns 1D-Array with sizes of individual blocks in this BlockVector

BlockVector.get_block_size(ndx)

BlockVector.is_block_defined(ndx)

BlockVector.copyfrom(other)

Copy entries of other vector into this vector

BlockVector.copyto(other)

Copy entries of this BlockVector into other

BlockVector.copy_structure()

Returns a copy of the BlockVector structure filled with zeros

BlockVector.set_blocks(blocks)

Assigns vectors in blocks

BlockVector.pprint()

Prints BlockVector in pretty format

BlockVector.nblocks

Returns the number of blocks.

BlockVector.bshape

Returns the number of blocks in this BlockVector in a tuple.

BlockVector.has_none

Indicate if this BlockVector has any none entries.

Classes

BlockVector(nblocks)

Structured vector interface.

Exceptions

NotFullyDefinedBlockVectorError

Functions

assert_block_structure(vec)