Package org.pytorch

Class IValue


  • public class IValue
    extends 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 Detail

      • 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​(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​(Map<String,​IValue> map)
        Creates a new IValue of type Dict[str, V].
      • dictLongKeyFrom

        public static IValue dictLongKeyFrom​(Map<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 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()