Exemple #1
0
def upper_tri(n):
    data = {}
    m = n * (n - 1) / 2
    rows = np.arange(m)
    cols = np.array([j * n + i for i in xrange(n) for j in xrange(i + 1, n)])
    A = sp.coo_matrix((np.ones(m), (rows, cols)), shape=(m, n * n))
    return sparse_matrix(constant.store(A, data), data)
Exemple #2
0
def transpose_matrix(m, n):
    A = sp.coo_matrix(
        (np.ones(m*n),
         (np.arange(m*n),
          np.tile(np.arange(n)*m, m) + np.repeat(np.arange(m), n))),
        shape=(m*n, m*n))
    return sparse_matrix(constant.store(A))
Exemple #3
0
def ones(*dims):
    data = {}
    return Expression(expression_type=expression_pb2.Expression.CONSTANT,
                      size=Size(dim=dims),
                      data=data,
                      constant=_constant.store(np.ones(dims), data),
                      func_curvature=CONSTANT)
Exemple #4
0
def ones(*dims):
    data = {}
    return Expression(
        expression_type=expression_pb2.Expression.CONSTANT,
        size=Size(dim=dims),
        data=data,
        constant=_constant.store(np.ones(dims), data),
        func_curvature=CONSTANT)
Exemple #5
0
def index(slice, n):
    m = slice.stop - slice.start
    if m == n:
        return identity(n)

    A = sp.coo_matrix(
        (np.ones(m),
         (np.arange(m), np.arange(slice.start, slice.stop, slice.step))),
        shape=(m, n))
    return sparse_matrix(constant.store(A))
Exemple #6
0
def convert_constant(expr):
    m, n = expr.size
    if isinstance(expr.value, (int, long, float)):
        return expression.constant(m, n, scalar=expr.value)
    else:
        return expression.constant(
            m, n,
            constant=constant.store(expr.value),
            sign=expression_pb2.Sign(
                sign_type=expression_pb2.Sign.Type.Value(expr.sign)))
Exemple #7
0
def index(slice, n):
    m = slice.stop - slice.start
    if m == n:
        return identity(n)

    A = sp.coo_matrix(
        (np.ones(m),
         (np.arange(m), np.arange(slice.start, slice.stop, slice.step))),
        shape=(m, n))
    data = {}
    return sparse_matrix(constant.store(A, data), data)
Exemple #8
0
def convert_constant(expr):
    m, n = expr.size
    if isinstance(expr.value, (int, float)):
        return expression.constant(m, n, scalar=expr.value)
    else:
        data = {}
        return expression.constant(
            m, n,
            data=data,
            constant=constant.store(expr.value, data),
            sign=expression_pb2.Sign(
                sign_type=expression_pb2.Sign.Type.Value(expr.sign)))
Exemple #9
0
def sum_left(m, n):
    data = {}
    return left_matrix_product(
        dense_matrix(constant.store(np.ones((1, m)), data), data), n)
Exemple #10
0
def sum_right(m, n):
    return right_matrix_product(dense_matrix(constant.store(np.ones((n,1)))), m)
Exemple #11
0
def sum_left(m, n):
    return left_matrix_product(dense_matrix(constant.store(np.ones((1,m)))), n)
Exemple #12
0
def sum(m, n):
    return kronecker_product(
        dense_matrix(constant.store(np.ones((1,n)))),
        dense_matrix(constant.store(np.ones((1,m)))))
Exemple #13
0
def transpose_matrix(m, n):
    A = sp.coo_matrix((np.ones(m * n), (np.arange(
        m * n), np.tile(np.arange(n) * m, m) + np.repeat(np.arange(m), n))),
                      shape=(m * n, m * n))
    data = {}
    return sparse_matrix(constant.store(A, data), data)
Exemple #14
0
def upper_tri(n):
    m = n*(n-1)/2
    rows = np.arange(m)
    cols = np.array([j*n + i for i in xrange(n) for j in xrange(i+1,n)])
    A = sp.coo_matrix((np.ones(m), (rows, cols)), shape=(m, n*n))
    return sparse_matrix(constant.store(A))
Exemple #15
0
def one_hot(i, n):
    return sparse_matrix(
        constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n,1))))
Exemple #16
0
def sum_right(m, n):
    data = {}
    return right_matrix_product(
        dense_matrix(constant.store(np.ones((n, 1)), data), data), m)
Exemple #17
0
def trace(n):
    data = {}
    rows = np.zeros(n)
    cols = np.arange(n) * (n + 1)
    A = sp.coo_matrix((np.ones(n), (rows, cols)), shape=(1, n * n))
    return sparse_matrix(constant.store(A, data), data)
Exemple #18
0
def diag_vec(n):
    data = {}
    rows = np.arange(n) * (n + 1)
    cols = np.arange(n)
    A = sp.coo_matrix((np.ones(n), (rows, cols)), shape=(n * n, n))
    return sparse_matrix(constant.store(A, data), data)
Exemple #19
0
def diag_vec(n):
    rows = np.arange(n)*(n+1)
    cols = np.arange(n)
    A = sp.coo_matrix((np.ones(n), (rows, cols)), shape=(n*n, n))
    return sparse_matrix(constant.store(A))
Exemple #20
0
def trace(n):
    rows = np.zeros(n)
    cols = np.arange(n)*(n+1)
    A = sp.coo_matrix((np.ones(n), (rows, cols)), shape=(1, n*n))
    return sparse_matrix(constant.store(A))
Exemple #21
0
def promote(n):
    return dense_matrix(constant.store(np.ones((n,1))))
Exemple #22
0
def sum(m, n):
    data = {}
    return kronecker_product(
        dense_matrix(constant.store(np.ones((1, n)), data), data),
        dense_matrix(constant.store(np.ones((1, m)), data), data))
Exemple #23
0
def promote(n):
    data = {}
    return dense_matrix(constant.store(np.ones((n, 1)), data), data)
Exemple #24
0
def sum(n):
    return dense_matrix(constant.store(np.ones((1,n))))
Exemple #25
0
def parameter_values(cvxpy_prob, data):
    return [(cvxpy_expr.parameter_id(param),
             constant.store(param.value, data).SerializeToString())
            for param in cvxpy_prob.parameters()]
Exemple #26
0
def parameter_values(cvxpy_prob, data):
    return [(cvxpy_expr.parameter_id(param),
             constant.store(param.value, data).SerializeToString())
            for param in cvxpy_prob.parameters()]
Exemple #27
0
def one_hot(i, n):
    return sparse_matrix(
        constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n, 1))))