Package org.pytorch
Class IValue
- java.lang.Object
-
- org.pytorch.IValue
-
public class IValue extends java.lang.ObjectJava 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
toXmethods for inappropriate types will throwIllegalStateException.IValueobjects are constructed withIValue.from(value),IValue.tupleFrom(value1, value2, ...),IValue.listFrom(value1, value2, ...), or one of thedictmethods, depending on the key type.Data is retrieved from
IValueobjects with thetoX()methods. Note thatstr-type IValues must be extracted withtoStr(), rather thanObject.toString().IValueobjects 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 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 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 newIValueof typeOptionalthat contains no value.
-
from
public static IValue from(boolean value)
Creates a newIValueof typebool.
-
from
public static IValue from(long value)
Creates a newIValueof typeint.
-
from
public static IValue from(double value)
Creates a newIValueof typefloat.
-
from
public static IValue from(java.lang.String value)
Creates a newIValueof typestr.
-
listFrom
public static IValue listFrom(boolean... list)
Creates a newIValueof typeList[bool].
-
listFrom
public static IValue listFrom(long... list)
Creates a newIValueof typeList[int].
-
listFrom
public static IValue listFrom(double... list)
Creates a newIValueof typeList[float].
-
listFrom
public static IValue listFrom(IValue... array)
Creates a newIValueof typeList[T]. All elements must have the same type.
-
tupleFrom
public static IValue tupleFrom(IValue... array)
Creates a newIValueof typeTuple[T0, T1, ...].
-
dictStringKeyFrom
public static IValue dictStringKeyFrom(java.util.Map<java.lang.String,IValue> map)
Creates a newIValueof typeDict[str, V].
-
dictLongKeyFrom
public static IValue dictLongKeyFrom(java.util.Map<java.lang.Long,IValue> map)
Creates a newIValueof typeDict[int, V].
-
toTensor
public Tensor 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
public Tensor[] toTensorList()
-
toList
public IValue[] toList()
-
toTuple
public IValue[] toTuple()
-
toDictStringKey
public java.util.Map<java.lang.String,IValue> toDictStringKey()
-
toDictLongKey
public java.util.Map<java.lang.Long,IValue> toDictLongKey()
-
-