code: def test_tensorsolve():
      rng = np.random.default_rng(utt.fetch_seed())
  
      A = tensor4("A", dtype=config.floatX)
      B = matrix("B", dtype=config.floatX)
      X = tensorsolve(A, B)
      fn = function([A, B], [X])
  
      # slightly modified example from np.linalg.tensorsolve docstring
      a = np.eye(2 * 3 * 4).astype(config.floatX)
      a.shape = (2 * 3, 4, 2, 3 * 4)
      b = rng.random((2 * 3, 4)).astype(config.floatX)
  
      n_x = np.linalg.tensorsolve(a, b)
      t_x = fn(a, b)
      assert _allclose(n_x, t_x)
  
      # check the type upcast now
      C = tensor4("C", dtype="float32")
      D = matrix("D", dtype="float64")
      Y = tensorsolve(C, D)
      fn = function([C, D], [Y])
  
      c = np.eye(2 * 3 * 4, dtype="float32")
      c.shape = (2 * 3, 4, 2, 3 * 4)
      d = rng.random((2 * 3, 4)).astype("float64")
      n_y = np.linalg.tensorsolve(c, d)
      t_y = fn(c, d)
      assert _allclose(n_y, t_y)
      assert n_y.dtype == Y.dtype
  
      # check the type upcast now
      E = tensor4("E", dtype="int32")
      F = matrix("F", dtype="float64")
      Z = tensorsolve(E, F)
      fn = function([E, F], [Z])
  
      e = np.eye(2 * 3 * 4, dtype="int32")
      e.shape = (2 * 3, 4, 2, 3 * 4)
      f = rng.random((2 * 3, 4)).astype("float64")
      n_z = np.linalg.tensorsolve(e, f)
      t_z = fn(e, f)
      assert _allclose(n_z, t_z)
      assert n_z.dtype == Z.dtype
  
imports: import numpy
  import numpy.linalg
  import pytest
  from numpy import inf
  from numpy.testing import assert_array_almost_equal
  import pytensor
  from pytensor import function
  from pytensor.configdefaults import config
  from pytensor.tensor.math import _allclose
  from pytensor.tensor.nlinalg import SVD, Eig, MatrixInverse, TensorInv, det, eig, eigh, lstsq, matrix_dot, matrix_inverse, matrix_power, norm, pinv, qr, slogdet, svd, tensorinv, tensorsolve, trace
  from pytensor.tensor.type import lmatrix, lscalar, matrix, scalar, tensor3, tensor4, vector
  from tests import unittest_tools
label_desc: Use image node_id 5 for calling a global function with example usage: test_tensorsolve() without return types