MCPcopy Create free account
hub / github.com/cvxpy/cvxpy / set_matrix_data

Function set_matrix_data

cvxpy/cvxcore/python/cppbackend.py:230–248  ·  view source on GitHub ↗

Calls the appropriate cvxcore function to set the matrix data field of our C++ linOp.

(linC, linPy)

Source from the content-addressed store, hash-verified

228
229
230def 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
251def format_matrix(matrix, shape=None, format="dense"):

Callers 1

set_linC_dataFunction · 0.85

Calls 5

get_typeFunction · 0.85
format_matrixFunction · 0.85
set_sparse_dataMethod · 0.45
set_dense_dataMethod · 0.45
set_data_ndimMethod · 0.45

Tested by

no test coverage detected