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 IValue
dictLongKeyFrom(java.util.Map<java.lang.Long,IValue> map)
Creates a newIValue
of typeDict[int, V]
.static IValue
dictStringKeyFrom(java.util.Map<java.lang.String,IValue> map)
Creates a newIValue
of typeDict[str, V]
.static IValue
from(boolean value)
Creates a newIValue
of typebool
.static IValue
from(double value)
Creates a newIValue
of typefloat
.static IValue
from(long value)
Creates a newIValue
of typeint
.static IValue
from(java.lang.String value)
Creates a newIValue
of typestr
.static IValue
from(Tensor tensor)
Creates a newIValue
of typeTensor
.boolean
isBool()
boolean
isBoolList()
boolean
isDictLongKey()
boolean
isDictStringKey()
boolean
isDouble()
boolean
isDoubleList()
boolean
isList()
boolean
isLong()
boolean
isLongList()
boolean
isNull()
boolean
isString()
boolean
isTensor()
boolean
isTensorList()
boolean
isTuple()
static IValue
listFrom(boolean... list)
Creates a newIValue
of typeList[bool]
.static IValue
listFrom(double... list)
Creates a newIValue
of typeList[float]
.static IValue
listFrom(long... list)
Creates a newIValue
of typeList[int]
.static IValue
listFrom(IValue... array)
Creates a newIValue
of typeList[T]
.static IValue
listFrom(Tensor... list)
Creates a newIValue
of typeList[Tensor]
.static IValue
optionalNull()
Creates a newIValue
of typeOptional
that contains no value.boolean
toBool()
boolean[]
toBoolList()
java.util.Map<java.lang.Long,IValue>
toDictLongKey()
java.util.Map<java.lang.String,IValue>
toDictStringKey()
double
toDouble()
double[]
toDoubleList()
IValue[]
toList()
long
toLong()
long[]
toLongList()
java.lang.String
toStr()
Tensor
toTensor()
Tensor[]
toTensorList()
IValue[]
toTuple()
static IValue
tupleFrom(IValue... array)
Creates a newIValue
of 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 newIValue
of typeOptional
that contains no value. -
from
Creates a newIValue
of typeTensor
. -
from
Creates a newIValue
of typebool
. -
from
Creates a newIValue
of typeint
. -
from
Creates a newIValue
of typefloat
. -
from
Creates a newIValue
of typestr
. -
listFrom
Creates a newIValue
of typeList[bool]
. -
listFrom
Creates a newIValue
of typeList[int]
. -
listFrom
Creates a newIValue
of typeList[float]
. -
listFrom
Creates a newIValue
of typeList[Tensor]
. -
listFrom
Creates a newIValue
of typeList[T]
. All elements must have the same type. -
tupleFrom
Creates a newIValue
of typeTuple[T0, T1, ...]
. -
dictStringKeyFrom
Creates a newIValue
of typeDict[str, V]
. -
dictLongKeyFrom
Creates a newIValue
of 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
-