code: def test_convert_to_complex(self):
      val64 = np.ones(3, dtype="complex64") + 0.5j
      val128 = np.ones(3, dtype="complex128") + 0.5j
  
      vec64 = TensorType("complex64", shape=(None,))()
      vec128 = TensorType("complex128", shape=(None,))()
  
      f = function([vec64], _convert_to_complex128(vec64))
      # we need to compare with the same type.
      assert vec64.type.values_eq_approx(val128, f(val64))
  
      f = function([vec128], _convert_to_complex128(vec128))
      assert vec64.type.values_eq_approx(val128, f(val128))
  
      f = function([vec64], _convert_to_complex64(vec64))
      assert vec64.type.values_eq_approx(val64, f(val64))
  
      f = function([vec128], _convert_to_complex64(vec128))
      assert vec128.type.values_eq_approx(val64, f(val128))
  
      # upcasting to complex128
      for t in [
          "int8",
          "int16",
          "int32",
          "int64",
          "float32",
          "float64",
      ]:
          a = pytensor.shared(np.ones(3, dtype=t))
          b = pytensor.shared(np.ones(3, dtype="complex128"))
          f = function([], _convert_to_complex128(a))
          assert a.type.values_eq_approx(b.get_value(), f())
  
      # upcasting to complex64
      for t in ["int8", "int16", "int32", "int64", "float32"]:
          a = pytensor.shared(np.ones(3, dtype=t))
          b = pytensor.shared(np.ones(3, dtype="complex64"))
          f = function([], _convert_to_complex64(a))
          assert a.type.values_eq_approx(b.get_value(), f())
  
      # downcast to complex64
      for t in ["float64"]:
          a = pytensor.shared(np.ones(3, dtype=t))
          b = pytensor.shared(np.ones(3, dtype="complex64"))
          f = function([], _convert_to_complex64(a))
          assert a.type.values_eq_approx(b.get_value(), f())
  
file_path: pytensor/tests/tensor/test_casting.py
imports: import numpy
  import pytest
  import pytensor
  from pytensor import function
  from pytensor.compile.io import In
  from pytensor.misc.safe_asarray import _asarray
  from pytensor.tensor.basic import _convert_to_complex64, _convert_to_complex128, _convert_to_float32, _convert_to_float64, _convert_to_int8, _convert_to_int16, _convert_to_int32, _convert_to_int64, cast
  from pytensor.tensor.type import TensorType, bvector, dmatrix, dvector, fvector, ivector, zmatrix
label_desc: Use image node_id 4 for calling the TestCasting obj's underlying member method code with example usage: obj.test_convert_to_complex() without return types