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)
| 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 |
no test coverage detected