Calls the appropriate cvxcore function to set the matrix data field of our C++ linOp.
(linC, linPy)
| 228 | |
| 229 | |
| 230 | def set_matrix_data(linC, linPy) -> None: |
| 231 | """Calls the appropriate cvxcore function to set the matrix data field of |
| 232 | our C++ linOp. |
| 233 | """ |
| 234 | |
| 235 | if get_type(linPy) == cvxcore.SPARSE_CONST: |
| 236 | coo = format_matrix(linPy.data, format="sparse") |
| 237 | # Ensure arrays are contiguous for C++ SWIG interface. |
| 238 | # scipy 1.17.0 may return non-contiguous arrays from sparse conversions. |
| 239 | linC.set_sparse_data( |
| 240 | np.ascontiguousarray(coo.data), |
| 241 | np.ascontiguousarray(coo.row, dtype=float), |
| 242 | np.ascontiguousarray(coo.col, dtype=float), |
| 243 | coo.shape[0], |
| 244 | coo.shape[1], |
| 245 | ) |
| 246 | else: |
| 247 | linC.set_dense_data(format_matrix(linPy.data, shape=linPy.shape)) |
| 248 | linC.set_data_ndim(len(linPy.data.shape)) |
| 249 | |
| 250 | |
| 251 | def format_matrix(matrix, shape=None, format="dense"): |
no test coverage detected