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)
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))
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)
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)
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))
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)))
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)
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)))
def sum_left(m, n): data = {} return left_matrix_product( dense_matrix(constant.store(np.ones((1, m)), data), data), n)
def sum_right(m, n): return right_matrix_product(dense_matrix(constant.store(np.ones((n,1)))), m)
def sum_left(m, n): return left_matrix_product(dense_matrix(constant.store(np.ones((1,m)))), n)
def sum(m, n): return kronecker_product( dense_matrix(constant.store(np.ones((1,n)))), dense_matrix(constant.store(np.ones((1,m)))))
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)
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))
def one_hot(i, n): return sparse_matrix( constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n,1))))
def sum_right(m, n): data = {} return right_matrix_product( dense_matrix(constant.store(np.ones((n, 1)), data), data), m)
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)
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)
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))
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))
def promote(n): return dense_matrix(constant.store(np.ones((n,1))))
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))
def promote(n): data = {} return dense_matrix(constant.store(np.ones((n, 1)), data), data)
def sum(n): return dense_matrix(constant.store(np.ones((1,n))))
def parameter_values(cvxpy_prob, data): return [(cvxpy_expr.parameter_id(param), constant.store(param.value, data).SerializeToString()) for param in cvxpy_prob.parameters()]
def one_hot(i, n): return sparse_matrix( constant.store(sp.coo_matrix(([1], ([i], [0])), shape=(n, 1))))