code: def test_matvec(self):
      def get_matvecs(A):
          return [
              {
                  "shape": A.shape,
                  "matvec": lambda x: np.dot(A, x).reshape(A.shape[0]),
                  "rmatvec": lambda x: np.dot(A.T.conj(), x).reshape(
                      A.shape[1]
                  ),
              },
              {
                  "shape": A.shape,
                  "matvec": lambda x: np.dot(A, x),
                  "rmatvec": lambda x: np.dot(A.T.conj(), x),
                  "matmat": lambda x: np.dot(A, x),
              },
          ]
  
      for matvecs in get_matvecs(self.A):
          A = interface.LinearOperator(**matvecs)
  
          assert_(A.args == ())
  
          assert_equal(A.matvec(np.array([1, 2, 3])), [14, 32])
          assert_equal(
              A.matvec(np.array([[1], [2], [3]])), [[14], [32]]
          )
          assert_equal(A * np.array([1, 2, 3]), [14, 32])
          assert_equal(A * np.array([[1], [2], [3]]), [[14], [32]])
          assert_equal(A.dot(np.array([1, 2, 3])), [14, 32])
          assert_equal(A.dot(np.array([[1], [2], [3]])), [[14], [32]])
  
          assert_equal(A.matvec(matrix([[1], [2], [3]])), [[14], [32]])
          assert_equal(A * matrix([[1], [2], [3]]), [[14], [32]])
          assert_equal(A.dot(matrix([[1], [2], [3]])), [[14], [32]])
  
          assert_equal((2 * A) * [1, 1, 1], [12, 30])
          assert_equal((2 * A).rmatvec([1, 1]), [10, 14, 18])
          assert_equal((2 * A).H.matvec([1, 1]), [10, 14, 18])
          assert_equal((2 * A) * [[1], [1], [1]], [[12], [30]])
          assert_equal((2 * A).matmat([[1], [1], [1]]), [[12], [30]])
          assert_equal((A * 2) * [1, 1, 1], [12, 30])
          assert_equal((A * 2) * [[1], [1], [1]], [[12], [30]])
          assert_equal((2j * A) * [1, 1, 1], [12j, 30j])
          assert_equal((A + A) * [1, 1, 1], [12, 30])
          assert_equal((A + A).rmatvec([1, 1]), [10, 14, 18])
          assert_equal((A + A).H.matvec([1, 1]), [10, 14, 18])
          assert_equal((A + A) * [[1], [1], [1]], [[12], [30]])
          assert_equal((A + A).matmat([[1], [1], [1]]), [[12], [30]])
          assert_equal((-A) * [1, 1, 1], [-6, -15])
          assert_equal((-A) * [[1], [1], [1]], [[-6], [-15]])
          assert_equal((A - A) * [1, 1, 1], [0, 0])
          assert_equal((A - A) * [[1], [1], [1]], [[0], [0]])
  
          z = A + A
          assert_(
              len(z.args) == 2 and z.args[0] is A and z.args[1] is A
          )
          z = 2 * A
          assert_(
              len(z.args) == 2 and z.args[0] is A and z.args[1] == 2
          )
  
          assert_(isinstance(A.matvec([1, 2, 3]), np.ndarray))
          assert_(
              isinstance(
                  A.matvec(np.array([[1], [2], [3]])), np.ndarray
              )
          )
          assert_(isinstance(A * np.array([1, 2, 3]), np.ndarray))
          assert_(isinstance(A * np.array([[1], [2], [3]]), np.ndarray))
          assert_(isinstance(A.dot(np.array([1, 2, 3])), np.ndarray))
          assert_(
              isinstance(A.dot(np.array([[1], [2], [3]])), np.ndarray)
          )
  
          assert_(
              isinstance(A.matvec(matrix([[1], [2], [3]])), np.ndarray)
          )
          assert_(isinstance(A * matrix([[1], [2], [3]]), np.ndarray))
          assert_(
              isinstance(A.dot(matrix([[1], [2], [3]])), np.ndarray)
          )
  
          assert_(isinstance(2 * A, interface._ScaledLinearOperator))
          assert_(isinstance(2j * A, interface._ScaledLinearOperator))
          assert_(isinstance(A + A, interface._SumLinearOperator))
          assert_(isinstance(-A, interface._ScaledLinearOperator))
          assert_(isinstance(A - A, interface._SumLinearOperator))
  
          assert_((2j * A).dtype == np.complex_)
  
          assert_raises(ValueError, A.matvec, np.array([1, 2]))
          assert_raises(ValueError, A.matvec, np.array([1, 2, 3, 4]))
          assert_raises(ValueError, A.matvec, np.array([[1], [2]]))
          assert_raises(
              ValueError, A.matvec, np.array([[1], [2], [3], [4]])
          )
  
          assert_raises(ValueError, lambda: A * A)
          assert_raises(ValueError, lambda: A**2)
  
      for matvecsA, matvecsB in product(
          get_matvecs(self.A), get_matvecs(self.B)
      ):
          A = interface.LinearOperator(**matvecsA)
          B = interface.LinearOperator(**matvecsB)
  
          assert_equal((A * B) * [1, 1], [50, 113])
          assert_equal((A * B) * [[1], [1]], [[50], [113]])
          assert_equal((A * B).matmat([[1], [1]]), [[50], [113]])
  
          assert_equal((A * B).rmatvec([1, 1]), [71, 92])
          assert_equal((A * B).H.matvec([1, 1]), [71, 92])
  
          assert_(isinstance(A * B, interface._ProductLinearOperator))
  
          assert_raises(ValueError, lambda: A + B)
          assert_raises(ValueError, lambda: A**2)
  
          z = A * B
          assert_(
              len(z.args) == 2 and z.args[0] is A and z.args[1] is B
          )
  
      for matvecsC in get_matvecs(self.C):
          C = interface.LinearOperator(**matvecsC)
  
          assert_equal((C**2) * [1, 1], [17, 37])
          assert_equal((C**2).rmatvec([1, 1]), [22, 32])
          assert_equal((C**2).H.matvec([1, 1]), [22, 32])
          assert_equal((C**2).matmat([[1], [1]]), [[17], [37]])
  
          assert_(isinstance(C**2, interface._PowerLinearOperator))
  
imports: from __future__ import division, print_function, absolute_import
  from functools import partial
  from itertools import product
  import operator
  import pytest
  from pytest import raises, warns
  from numpy.testing import assert_, assert_equal
  import numpy
  import scipy.sparse
  from scipy.sparse.linalg import interface
  from scipy.sparse.sputils import matrix
label_desc: Use image node_id 2 for calling the TestLinearOperator obj's underlying member method code with example usage: obj.test_matvec() and returns: list