class_docstr: Pair for :class:`torch.Tensor`-like inputs.
  
  Kwargs:
      allow_subclasses (bool):
      rtol (Optional[float]): Relative tolerance. If specified ``atol`` must also be specified. If omitted, default
          values based on the type are selected. See :func:assert_close: for details.
      atol (Optional[float]): Absolute tolerance. If specified ``rtol`` must also be specified. If omitted, default
          values based on the type are selected. See :func:assert_close: for details.
      equal_nan (bool): If ``True``, two ``NaN`` values are considered equal. Defaults to ``False``.
      check_device (bool): If ``True`` (default), asserts that corresponding tensors are on the same
          :attr:`~torch.Tensor.device`. If this check is disabled, tensors on different
          :attr:`~torch.Tensor.device`'s are moved to the CPU before being compared.
      check_dtype (bool): If ``True`` (default), asserts that corresponding tensors have the same ``dtype``. If this
          check is disabled, tensors with different ``dtype``'s are promoted  to a common ``dtype`` (according to
          :func:`torch.promote_types`) before being compared.
      check_layout (bool): If ``True`` (default), asserts that corresponding tensors have the same ``layout``. If this
          check is disabled, tensors with different ``layout``'s are converted to strided tensors before being
          compared.
      check_stride (bool): If ``True`` and corresponding tensors are strided, asserts that they have the same stride.
class_docstr_tok: ["Pair","for",":","class",":","`","torch.Tensor","`","-like","inputs",".","Kwargs",":","allow_subclasses","(","bool",")",":","rtol","(","Optional","[","float","]",")",":","Relative","tolerance",".","If","specified","``","atol","``","must","also","be","specified",".","If","omitted",",","default","values","based","on","the","type","are","selected",".","See",":","func",":","assert_close",":","for","details",".","atol","(","Optional","[","float","]",")",":","Absolute","tolerance",".","If","specified","``","rtol","``","must","also","be","specified",".","If","omitted",",","default","values","based","on","the","type","are","selected",".","See",":","func",":","assert_close",":","for","details",".","equal_nan","(","bool",")",":","If","``","True","``",",","two","``","NaN","``","values","are","considered","equal",".","Defaults","to","``","False","``",".","check_device","(","bool",")",":","If","``","True","``","(","default",")",",","asserts","that","corresponding","tensors","are","on","the","same",":","attr",":","`","~torch.Tensor.device","`",".","If","this","check","is","disabled",",","tensors","on","different",":","attr",":","`","~torch.Tensor.device","`","'s","are","moved","to","the","CPU","before","being","compared",".","check_dtype","(","bool",")",":","If","``","True","``","(","default",")",",","asserts","that","corresponding","tensors","have","the","same","``","dtype","``",".","If","this","check","is","disabled",",","tensors","with","different","``","dtype","``","'s","are","promoted","to","a","common","``","dtype","``","(","according","to",":","func",":","`","torch.promote_types","`",")","before","being","compared",".","check_layout","(","bool",")",":","If","``","True","``","(","default",")",",","asserts","that","corresponding","tensors","have","the","same","``","layout","``",".","If","this","check","is","disabled",",","tensors","with","different","``","layout","``","'s","are","converted","to","strided","tensors","before","being","compared",".","check_stride","(","bool",")",":","If","``","True","``","and","corresponding","tensors","are","strided",",","asserts","that","they","have","the","same","stride","."]
docstr: Compares sparse compressed tensors by comparing
  
  - the number of non-zero elements (nnz) for equality,
  - the plain indices for equality,
  - the compressed indices for equality, and
  - the values for closeness.
docstr_tok: ["Compares","sparse","compressed","tensors","by","comparing","-","the","number","of","non-zero","elements","(","nnz",")","for","equality",",","-","the","plain","indices","for","equality",",","-","the","compressed","indices","for","equality",",","and","-","the","values","for","closeness","."]
code: def _compare_sparse_compressed_values(
      self,
      actual: torch.Tensor,
      expected: torch.Tensor,
      *,
      rtol: float,
      atol: float,
      equal_nan: bool,
  ) -> None:
      """Compares sparse compressed tensors by comparing
  
      - the number of non-zero elements (nnz) for equality,
      - the plain indices for equality,
      - the compressed indices for equality, and
      - the values for closeness.
      """
      format_name, compressed_indices_method, plain_indices_method = {
          torch.sparse_csr: (
              "CSR",
              torch.Tensor.crow_indices,
              torch.Tensor.col_indices,
          ),
          torch.sparse_csc: (
              "CSC",
              torch.Tensor.ccol_indices,
              torch.Tensor.row_indices,
          ),
          torch.sparse_bsr: (
              "BSR",
              torch.Tensor.crow_indices,
              torch.Tensor.col_indices,
          ),
          torch.sparse_bsc: (
              "BSC",
              torch.Tensor.ccol_indices,
              torch.Tensor.row_indices,
          ),
      }[actual.layout]
  
      if actual._nnz() != expected._nnz():
          self._fail(
              AssertionError,
              (
                  f"The number of specified values in sparse {format_name} tensors does not match: "
                  f"{actual._nnz()} != {expected._nnz()}"
              ),
          )
  
      # Compressed and plain indices in the CSR / CSC / BSR / BSC sparse formates can be `torch.int32` _or_
      # `torch.int64`. While the same dtype is enforced for the compressed and plain indices of a single tensor, it
      # can be different between two tensors. Thus, we need to convert them to the same dtype, or the comparison will
      # fail.
      actual_compressed_indices = compressed_indices_method(actual)
      expected_compressed_indices = compressed_indices_method(expected)
      indices_dtype = torch.promote_types(
          actual_compressed_indices.dtype,
          expected_compressed_indices.dtype,
      )
  
      self._compare_regular_values_equal(
          actual_compressed_indices.to(indices_dtype),
          expected_compressed_indices.to(indices_dtype),
          identifier=f"Sparse {format_name} {compressed_indices_method.__name__}",
      )
      self._compare_regular_values_equal(
          plain_indices_method(actual).to(indices_dtype),
          plain_indices_method(expected).to(indices_dtype),
          identifier=f"Sparse {format_name} {plain_indices_method.__name__}",
      )
      self._compare_regular_values_close(
          actual.values(),
          expected.values(),
          rtol=rtol,
          atol=atol,
          equal_nan=equal_nan,
          identifier=f"Sparse {format_name} values",
      )
  
imports: import abc
  import cmath
  import collections.abc
  import contextlib
  import warnings
  from typing import Any, Callable, Collection, Dict, List, NoReturn, Optional, Sequence, Tuple, Type, Union
  import torch
label_desc: Use image node_id 11 for calling the TensorLikePair obj's underlying member method code with example usage: obj._compare_sparse_compressed_values(actual, expected) without return types