dgl.sparse.DiagMatrix.to

DiagMatrix.to(device=None, dtype=None)[source]

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

The converted matrix

Return type

DiagMatrix

Examples

>>> val = torch.ones(2)
>>> D = dglsp.diag(val)
>>> D.to(device="cuda:0", dtype=torch.int32)
DiagMatrix(values=tensor([1, 1], device='cuda:0', dtype=torch.int32),
           shape=(2, 2))