Rate this Page

torch.hash_tensor#

torch.hash_tensor(input,*,mode=0)Tensor#

Returns a hash of all elements in theinput tensor.

Currently only mode=0 (reduction via xor) is supported. The output will alwaysbe of typetorch.uint64. The elements ofinput are upcasted to their64 bit float / integer equivalent and bitcasted totorch.uint64 beforereduction via xor.

Parameters

input (Tensor) – the input tensor.

Keyword Arguments

mode (int) – The hash to use. Default: 0 (xor_reduction)

Example:

>>>a=torch.randn(1,3)>>>atensor([[ 1.1918, -1.1813,  0.3373]])>>>torch.hash_tensor(a)tensor(13822780554648485888, dtype=torch.uint64)
torch.hash_tensor(input,dim,*,keepdim=False,mode=0)Tensor

Returns the hash of each row of theinput tensor in the givendimensiondim given by mode. Ifdim is a list of dimensions,reduce over all of them.

Ifkeepdim isTrue, the output tensor is of the same sizeasinput except in the dimension(s)dim where it is of size 1.Otherwise,dim is squeezed (seetorch.squeeze()), resulting in theoutput tensor having 1 (orlen(dim)) fewer dimension(s).

Parameters
  • input (Tensor) – the input tensor.

  • dim (int ortuple ofints,optional) – the dimension or dimensions to reduce.IfNone, all dimensions are reduced.

  • keepdim (bool,optional) – whether the output tensor hasdim retained or not. Default:False.

Keyword Arguments

mode (int) – The hash to use. Default: 0 (xor_reduction)

Example:

>>>a=torch.randn(2,4)>>>atensor([[ 0.1317, -0.5554, -1.4724, -1.1391],        [ 0.0778, -0.6070,  0.6375,  0.1798]])>>>torch.hash_tensor(a,1)tensor([9233691267014066176, 9255993250844508160], dtype=torch.uint64)