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 filter(self, value, strict=False, allow_downcast=None):
      if isinstance(value, Variable):
          raise TypeError(
              "Expected an array-like object, but found a Variable: "
              "maybe you are trying to call a function on a (possibly "
              "shared) variable instead of a numeric array?"
          )
  
      if (
          isinstance(value, self.format_cls[self.format])
          and value.dtype == self.dtype
      ):
          return value
  
      if strict:
          raise TypeError(
              f"{value} is not sparse, or not the right dtype (is {value.dtype}, "
              f"expected {self.dtype})"
          )
  
      # The input format could be converted here
      if allow_downcast:
          sp = self.format_cls[self.format](value, dtype=self.dtype)
      else:
          data = self.format_cls[self.format](value)
          up_dtype = ps.upcast(self.dtype, data.dtype)
          if up_dtype != self.dtype:
              raise TypeError(
                  f"Expected {self.dtype} dtype but got {data.dtype}"
              )
          sp = data.astype(up_dtype)
  
      assert sp.format == self.format
  
      return sp
  
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 3 for calling the SparseTensorType obj's underlying member method code with example usage: obj.filter(value, strict, allow_downcast) and returns: sp, value