'Matrix-vector multiplication.
Performs the operation y=A*x where A is an MxN linear
operator and x is a column vector or 1-d array.
Parameters
x : {matrix, ndarray}
An array with shape (N,) or (N,1).
Returns
y : {matrix, ndarray}
A matrix or ndarray with shape (M,) or (M,1) depending
on the type and shape of the x argument.
Notes
This matvec wraps the user-specified matvec routine or overridden
_matvec method to ensure that y has the correct shape and type.'

def matvec(self, x):

    x = np.asanyarray(x)
    (M, N) = self.shape
    if ((x.shape != (N,)) and (x.shape != (N, 1))):
        raise ValueError('dimension    mismatch')
    y = self._matvec(x)
    if isinstance(x, np.matrix):
        y = np.asmatrix(y)
    else:
        y = np.asarray(y)
    if (x.ndim == 1):
        y = y.reshape(M)
    elif (x.ndim == 2):
        y = y.reshape(M, 1)
    else:
        raise ValueError('invalid    shape    returned    by    user-defined    matvec()')
    return y
