1

I'm using CVXPY through Julia, a language where multidimentional arrays are stored in memory using column-major order. However CVXPY is written in Python and accepts Numpy style arrays (which are row-major by default) to be used as constants.

I want to know if I should care about ordering, e.g. with matrix A, when translating Python code like this:

import cvxpy as cp
import numpy as np

m = 30
n = 20

A = np.random.randn(m, n)
b = np.random.randn(m)

# Construct the problem.
x = cp.Variable(n)
objective = cp.Minimize(cp.sum_squares(A*x - b))
constraints = [0 <= x, x <= 1]
prob = cp.Problem(objective, constraints)

to Julia:

using Random, PyCall
cp = pyimport("cvxpy")

m = 30
n = 20

A = randn(m, n)
b = randn(m)

# Construct the problem.
x = cp.Variable(n)
objective = cp.Minimize(cp.sum_squares(cp.matmul(A,x) - b))
constraints = [0 <= x, x <= 1]
prob = cp.Problem(objective, constraints)
fire-bee
  • 111
  • 1
  • 3
  • Looks like a valid question, but imho real-world applications of cvxpy and it's solvers are not dense and therefore lots of things change as sparse-matrices are not numpy-based anymore and there is a need for copying for sure (i suppose), as things get much more complex: not only col-major vs. row-major anymore. Another remark: i guess that everything your might lose due to copying (or whatever happens during wrapper) is dominated by solver-time.Fun fact: probably every solver there is will again copy and reorder your input to it's own internal matrix-format (see cvxopt, ecos, ...). – sascha Nov 20 '20 at 13:25

1 Answers1

0

I've seen exactly this done, and not seen any special handling from want I recall. So no, it doesn't cause any issues

Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137