Package org.pytorch

Class IValue

java.lang.Object
org.pytorch.IValue

public class IValue
extends java.lang.Object
Java representation of a TorchScript value, which is implemented as tagged union that can be one of the supported types: https://pytorch.org/docs/stable/jit.html#types .

Calling toX methods for inappropriate types will throw IllegalStateException.

IValue objects are constructed with IValue.from(value), IValue.tupleFrom(value1, value2, ...), IValue.listFrom(value1, value2, ...), or one of the dict methods, depending on the key type.

Data is retrieved from IValue objects with the toX() methods. Note that str-type IValues must be extracted with toStr(), rather than Object.toString().

IValue objects may retain references to objects passed into their constructors, and may return references to their internal state from toX().

  • Method Details

    • isNull

      public boolean isNull()
    • isTensor

      public boolean isTensor()
    • isBool

      public boolean isBool()
    • isLong

      public boolean isLong()
    • isDouble

      public boolean isDouble()
    • isString

      public boolean isString()
    • isTuple

      public boolean isTuple()
    • isBoolList

      public boolean isBoolList()
    • isLongList

      public boolean isLongList()
    • isDoubleList

      public boolean isDoubleList()
    • isTensorList

      public boolean isTensorList()
    • isList

      public boolean isList()
    • isDictStringKey

      public boolean isDictStringKey()
    • isDictLongKey

      public boolean isDictLongKey()
    • optionalNull

      public static IValue optionalNull()
      Creates a new IValue of type Optional that contains no value.
    • from

      public static IValue from​(Tensor tensor)
      Creates a new IValue of type Tensor.
    • from

      public static IValue from​(boolean value)
      Creates a new IValue of type bool.
    • from

      public static IValue from​(long value)
      Creates a new IValue of type int.
    • from

      public static IValue from​(double value)
      Creates a new IValue of type float.
    • from

      public static IValue from​(java.lang.String value)
      Creates a new IValue of type str.
    • listFrom

      public static IValue listFrom​(boolean... list)
      Creates a new IValue of type List[bool].
    • listFrom

      public static IValue listFrom​(long... list)
      Creates a new IValue of type List[int].
    • listFrom

      public static IValue listFrom​(double... list)
      Creates a new IValue of type List[float].
    • listFrom

      public static IValue listFrom​(Tensor... list)
      Creates a new IValue of type List[Tensor].
    • listFrom

      public static IValue listFrom​(IValue... array)
      Creates a new IValue of type List[T]. All elements must have the same type.
    • tupleFrom

      public static IValue tupleFrom​(IValue... array)
      Creates a new IValue of type Tuple[T0, T1, ...].
    • dictStringKeyFrom

      public static IValue dictStringKeyFrom​(java.util.Map<java.lang.String,​IValue> map)
      Creates a new IValue of type Dict[str, V].
    • dictLongKeyFrom

      public static IValue dictLongKeyFrom​(java.util.Map<java.lang.Long,​IValue> map)
      Creates a new IValue of type Dict[int, V].
    • toTensor

      public Tensor toTensor()
    • toBool

      public boolean toBool()
    • toLong

      public long toLong()
    • toDouble

      public double toDouble()
    • toStr

      public java.lang.String toStr()
    • toBoolList

      public boolean[] toBoolList()
    • toLongList

      public long[] toLongList()
    • toDoubleList

      public double[] toDoubleList()
    • toTensorList

      public Tensor[] toTensorList()
    • toList

      public IValue[] toList()
    • toTuple

      public IValue[] toTuple()
    • toDictStringKey

      public java.util.Map<java.lang.String,​IValue> toDictStringKey()
    • toDictLongKey

      public java.util.Map<java.lang.Long,​IValue> toDictLongKey()