Package org.pytorch
Class IValue
- java.lang.Object
-
- org.pytorch.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 throwIllegalStateException
.IValue
objects are constructed withIValue.from(value)
,IValue.tupleFrom(value1, value2, ...)
,IValue.listFrom(value1, value2, ...)
, or one of thedict
methods, depending on the key type.Data is retrieved from
IValue
objects with thetoX()
methods. Note thatstr
-type IValues must be extracted withtoStr()
, rather thanObject.toString()
.IValue
objects may retain references to objects passed into their constructors, and may return references to their internal state fromtoX()
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IValue
dictLongKeyFrom(Map<Long,IValue> map)
Creates a newIValue
of typeDict[int, V]
.static IValue
dictStringKeyFrom(Map<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(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()
Map<Long,IValue>
toDictLongKey()
Map<String,IValue>
toDictStringKey()
double
toDouble()
double[]
toDoubleList()
IValue[]
toList()
long
toLong()
long[]
toLongList()
String
toStr()
Tensor
toTensor()
Tensor[]
toTensorList()
IValue[]
toTuple()
static IValue
tupleFrom(IValue... array)
Creates a newIValue
of typeTuple[T0, T1, ...]
.
-
-
-
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 newIValue
of typeOptional
that contains no value.
-
from
public static IValue from(boolean value)
Creates a newIValue
of typebool
.
-
from
public static IValue from(long value)
Creates a newIValue
of typeint
.
-
from
public static IValue from(double value)
Creates a newIValue
of typefloat
.
-
listFrom
public static IValue listFrom(boolean... list)
Creates a newIValue
of typeList[bool]
.
-
listFrom
public static IValue listFrom(long... list)
Creates a newIValue
of typeList[int]
.
-
listFrom
public static IValue listFrom(double... list)
Creates a newIValue
of typeList[float]
.
-
listFrom
public static IValue listFrom(IValue... array)
Creates a newIValue
of typeList[T]
. All elements must have the same type.
-
tupleFrom
public static IValue tupleFrom(IValue... array)
Creates a newIValue
of typeTuple[T0, T1, ...]
.
-
dictStringKeyFrom
public static IValue dictStringKeyFrom(Map<String,IValue> map)
Creates a newIValue
of typeDict[str, V]
.
-
dictLongKeyFrom
public static IValue dictLongKeyFrom(Map<Long,IValue> map)
Creates a newIValue
of typeDict[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()
-
-