code: def test_rop_lop():
      mx = tensor.matrix("mx")
      mv = tensor.matrix("mv")
      v = tensor.vector("v")
      y = matrix_inverse(mx).sum(axis=0)
  
      yv = tensor.Rop(y, mx, mv)
      rop_f = function([mx, mv], yv)
  
      sy, _ = theano.scan(
          lambda i, y, x, v: (tensor.grad(y[i], x) * v).sum(),
          sequences=tensor.arange(y.shape[0]),
          non_sequences=[y, mx, mv],
      )
      scan_f = function([mx, mv], sy)
  
      rng = np.random.RandomState(utt.fetch_seed())
      vx = np.asarray(rng.randn(4, 4), theano.config.floatX)
      vv = np.asarray(rng.randn(4, 4), theano.config.floatX)
  
      v1 = rop_f(vx, vv)
      v2 = scan_f(vx, vv)
  
      assert _allclose(v1, v2), "ROP mismatch: %s %s" % (v1, v2)
  
      raised = False
      try:
          tensor.Rop(
              theano.clone(y, replace={mx: break_op(mx)}), mx, mv
          )
      except ValueError:
          raised = True
      if not raised:
          raise Exception(
              (
                  "Op did not raised an error even though the function"
                  " is not differentiable"
              )
          )
  
      vv = np.asarray(rng.uniform(size=(4,)), theano.config.floatX)
      yv = tensor.Lop(y, mx, v)
      lop_f = function([mx, v], yv)
  
      sy = tensor.grad((v * y).sum(), mx)
      scan_f = function([mx, v], sy)
  
      v1 = lop_f(vx, vv)
      v2 = scan_f(vx, vv)
      assert _allclose(v1, v2), "LOP mismatch: %s %s" % (v1, v2)
  
file_path: Theano/theano/sandbox/linalg/tests/test_linalg.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import numpy.linalg
  import theano
  from theano import tensor, function
  from theano.tensor.basic import _allclose
  from theano.tests.test_rop import break_op
  from theano.tests import unittest_tools
  from theano import config
  from theano.tensor.nlinalg import MatrixInverse
  from theano.tensor import DimShuffle
  from theano.sandbox.linalg.ops import Cholesky, matrix_inverse, Solve, solve, spectral_radius_bound, imported_scipy, inv_as_solve
  from nose.plugins.skip import SkipTest
label_desc: Use image node_id 1 for calling a global function with example usage: test_rop_lop() without return types