MCPcopy Create free account
hub / github.com/cvxpy/cvxpy / _format_block

Method _format_block

cvxpy/interface/base_matrix_interface.py:116–138  ·  view source on GitHub ↗

Formats the block for block_add. Args: matrix: The matrix the block will be added to. block: The matrix/scalar to be added. rows: The height of the block. cols: The width of the block.

(self, matrix, block, rows, cols)

Source from the content-addressed store, hash-verified

114 horiz_offset:(horiz_offset+cols):horiz_step] += block
115
116 def _format_block(self, matrix, block, rows, cols):
117 """Formats the block for block_add.
118
119 Args:
120 matrix: The matrix the block will be added to.
121 block: The matrix/scalar to be added.
122 rows: The height of the block.
123 cols: The width of the block.
124 """
125 # If the block is a scalar, promote it.
126 if cvxpy.interface.matrix_utilities.is_scalar(block):
127 block = self.scalar_matrix(
128 cvxpy.interface.matrix_utilities.scalar_value(block), rows, cols)
129 # If the block is a vector coerced into a matrix, promote it.
130 elif cvxpy.interface.matrix_utilities.is_vector(block) and cols > 1:
131 block = self.reshape(block, (rows, cols))
132 # If the block is a matrix coerced into a vector, vectorize it.
133 elif not cvxpy.interface.matrix_utilities.is_vector(block) and cols == 1:
134 block = self.reshape(block, (rows, cols))
135 # Ensure the block is the same type as the matrix.
136 elif type(block) != type(matrix):
137 block = self.const_to_matrix(block)
138 return block

Callers 2

block_addMethod · 0.95
block_addMethod · 0.80

Calls 7

scalar_matrixMethod · 0.95
reshapeMethod · 0.95
const_to_matrixMethod · 0.95
typeClass · 0.85
is_scalarMethod · 0.80
is_vectorMethod · 0.80
scalar_valueMethod · 0.45

Tested by

no test coverage detected