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

Function format_matrix

cvxpy/cvxcore/python/cppbackend.py:251–265  ·  view source on GitHub ↗

Returns the matrix in the appropriate form for SWIG wrapper

(matrix, shape=None, format="dense")

Source from the content-addressed store, hash-verified

249
250
251def format_matrix(matrix, shape=None, format="dense"):
252 """Returns the matrix in the appropriate form for SWIG wrapper"""
253 if format == "dense":
254 # Ensure is 2D.
255 if len(shape) == 0:
256 shape = (1, 1)
257 elif len(shape) == 1:
258 shape = shape + (1,)
259 return np.reshape(matrix, shape, order="F")
260 elif format == "sparse":
261 return sp.coo_matrix(matrix)
262 elif format == "scalar":
263 return np.asfortranarray([[matrix]])
264 else:
265 raise NotImplementedError()

Callers 2

set_linC_dataFunction · 0.85
set_matrix_dataFunction · 0.85

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected