Returns the matrix in the appropriate form for SWIG wrapper
(matrix, shape=None, format="dense")
| 249 | |
| 250 | |
| 251 | def 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() |
no test coverage detected