Rate this Page

torch.isclose#

torch.isclose(input,other,rtol=1e-05,atol=1e-08,equal_nan=False)Tensor#

Returns a new tensor with boolean elements representing if each element ofinput is “close” to the corresponding element ofother.Closeness is defined as:

inputiotherirtol×otheri+atol\lvert \text{input}_i - \text{other}_i \rvert \leq \texttt{rtol} \times \lvert \text{other}_i \rvert + \texttt{atol}

whereinput andother are finite. Whereinputand/orother are nonfinite they are close if and only ifthey are equal, with NaNs being considered equal to each other whenequal_nan is True.

Parameters
  • input (Tensor) – first tensor to compare

  • other (Tensor) – second tensor to compare

  • rtol (float,optional) – relative tolerance. Default: 1e-05

  • atol (float,optional) – absolute tolerance. Default: 1e-08

  • equal_nan (bool,optional) – ifTrue, then twoNaN s will be considered equal. Default:False

Examples:

>>>torch.isclose(torch.tensor((1.,2,3)),torch.tensor((1+1e-10,3,4)))tensor([ True, False, False])>>>torch.isclose(torch.tensor((float('inf'),4)),torch.tensor((float('inf'),6)),rtol=.5)tensor([True, True])