class_docstr: Class for sparse matrix.
class_docstr_tok: ["Class","for","sparse","matrix","."]
docstr: Performs matrix dtype and/or device conversion. If the target device
  and dtype are already in use, the original matrix will be returned.
  
  Parameters
  ----------
  device : torch.device, optional
      The target device of the matrix if provided, otherwise the current
      device will be used
  dtype : torch.dtype, optional
      The target data type of the matrix values if provided, otherwise the
      current data type will be used
  
  Returns
  -------
  SparseMatrix
      The converted matrix
  
  Examples
  --------
  
  >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
  >>> A = dglsp.spmatrix(indices, shape=(3, 4))
  >>> A.to(device="cuda:0", dtype=torch.int32)
  SparseMatrix(indices=tensor([[1, 1, 2],
                               [1, 2, 0]], device='cuda:0'),
               values=tensor([1, 1, 1], device='cuda:0',
                             dtype=torch.int32),
               shape=(3, 4), nnz=3)
docstr_tok: ["Performs","matrix","dtype","and\/or","device","conversion",".","If","the","target","device","and","dtype","are","already","in","use",",","the","original","matrix","will","be","returned",".","Parameters","--","--","--","--","--","device",":","torch.device",",","optional","The","target","device","of","the","matrix","if","provided",",","otherwise","the","current","device","will","be","used","dtype",":","torch.dtype",",","optional","The","target","data","type","of","the","matrix","values","if","provided",",","otherwise","the","current","data","type","will","be","used","Returns","--","--","--","-","SparseMatrix","The","converted","matrix","Examples","--","--","--","--",">",">",">","indices","=","torch.tensor","(","[","[","1",",","1",",","2","]",",","[","1",",","2",",","0","]","]",")",">",">",">","A","=","dglsp.spmatrix","(","indices",",","shape=","(","3",",","4",")",")",">",">",">","A.to","(","device=","''","cuda:0","''",",","dtype=torch.int32",")","SparseMatrix","(","indices=tensor","(","[","[","1",",","1",",","2","]",",","[","1",",","2",",","0","]","]",",","device='cuda:0","'",")",",","values=tensor","(","[","1",",","1",",","1","]",",","device='cuda:0","'",",","dtype=torch.int32",")",",","shape=","(","3",",","4",")",",","nnz=3",")"]
code: def to(self, device=None, dtype=None):
      """Performs matrix dtype and/or device conversion. If the target device
      and dtype are already in use, the original matrix will be returned.
  
      Parameters
      ----------
      device : torch.device, optional
          The target device of the matrix if provided, otherwise the current
          device will be used
      dtype : torch.dtype, optional
          The target data type of the matrix values if provided, otherwise the
          current data type will be used
  
      Returns
      -------
      SparseMatrix
          The converted matrix
  
      Examples
      --------
  
      >>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]])
      >>> A = dglsp.spmatrix(indices, shape=(3, 4))
      >>> A.to(device="cuda:0", dtype=torch.int32)
      SparseMatrix(indices=tensor([[1, 1, 2],
                                   [1, 2, 0]], device='cuda:0'),
                   values=tensor([1, 1, 1], device='cuda:0',
                                 dtype=torch.int32),
                   shape=(3, 4), nnz=3)
      """
      if device is None:
          device = self.device
      if dtype is None:
          dtype = self.dtype
  
      if device == self.device and dtype == self.dtype:
          return self
      elif device == self.device:
          return val_like(self, self.val.to(dtype=dtype))
      else:
          # TODO(#5119): Find a better moving strategy instead of always
          # convert to COO format.
          row, col = self.coo()
          row = row.to(device=device)
          col = col.to(device=device)
          val = self.val.to(device=device, dtype=dtype)
          return from_coo(row, col, val, self.shape)
  
imports: from typing import Optional, Tuple
  import torch
label_desc: Use image node_id 18 for calling the SparseMatrix obj's underlying member method code with example usage: obj.to(device, dtype) and returns: self, val_like, from_coo