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 Summary
Modifier and Type Method Description static IValuedictLongKeyFrom(java.util.Map<java.lang.Long,IValue> map)Creates a newIValueof typeDict[int, V].static IValuedictStringKeyFrom(java.util.Map<java.lang.String,IValue> map)Creates a newIValueof typeDict[str, V].static IValuefrom(boolean value)Creates a newIValueof typebool.static IValuefrom(double value)Creates a newIValueof typefloat.static IValuefrom(long value)Creates a newIValueof typeint.static IValuefrom(java.lang.String value)Creates a newIValueof typestr.static IValuefrom(Tensor tensor)Creates a newIValueof typeTensor.booleanisBool()booleanisBoolList()booleanisDictLongKey()booleanisDictStringKey()booleanisDouble()booleanisDoubleList()booleanisList()booleanisLong()booleanisLongList()booleanisNull()booleanisString()booleanisTensor()booleanisTensorList()booleanisTuple()static IValuelistFrom(boolean... list)Creates a newIValueof typeList[bool].static IValuelistFrom(double... list)Creates a newIValueof typeList[float].static IValuelistFrom(long... list)Creates a newIValueof typeList[int].static IValuelistFrom(IValue... array)Creates a newIValueof typeList[T].static IValuelistFrom(Tensor... list)Creates a newIValueof typeList[Tensor].static IValueoptionalNull()Creates a newIValueof typeOptionalthat contains no value.booleantoBool()boolean[]toBoolList()java.util.Map<java.lang.Long,IValue>toDictLongKey()java.util.Map<java.lang.String,IValue>toDictStringKey()doubletoDouble()double[]toDoubleList()IValue[]toList()longtoLong()long[]toLongList()java.lang.StringtoStr()TensortoTensor()Tensor[]toTensorList()IValue[]toTuple()static IValuetupleFrom(IValue... array)Creates a newIValueof typeTuple[T0, T1, ...].
-
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
Creates a newIValueof typeOptionalthat contains no value. -
from
Creates a newIValueof typeTensor. -
from
Creates a newIValueof typebool. -
from
Creates a newIValueof typeint. -
from
Creates a newIValueof typefloat. -
from
Creates a newIValueof typestr. -
listFrom
Creates a newIValueof typeList[bool]. -
listFrom
Creates a newIValueof typeList[int]. -
listFrom
Creates a newIValueof typeList[float]. -
listFrom
Creates a newIValueof typeList[Tensor]. -
listFrom
Creates a newIValueof typeList[T]. All elements must have the same type. -
tupleFrom
Creates a newIValueof typeTuple[T0, T1, ...]. -
dictStringKeyFrom
Creates a newIValueof typeDict[str, V]. -
dictLongKeyFrom
Creates a newIValueof typeDict[int, V]. -
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
-
toList
-
toTuple
-
toDictStringKey
-
toDictLongKey
-