def multiply_constant(expr, n): if expr.expression_type == Expression.CONSTANT: if expr.constant.constant_type == Constant.SCALAR: return linear_map.scalar(expr.constant.scalar, n) if expr.constant.constant_type == Constant.DENSE_MATRIX: return linear_map.dense_matrix(expr.constant, expr.data) if expr.constant.constant_type == Constant.SPARSE_MATRIX: return linear_map.sparse_matrix(expr.constant, expr.data) elif expr.expression_type == Expression.TRANSPOSE: return linear_map.transpose(multiply_constant(only_arg(expr), n)) raise TransformError("unknown constant type", 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)
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)