def block_add(self, matrix, block, vert_offset, horiz_offset, rows, cols, vert_step=1, horiz_step=1): # If the block is a scalar, promote it. if intf.is_scalar(block): block = self.scalar_matrix(intf.scalar_value(block), rows, cols) # If the block is a vector coerced into a matrix, promote it. elif intf.is_vector(block) and cols > 1: block = self.reshape(block, (rows, cols)) # If the block is a matrix coerced into a vector, vectorize it. elif not intf.is_vector(block) and cols == 1: block = self.reshape(block, (rows, cols)) # Ensure the block is the same type as the matrix. elif type(block) != type(matrix): block = self.const_to_matrix(block) matrix[vert_offset:(rows+vert_offset):vert_step, horiz_offset:(horiz_offset+cols):horiz_step] += block
def _format_block(self, matrix, block, rows, cols): """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. """ # If the block is a scalar, promote it. if intf.is_scalar(block): block = self.scalar_matrix(intf.scalar_value(block), rows, cols) # If the block is a vector coerced into a matrix, promote it. elif intf.is_vector(block) and cols > 1: block = self.reshape(block, (rows, cols)) # If the block is a matrix coerced into a vector, vectorize it. elif not intf.is_vector(block) and cols == 1: block = self.reshape(block, (rows, cols)) # Ensure the block is the same type as the matrix. elif type(block) != type(matrix): block = self.const_to_matrix(block) return block