class_docstr: A `Type` for sparse tensors.
  
  Notes
  -----
  Currently, sparse tensors can only be matrices (i.e. have two dimensions).
class_docstr_tok: ["A","`","Type","`","for","sparse","tensors",".","Notes","--","--","-","Currently",",","sparse","tensors","can","only","be","matrices","(","i.e",".","have","two","dimensions",")","."]
code: def convert_variable(self, var):
      res = super().convert_variable(var)
  
      if res is None:
          return res
  
      if not isinstance(res.type, type(self)):
          if isinstance(res.type, DenseTensorType):
              if self.format == "csr":
                  from pytensor.sparse.basic import csr_from_dense
  
                  return csr_from_dense(res)
              else:
                  from pytensor.sparse.basic import csc_from_dense
  
                  return csc_from_dense(res)
  
          return None
  
      if res.format != self.format:
          # TODO: Convert sparse `var`s with different formats to this format?
          return None
  
      return res
  
imports: from collections.abc import Iterable
  from typing import Literal, Optional, Union
  import numpy
  import scipy.sparse
  import pytensor
  from pytensor import scalar
  from pytensor.graph.basic import Variable
  from pytensor.graph.type import HasDataType
  from pytensor.tensor.type import DenseTensorType, TensorType
label_desc: Use image node_id 5 for calling the SparseTensorType obj's underlying member method code with example usage: obj.convert_variable(var) and returns: res, res, None, None, csr_from_dense, csc_from_dense