def aslinearoperator(A):
 if isinstance(A, LinearOperator):
  return A
 elif (isinstance(A, np.ndarray) or isinstance(A, np.matrix)):
  if (A.ndim > 2):
   raise ValueError('array must have ndim <= 2')
  A = np.atleast_2d(np.asarray(A))
  return MatrixLinearOperator(A)
 elif isspmatrix(A):
  return MatrixLinearOperator(A)
 elif (hasattr(A, 'shape') and hasattr(A, 'matvec')):
  rmatvec = None
  dtype = None
  if hasattr(A, 'rmatvec'):
   rmatvec = A.rmatvec
  if hasattr(A, 'dtype'):
   dtype = A.dtype
  return LinearOperator(A.shape, A.matvec, rmatvec=rmatvec, dtype=dtype)
 else:
  raise TypeError('type not understood')

def aslinearoperator ( A ) : if isinstance ( A , LinearOperator ) : return A elif ( isinstance ( A , np . ndarray ) or isinstance ( A , np . matrix ) ) : if ( A . ndim > 2 ) : raise ValueError ( 'array must have ndim <= 2' ) A = np . atleast_2d ( np . asarray ( A ) ) return MatrixLinearOperator ( A ) elif isspmatrix ( A ) : return MatrixLinearOperator ( A ) elif ( hasattr ( A , 'shape' ) and hasattr ( A , 'matvec' ) ) : rmatvec = None dtype = None if hasattr ( A , 'rmatvec' ) : rmatvec = A . rmatvec if hasattr ( A , 'dtype' ) : dtype = A . dtype return LinearOperator ( A . shape , A . matvec , rmatvec = rmatvec , dtype = dtype ) else : raise TypeError ( 'type not understood' )
return a as a linearoperator .