PendingDeprecationWarning: numpy matrix

188 views
Skip to first unread message

Allen Lawrence

unread,
Aug 6, 2018, 8:30:08 PM8/6/18
to cvxpy
Having just updated to numpy 1.15, `canonInterface.format_matrix` now triggers the following error:
PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
  return matrix(data, dtype=dtype, copy=False)


This is caused by a numpy.matrix conversion in `format_matrix`:
def format_matrix(matrix, format='dense'):
    ''' Returns the matrix in the appropriate form,
        so that it can be efficiently loaded with our swig wrapper
    '''
    if (format == 'dense'):
        # Ensure is 2D.
        matrix = np.atleast_2d(matrix)
        return np.asfortranarray(matrix)
    elif(format == 'sparse'):
        return scipy.sparse.coo_matrix(matrix)
    elif(format == 'scalar'):
        return np.asfortranarray(np.matrix(matrix))
    else:
        raise NotImplementedError()

This doesn't break anything (only a warning), I just mention I should post it here as a heads up.

Steven Diamond

unread,
Aug 13, 2018, 6:36:17 PM8/13/18
to cvxpy
I appreciate the heads up! It's good to know we need to take care of this.
Reply all
Reply to author
Forward
0 new messages