예제 #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)
예제 #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))
예제 #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)
예제 #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)
예제 #5
0
파일: linear_map.py 프로젝트: silky/epsilon
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))
예제 #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)))
예제 #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)
예제 #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)))
예제 #9
0
def sum_left(m, n):
    data = {}
    return left_matrix_product(
        dense_matrix(constant.store(np.ones((1, m)), data), data), n)
예제 #10
0
def sum_right(m, n):
    return right_matrix_product(dense_matrix(constant.store(np.ones((n,1)))), m)
예제 #11
0
def sum_left(m, n):
    return left_matrix_product(dense_matrix(constant.store(np.ones((1,m)))), n)
예제 #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)))))
예제 #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)
예제 #14
0
파일: linear_map.py 프로젝트: silky/epsilon
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))
예제 #15
0
파일: linear_map.py 프로젝트: silky/epsilon
def one_hot(i, n):
    return sparse_matrix(
        constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n,1))))
예제 #16
0
def sum_right(m, n):
    data = {}
    return right_matrix_product(
        dense_matrix(constant.store(np.ones((n, 1)), data), data), m)
예제 #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)
예제 #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)
예제 #19
0
파일: linear_map.py 프로젝트: silky/epsilon
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))
예제 #20
0
파일: linear_map.py 프로젝트: silky/epsilon
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))
예제 #21
0
파일: linear_map.py 프로젝트: silky/epsilon
def promote(n):
    return dense_matrix(constant.store(np.ones((n,1))))
예제 #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))
예제 #23
0
def promote(n):
    data = {}
    return dense_matrix(constant.store(np.ones((n, 1)), data), data)
예제 #24
0
파일: linear_map.py 프로젝트: silky/epsilon
def sum(n):
    return dense_matrix(constant.store(np.ones((1,n))))
예제 #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()]
예제 #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()]
예제 #27
0
def one_hot(i, n):
    return sparse_matrix(
        constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n, 1))))