BlockMatrix

(class from pyomo.contrib.pynumero.sparse.block_matrix)

class pyomo.contrib.pynumero.sparse.block_matrix.BlockMatrix(nbrows, nbcols)[source]

Bases: BaseBlockMatrix

Structured Matrix interface

_blocks

2D-array where submatrices are stored

Type:

numpy.ndarray

_bshape

number of block-rows and block-columns

Type:

tuple

_block_mask

2D-array with booleans that indicates if block is not empty. Empty blocks are represented with None

Type:

numpy.ndarray

_brow_lengths

1D-array with sizes of block-rows

Type:

numpy.ndarray

_bcol_lengths

1D-array with sizes of block-columns

Type:

numpy.ndarray

_undefined_brows

set of block row indices with undefined dimensions

Type:

set

_undefined_bcols

set of block column indices with undefined dimensions

Type:

set

Parameters:
  • nbrows (int) – number of block-rows in the matrix

  • nbcols (int) – number of block-columns in the matrix

__init__(nbrows, nbcols)[source]

Methods

__init__(nbrows, nbcols)

block_shapes()

Returns list with shapes of blocks in this BlockMatrix

col_block_sizes([copy])

Returns array with col-block sizes

coo_data()

Returns data array of matrix.

copy([deep])

Makes a copy of this BlockMatrix

copy_structure()

Makes a copy of the structure of this BlockMatrix.

copyfrom(other[, deep])

Copies entries of other matrix into this matrix.

copyto(other[, deep])

Copies entries of this BlockMatrix into other.

diagonal([k])

dot(other)

Ordinary dot product

get_block(row, col)

get_block_column_index(index)

Returns block-column idx from matrix column index.

get_block_mask([copy])

get_block_row_index(index)

Returns block-row idx from matrix row index.

get_col_size(col)

get_row_size(row)

getcol(j)

Returns vector of column j

getrow(i)

Returns vector of column i

has_undefined_col_sizes()

Indicates if the matrix has block-columns with undefined dimensions

has_undefined_row_sizes()

Indicates if the matrix has block-rows with undefined dimensions

is_col_size_defined(col)

is_empty_block(idx, jdx)

Indicates if a block is None

is_row_size_defined(row)

mean([axis, dtype, out])

nonzero()

reset_bcol(jdx)

Resets all blocks in selected block-column to None

reset_brow(idx)

Resets all blocks in selected block-row to None

row_block_sizes([copy])

Returns array with row-block sizes

set_block(row, col, value)

set_col_size(col, size)

set_row_size(row, size)

setdiag(values[, k])

sum([axis, dtype, out])

toarray([order, out])

Returns a numpy.ndarray representation of this matrix.

tobsr([blocksize, copy])

tocoo([copy])

Converts this matrix to COOrdinate format.

tocsc([copy])

Converts this matrix to Compressed Sparse Column format.

tocsr([copy])

Converts this matrix to Compressed Sparse Row format.

todia([copy])

tolil([copy])

tostring([order])

transpose([axes, copy])

Creates a transpose copy of the BlockMatrix.

Attributes

T

Transpose matrix

bshape

Returns tuple with the block-shape of the matrix

dtype

Returns data type of the matrix.

format

nnz

Returns total number of nonzero values in this matrix

shape

Returns tuple with total number of rows and columns

Member Documentation

block_shapes()[source]

Returns list with shapes of blocks in this BlockMatrix

Notes

For a BlockMatrix with 2 block-rows and 2 block-cols this method returns [[Block_00.shape, Block_01.shape],[Block_10.shape, Block_11.shape]]

Return type:

list

col_block_sizes(copy=True)[source]

Returns array with col-block sizes

Parameters:

copy (bool) – If False, then the internal array which stores the column block sizes will be returned without being copied. Setting copy to False is risky and should only be done with extreme care.

Return type:

numpy.ndarray

coo_data()[source]

Returns data array of matrix. The array corresponds to the data pointer in COOrdinate matrix format.

Return type:

numpy.ndarray with values of all entries in the matrix

copy(deep=True)[source]

Makes a copy of this BlockMatrix

Parameters:

deep (bool) – If deep is True, then the blocks in this BlockMatrix are copied

Return type:

BlockMatrix

copy_structure()[source]

Makes a copy of the structure of this BlockMatrix. This proivides a light-weighted copy of each block in this BlockMatrix. The blocks in the resulting matrix have the same shape as in the original matrices but not the same number of nonzeros.

Return type:

BlockMatrix

copyfrom(other, deep=True)[source]

Copies entries of other matrix into this matrix. This method provides an easy way to populate a BlockMatrix from scipy.sparse matrices. It also intended to facilitate copying values from other BlockMatrix to this BlockMatrix

Parameters:
  • other (BlockMatrix or scipy.spmatrix)

  • deep (bool) – If deep is True and other is a BlockMatrix, then the blocks in other are copied. If deep is False and other is a BlockMatrix, then the blocks in other are not copied.

Return type:

None

copyto(other, deep=True)[source]

Copies entries of this BlockMatrix into other. This method provides an easy way to copy values of this matrix into another format.

Parameters:
  • other (BlockMatrix or scipy.spmatrix)

  • deep (bool) – If deep is True and other is a BlockMatrix, then the blocks in this BlockMatrix are copied. If deep is False and other is a BlockMatrix, then the blocks in this BlockMatrix are not copied.

Return type:

None

dot(other)[source]

Ordinary dot product

get_block_column_index(index)[source]

Returns block-column idx from matrix column index.

Parameters:

index (int) – Column index

Return type:

int

get_block_row_index(index)[source]

Returns block-row idx from matrix row index.

Parameters:

index (int) – Row index

Return type:

int

getcol(j)[source]

Returns vector of column j

Parameters:

j (int) – Column index

Return type:

pyomo.contrib.pynumero.sparse BlockVector

getrow(i)[source]

Returns vector of column i

Parameters:

i (int) – Row index

Return type:

pyomo.contrib.pynumero.sparse BlockVector

has_undefined_col_sizes()[source]

Indicates if the matrix has block-columns with undefined dimensions

Return type:

bool

has_undefined_row_sizes()[source]

Indicates if the matrix has block-rows with undefined dimensions

Return type:

bool

is_empty_block(idx, jdx)[source]

Indicates if a block is None

Parameters:
  • idx (int) – block-row index

  • jdx (int) – block-column index

Return type:

bool

reset_bcol(jdx)[source]

Resets all blocks in selected block-column to None

Parameters:

jdx (int) – block-column index to be reset

Return type:

None

reset_brow(idx)[source]

Resets all blocks in selected block-row to None

Parameters:

idx (int) – block-row index to be reset

Return type:

None

row_block_sizes(copy=True)[source]

Returns array with row-block sizes

Parameters:

copy (bool) – If False, then the internal array which stores the row block sizes will be returned without being copied. Setting copy to False is risky and should only be done with extreme care.

Return type:

numpy.ndarray

toarray(order=None, out=None)[source]

Returns a numpy.ndarray representation of this matrix.

Parameters:
  • order ({'C', 'F'}, optional) – Whether to store multi-dimensional data in C (row-major) or Fortran (column-major) order in memory. The default is ‘None’, indicating the NumPy default of C-ordered. Cannot be specified in conjunction with the out argument.

  • out (ndarray, 2-dimensional, optional) – If specified, uses this array as the output buffer instead of allocating a new array to return. The provided array must have the same shape and dtype as the sparse matrix on which you are calling the method. For most sparse types, out is required to be memory contiguous (either C or Fortran ordered).

Returns:

arr – An array with the same shape and containing the same data represented by the BlockMatrix.

Return type:

ndarray, 2-dimensional

tocoo(copy=True)[source]

Converts this matrix to COOrdinate format.

Parameters:

copy (bool, optional) – This argument is in the signature solely for Scipy compatibility reasons. It does not do anything. The data is always copied.

Return type:

scipy.sparse.coo_matrix

tocsc(copy=True)[source]

Converts this matrix to Compressed Sparse Column format.

Parameters:

copy (bool, optional) – This argument is in the signature solely for Scipy compatibility reasons. It does not do anything. The data is always copied.

Return type:

scipy.sparse.csc_matrix

tocsr(copy=True)[source]

Converts this matrix to Compressed Sparse Row format.

Parameters:

copy (bool, optional) – This argument is in the signature solely for Scipy compatibility reasons. It does not do anything. The data is always copied.

Return type:

scipy.sparse.csr_matrix

transpose(axes=None, copy=True)[source]

Creates a transpose copy of the BlockMatrix.

Parameters:
  • axes (None, optional) – This argument is in the signature solely for NumPy compatibility reasons. Do not pass in anything except for the default value.

  • copy (bool) – This argument is in the signature solely for scipy compatibility reasons. Do not pass in anything except for the default value.

Return type:

BlockMatrix with dimensions reversed

property T

Transpose matrix

property bshape

Returns tuple with the block-shape of the matrix

property dtype

Returns data type of the matrix.

property nnz

Returns total number of nonzero values in this matrix

property shape

Returns tuple with total number of rows and columns