def transform_vstack(expr): m = dim(expr, 0) n = dim(expr, 1) offset = 0 add_args = [] for arg in expr.arg: mi = dim(arg, 0) add_args.append( expression.linear_map( linear_map.left_matrix_product( linear_map.transpose( linear_map.index(slice(offset, offset + mi), m)), n), transform_expr(arg))) offset += mi return expression.add(*add_args)
def transform_multiply(expr): if len(expr.arg) != 2: raise TransformError("wrong number of args", expr) m = dim(expr, 0) n = dim(expr, 1) if expr.arg[0].dcp_props.constant: A = multiply_constant(expr.arg[0], m) B = promote(transform_expr(expr.arg[1]), n * n) return expression.linear_map(linear_map.left_matrix_product(A, n), B) if expr.arg[1].dcp_props.constant: A = promote(transform_expr(expr.arg[0]), m * m) B = multiply_constant(expr.arg[1], n) return expression.linear_map(linear_map.right_matrix_product(B, m), A) raise TransformError("multiplying non constants", expr)
def transform_vstack(expr): m = dim(expr, 0) n = dim(expr, 1) offset = 0 add_args = [] for arg in expr.arg: mi = dim(arg, 0) add_args.append( expression.linear_map( linear_map.left_matrix_product( linear_map.transpose( linear_map.index(slice(offset, offset+mi), m)), n), transform_expr(arg))) offset += mi return expression.add(*add_args)