Builds a sparse representation of the problem data. Parameters ---------- linOps: A list of python linOp trees representing an affine expression var_length: The total length of the variables. id_to_col: A map from variable id to column offset. param_to_s
(linOps,
var_length,
id_to_col,
param_to_size,
param_to_col,
constr_length,
canon_backend: str | None = None
)
| 258 | |
| 259 | |
| 260 | def get_problem_matrix(linOps, |
| 261 | var_length, |
| 262 | id_to_col, |
| 263 | param_to_size, |
| 264 | param_to_col, |
| 265 | constr_length, |
| 266 | canon_backend: str | None = None |
| 267 | ): |
| 268 | """ |
| 269 | Builds a sparse representation of the problem data. |
| 270 | |
| 271 | Parameters |
| 272 | ---------- |
| 273 | linOps: A list of python linOp trees representing an affine expression |
| 274 | var_length: The total length of the variables. |
| 275 | id_to_col: A map from variable id to column offset. |
| 276 | param_to_size: A map from parameter id to parameter size. |
| 277 | param_to_col: A map from parameter id to column in tensor. |
| 278 | constr_length: Summed sizes of constraints input. |
| 279 | canon_backend : |
| 280 | 'CPP' (default) | 'SCIPY' |
| 281 | Specifies which backend to use for canonicalization, which can affect |
| 282 | compilation time. Defaults to None, i.e., selecting the default backend. |
| 283 | |
| 284 | Returns |
| 285 | ------- |
| 286 | A sparse (CSC) matrix with constr_length * (var_length + 1) rows and |
| 287 | param_size + 1 columns (where param_size is the length of the |
| 288 | parameter vector). |
| 289 | """ |
| 290 | |
| 291 | # Allow to switch default backends through an environment variable for CI |
| 292 | default_canon_backend = get_default_canon_backend() |
| 293 | canon_backend = default_canon_backend if not canon_backend else canon_backend |
| 294 | |
| 295 | if canon_backend == s.CPP_CANON_BACKEND: |
| 296 | from cvxpy.cvxcore.python.cppbackend import build_matrix |
| 297 | return build_matrix(id_to_col, param_to_size, param_to_col, var_length, constr_length, linOps) |
| 298 | |
| 299 | elif canon_backend in {s.SCIPY_CANON_BACKEND, s.RUST_CANON_BACKEND, s.COO_CANON_BACKEND}: |
| 300 | param_size_plus_one = sum(param_to_size.values()) |
| 301 | output_shape = (np.int64(constr_length)*np.int64(var_length+1), |
| 302 | param_size_plus_one) |
| 303 | if len(linOps) > 0: |
| 304 | backend = get_backend(canon_backend, id_to_col, |
| 305 | param_to_size, param_to_col, |
| 306 | param_size_plus_one, var_length) |
| 307 | A_py = backend.build_matrix(linOps) |
| 308 | else: |
| 309 | A_py = sp.csc_array(((), ((), ())), output_shape) |
| 310 | assert A_py.shape == output_shape |
| 311 | return A_py |
| 312 | else: |
| 313 | raise ValueError(f'Unknown backend: {canon_backend}') |
| 314 |
nothing calls this directly
no test coverage detected