Esempio n. 1
0
def transform_hstack(expr):
    m = dim(expr, 0)
    n = dim(expr, 1)
    offset = 0
    add_args = []
    for arg in expr.arg:
        ni = dim(arg, 1)
        add_args.append(
            expression.linear_map(
                linear_map.right_matrix_product(linear_map.index(slice(offset, offset + ni), n), m), transform_expr(arg)
            )
        )
        offset += ni
    return expression.add(*add_args)
Esempio n. 2
0
def transform_hstack(expr):
    m = dim(expr, 0)
    n = dim(expr, 1)
    offset = 0
    add_args = []
    for arg in expr.arg:
        ni = dim(arg, 1)
        add_args.append(
            expression.linear_map(
                linear_map.right_matrix_product(
                    linear_map.index(slice(offset, offset + ni), n), m),
                transform_expr(arg)))
        offset += ni
    return expression.add(*add_args)
Esempio n. 3
0
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)
Esempio n. 4
0
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)