jina.types.ndarray.sparse.pytorch module

class jina.types.ndarray.sparse.pytorch.SparseNdArray(proto=None, transpose_indices=True, *args, **kwargs)[source]

Bases: jina.types.ndarray.sparse.BaseSparseNdArray

Pytorch powered sparse ndarray, i.e. FloatTensor.

Parameters
  • proto (Optional[SparseNdArrayProto]) – protobuf instance, default is None.

  • transpose_indices (bool) – in torch, the input to LongTensor is NOT a list of index tuples.

  • args – positional arguments.

  • kwargs – positional key value arguments.

If you want to write your indices this way, you should transpose before passing them to the sparse constructor

Note

To comply with Tensorflow, transpose_indices is set to True by default

Set constructor method.

Parameters
  • args – args passed to super().

  • kwargs – kwargs passed to super().

sparse_constructor(indices, values, shape)[source]

Sparse NdArray constructor for FloatTensor.

Parameters
  • indices (ndarray) – the indices of the sparse array

  • values (ndarray) – the values of the sparse array

  • shape (List[int]) – the shape of the sparse array

Return type

FloatTensor

Returns

FloatTensor

sparse_parser(value)[source]

Parse a FloatTensor to indices, values and shape.

Parameters

value (FloatTensor) – the FloatTensor.

Returns

a Dict with three entries {‘indices’: …, ‘values’:…, ‘shape’:…}