Shortcuts

IValue

public class IValue

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 toString().

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

Methods

dictLongKeyFrom

public static IValue dictLongKeyFrom(Map<Long, IValue> map)

Creates a new IValue of type Dict[int, V].

dictStringKeyFrom

public static IValue dictStringKeyFrom(Map<String, IValue> map)

Creates a new IValue of type Dict[str, V].

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.

isBool

public boolean isBool()

isBoolList

public boolean isBoolList()

isDictLongKey

public boolean isDictLongKey()

isDictStringKey

public boolean isDictStringKey()

isDouble

public boolean isDouble()

isDoubleList

public boolean isDoubleList()

isList

public boolean isList()

isLong

public boolean isLong()

isLongList

public boolean isLongList()

isNull

public boolean isNull()

isString

public boolean isString()

isTensor

public boolean isTensor()

isTensorList

public boolean isTensorList()

isTuple

public boolean isTuple()

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.

optionalNull

public static IValue optionalNull()

Creates a new IValue of type Optional that contains no value.

toBool

public boolean toBool()

toBoolList

public boolean[] toBoolList()

toDictLongKey

public Map<Long, IValue> toDictLongKey()

toDictStringKey

public Map<String, IValue> toDictStringKey()

toDouble

public double toDouble()

toDoubleList

public double[] toDoubleList()

toList

public IValue[] toList()

toLong

public long toLong()

toLongList

public long[] toLongList()

toStr

public String toStr()

toTensor

public Tensor toTensor()

toTensorList

public Tensor[] toTensorList()

toTuple

public IValue[] toTuple()

tupleFrom

public static IValue tupleFrom(IValue... array)

Creates a new IValue of type Tuple[T0, T1, ...].

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources