code: def test_rop_lop():
      mx = matrix("mx")
      mv = matrix("mv")
      v = vector("v")
      y = MatrixInverse()(mx).sum(axis=0)
  
      yv = pytensor.gradient.Rop(y, mx, mv)
      rop_f = function([mx, mv], yv)
  
      sy, _ = pytensor.scan(
          lambda i, y, x, v: (
              pytensor.gradient.grad(y[i], x) * v
          ).sum(),
          sequences=pt.arange(y.shape[0]),
          non_sequences=[y, mx, mv],
      )
      scan_f = function([mx, mv], sy)
  
      rng = np.random.default_rng(utt.fetch_seed())
      vx = np.asarray(
          rng.standard_normal((4, 4)), pytensor.config.floatX
      )
      vv = np.asarray(
          rng.standard_normal((4, 4)), pytensor.config.floatX
      )
  
      v1 = rop_f(vx, vv)
      v2 = scan_f(vx, vv)
  
      assert _allclose(v1, v2), f"ROP mismatch: {v1} {v2}"
  
      raised = False
      try:
          pytensor.gradient.Rop(
              pytensor.clone_replace(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,)), pytensor.config.floatX)
      yv = pytensor.gradient.Lop(y, mx, v)
      lop_f = function([mx, v], yv)
  
      sy = pytensor.gradient.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), f"LOP mismatch: {v1} {v2}"
  
imports: from functools import partial
  import numpy
  import pytest
  import scipy.linalg
  from numpy.testing import assert_allclose
  import pytensor
  from pytensor import function
  from pytensor import tensor
  from pytensor.compile import get_default_mode
  from pytensor.configdefaults import config
  from pytensor.tensor import swapaxes
  from pytensor.tensor.blockwise import Blockwise
  from pytensor.tensor.elemwise import DimShuffle
  from pytensor.tensor.math import _allclose, dot, matmul
  from pytensor.tensor.nlinalg import Det, MatrixInverse, matrix_inverse
  from pytensor.tensor.rewriting.linalg import inv_as_solve
  from pytensor.tensor.slinalg import Cholesky, Solve, SolveBase, SolveTriangular, cho_solve, cholesky, solve, solve_triangular
  from pytensor.tensor.type import dmatrix, matrix, tensor, vector
  from tests import unittest_tools
  from tests.test_rop import break_op
label_desc: Use image node_id 1 for calling a global function with example usage: test_rop_lop() without return types