decogo.util.block_vector¶
Implements sparse and dense block vector data structures
Functions
Computes infinity norm, i.e. \(||x||_\infty = \max\limits_{k \in K, i \in n_k}|x_{ki}|\). |
Classes
|
This class stores dense vector with the respect to blocks |
|
Class for storing the values in sparse format blockwise. |
- class decogo.util.block_vector.SparseBlockVector(values, blocks_size)[source]¶
Class for storing the values in sparse format blockwise. It consists of k blocks. Each block uses the standard Python sparse matrix with dimension \(1 \times n_k\), where \(n_k\) is the block size
- Parameters:
vectors (dict) – Sparse matrices stored blockwise
blocks_size (list) – Size of the blocks
blocks (list) – Block ids which contain nonzero values
- __init__(values, blocks_size)[source]¶
Constructor method
- Parameters:
values (list) – List of tuples (block_id, index, value)
blocks_size (list) – Number of variables per block
- __getitem__(item)[source]¶
Index operator
- Parameters:
item (tuple) – Input index as tuple: (block_id, index)
- Returns:
Value associated with the given index
- Return type:
float
- scalar_prod(x)[source]¶
Scalar product computation (or dot product) computed blockwise, \(v=\sum_{k \in K}a_k^Tx_k\)
- Parameters:
x (SparseBlockVector or BlockVector) – Input vector
- Returns:
Value for scalar product \(v\)
- Return type:
float
- maxabs(block_id=None)[source]¶
Finds maximum element by absolute value
- Parameters:
block_id (int, optional) – Block id where to look for the maximum value
- Returns:
Max element by absolute value
- Return type:
float or None
- property num_blocks¶
Return number of blocks
- Returns:
Return number of blocks
- Return type:
int
- get_block(block_id)[source]¶
Gets vector associated with the given block id
- Parameters:
block_id (int) – Given block identifier
- Returns:
Sparse vector (matrix)
- Return type:
coo_matrix or None
- class decogo.util.block_vector.BlockVector(blocks_size=None)[source]¶
This class stores dense vector with the respect to blocks
- Parameters:
vectors (dict) – Dense vectors stored blockwise
blocks_size (list) – Size of the blocks
blocks (list) – Block identifiers
- __getitem__(item)[source]¶
Index operator
- Parameters:
item (tuple) – Input index in tuple (block_id, index)
- Returns:
Value associated to index
- Return type:
float
- get_block(block_id)[source]¶
Get vector associated to the blocks
- Parameters:
block_id – Block identifier
- Returns:
Vector
- Return type:
ndarray
- set_block(block_id, array)[source]¶
Sets vector associated to block
- Parameters:
block_id (int) – Block identifier
array (ndarray) – Array to set
- __setitem__(key, value)[source]¶
Index operator
- Parameters:
key (tuple) – Index as tuple: (block_id, index)
value (float) – Value to set
- property num_blocks¶
Return number of blocks
- Returns:
Number of blocks
- Return type:
int
- __add__(other)[source]¶
Operator +
- Parameters:
other (BlockVector) – Other vector
- Returns:
Sum of two vectors
- Return type:
- __sub__(other)[source]¶
Operator -
- Parameters:
other (BlockVector) – Other vector
- Returns:
Difference of two vectors
- Return type:
- __eq__(other)[source]¶
Operator ==, checks if two vectors are equal
- Parameters:
other (BlockVector) – Other vector
- Returns:
True or False
- Return type:
bool
- __mul__(other)[source]¶
Multiplication operator. Currently supports only scalar types for multiplication
- Parameters:
other (float) – Scalar value
- Returns:
Vector multiplied by scalar value
- Return type:
- Raises:
ValueError – If
otheris not a sequence
- __truediv__(other)[source]¶
True division operator. Currently supports only scalar types for division
- Parameters:
other (float) – Scalar value
- Returns:
Vector divided by scalar value
- Return type:
- Raises:
ValueError – If
otheris not a sequence
- decogo.util.block_vector.infinity_norm(x)[source]¶
Computes infinity norm, i.e. \(||x||_\infty = \max\limits_{k \in K, i \in n_k}|x_{ki}|\)
- Parameters:
x (BlockVector or SparseBlockVector) – Input vector
- Returns:
Value of infinity norm
- Return type:
float