Package ai.djl.pytorch.jni
Class IValue
- java.lang.Object
-
- ai.djl.util.NativeResource<java.lang.Long>
-
- ai.djl.pytorch.jni.IValue
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class IValue extends ai.djl.util.NativeResource<java.lang.Long>A class represent a PyTorchIValuedata.DJL doesn't support creating nested IValue.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static IValuefrom(boolean value)Creates a newIValueof typeboolean.static IValuefrom(double value)Creates a newIValueof typedouble.static IValuefrom(long value)Creates a newIValueof typelong.static IValuefrom(PtNDArray array)Creates a newIValueof typePtNDArray.static IValuefrom(java.lang.String value)Creates a newIValueof typeString.java.lang.StringgetType()Returns the type of the IValue.booleanisBoolean()Returns if the IValue is abooleantype.booleanisBooleanList()Returns if the IValue is aboolean[]type.booleanisDouble()Returns if the IValue is adoubletype.booleanisDoubleList()Returns if the IValue is adouble[]type.booleanisList()Returns if the IValue is aIValue[]type.booleanisLong()Returns if the IValue is alongtype.booleanisLongList()Returns if the IValue is along[]type.booleanisMap()Returns if the IValue is aMap<String, V>type.booleanisString()Returns if the IValue is aStringtype.booleanisTensor()Returns if the IValue is aTensortype.booleanisTensorList()Returns if the IValue is aIValue[]type.booleanisTuple()Returns if the IValue is a tuple type.static IValuelistFrom(boolean... list)Creates a newIValueof typeboolean[].static IValuelistFrom(double... list)Creates a newIValueof typedouble[].static IValuelistFrom(long... list)Creates a newIValueof typelong[].static IValuelistFrom(PtNDArray... list)Creates a newIValueof typeNDArray[].static IValuelistFrom(IValue... list)Creates a newIValueof typeNDArray[].static IValuestringIValueMapFrom(java.util.Map<java.lang.String,IValue> map)Creates a newIValueof typeMap[String, IValue].static IValuestringMapFrom(java.util.Map<java.lang.String,PtNDArray> map)Creates a newIValueof typeMap[String, PtNDArray].booleantoBoolean()Returns thebooleanvalue of this IValue.boolean[]toBooleanArray()Returns theboolean[]value of this IValue.doubletoDouble()Returns thedoublevalue of this IValue.double[]toDoubleArray()Returns thedouble[]value of this IValue.IValue[]toIValueArray()Returns theIValue[]value of this IValue list.java.util.Map<java.lang.String,IValue>toIValueMap()Returns theMap<String, IValue>value of this IValue.IValue[]toIValueTuple()Returns theMap<String, IValue>value of this IValue.longtoLong()Returns thelongvalue of this IValue.long[]toLongArray()Returns thelong[]value of this IValue.ai.djl.ndarray.NDListtoNDList(PtNDManager manager)Returns theNDListvalue of this IValue.java.lang.StringtoStringValue()Returns theStringvalue of this IValue.PtNDArraytoTensor(PtNDManager manager)Returns theNDArrayvalue of this IValue.PtNDArray[]toTensorArray(PtNDManager manager)Returns theNDArray[]value of this IValue.static IValuetupleFrom(IValue... list)Creates a newIValueof typeNDArray[].
-
-
-
Method Detail
-
getType
public java.lang.String getType()
Returns the type of the IValue.- Returns:
- the type of the IValue
-
isTensor
public boolean isTensor()
Returns if the IValue is aTensortype.- Returns:
- if the IValue is a Tensor type
-
isBoolean
public boolean isBoolean()
Returns if the IValue is abooleantype.- Returns:
- if the IValue is a boolean type
-
isLong
public boolean isLong()
Returns if the IValue is alongtype.- Returns:
- if the IValue is a long type
-
isDouble
public boolean isDouble()
Returns if the IValue is adoubletype.- Returns:
- if the IValue is a double type
-
isString
public boolean isString()
Returns if the IValue is aStringtype.- Returns:
- if the IValue is a String type
-
isBooleanList
public boolean isBooleanList()
Returns if the IValue is aboolean[]type.- Returns:
- if the IValue is a boolean[] type
-
isLongList
public boolean isLongList()
Returns if the IValue is along[]type.- Returns:
- if the IValue is a long[] type
-
isDoubleList
public boolean isDoubleList()
Returns if the IValue is adouble[]type.- Returns:
- if the IValue is a double[] type
-
isTensorList
public boolean isTensorList()
Returns if the IValue is aIValue[]type.The elements in the array must have the same type.
- Returns:
- if the IValue is a IValue[] type
-
isList
public boolean isList()
Returns if the IValue is aIValue[]type.The elements in the array must have the same type.
- Returns:
- if the IValue is a IValue[] type
-
isMap
public boolean isMap()
Returns if the IValue is aMap<String, V>type.- Returns:
- if the IValue is a Map<String, V> type
-
isTuple
public boolean isTuple()
Returns if the IValue is a tuple type.- Returns:
- if the IValue is a tuple type
-
from
public static IValue from(PtNDArray array)
Creates a newIValueof typePtNDArray.- Parameters:
array- the NDArray- Returns:
- a new
IValueof typePtNDArray
-
from
public static IValue from(boolean value)
Creates a newIValueof typeboolean.- Parameters:
value- the boolean value- Returns:
- a new
IValueof typeboolean
-
from
public static IValue from(long value)
Creates a newIValueof typelong.- Parameters:
value- the long value- Returns:
- a new
IValueof typelong
-
from
public static IValue from(double value)
Creates a newIValueof typedouble.- Parameters:
value- the double value- Returns:
- a new
IValueof typedouble
-
from
public static IValue from(java.lang.String value)
Creates a newIValueof typeString.- Parameters:
value- the String value- Returns:
- a new
IValueof typeString
-
listFrom
public static IValue listFrom(boolean... list)
Creates a newIValueof typeboolean[].- Parameters:
list- the boolean[] value- Returns:
- a new
IValueof typeboolean[]
-
listFrom
public static IValue listFrom(long... list)
Creates a newIValueof typelong[].- Parameters:
list- the long[] value- Returns:
- a new
IValueof typelong[]
-
listFrom
public static IValue listFrom(double... list)
Creates a newIValueof typedouble[].- Parameters:
list- the double[] value- Returns:
- a new
IValueof typedouble[]
-
listFrom
public static IValue listFrom(PtNDArray... list)
Creates a newIValueof typeNDArray[].- Parameters:
list- the NDArray[] value- Returns:
- a new
IValueof typeNDArray[]
-
listFrom
public static IValue listFrom(IValue... list)
Creates a newIValueof typeNDArray[].- Parameters:
list- the NDArray[] value- Returns:
- a new
IValueof typeNDArray[]
-
tupleFrom
public static IValue tupleFrom(IValue... list)
Creates a newIValueof typeNDArray[].- Parameters:
list- the NDArray[] value- Returns:
- a new
IValueof typeNDArray[]
-
stringMapFrom
public static IValue stringMapFrom(java.util.Map<java.lang.String,PtNDArray> map)
Creates a newIValueof typeMap[String, PtNDArray].- Parameters:
map- the Map[String, IValue] value- Returns:
- a new
IValueof typeMap[String, PtNDArray]
-
stringIValueMapFrom
public static IValue stringIValueMapFrom(java.util.Map<java.lang.String,IValue> map)
Creates a newIValueof typeMap[String, IValue].- Parameters:
map- the Map[String, IValue] value- Returns:
- a new
IValueof typeMap[String, IValue]
-
toBoolean
public boolean toBoolean()
Returns thebooleanvalue of this IValue.- Returns:
- the boolean value of this IValue
-
toLong
public long toLong()
Returns thelongvalue of this IValue.- Returns:
- the long value of this IValue
-
toDouble
public double toDouble()
Returns thedoublevalue of this IValue.- Returns:
- the double value of this IValue
-
toStringValue
public java.lang.String toStringValue()
Returns theStringvalue of this IValue.- Returns:
- the String value of this IValue
-
toBooleanArray
public boolean[] toBooleanArray()
Returns theboolean[]value of this IValue.- Returns:
- the boolean[] value of this IValue
-
toLongArray
public long[] toLongArray()
Returns thelong[]value of this IValue.- Returns:
- the long[] value of this IValue
-
toDoubleArray
public double[] toDoubleArray()
Returns thedouble[]value of this IValue.- Returns:
- the double[] value of this IValue
-
toTensor
public PtNDArray toTensor(PtNDManager manager)
Returns theNDArrayvalue of this IValue.- Parameters:
manager- theNDManagerto create the NDArray- Returns:
- the NDArray value of this IValue
-
toTensorArray
public PtNDArray[] toTensorArray(PtNDManager manager)
Returns theNDArray[]value of this IValue.- Parameters:
manager- the NDManager to create NDArray- Returns:
- the NDArray[] value of this IValue
-
toIValueArray
public IValue[] toIValueArray()
Returns theIValue[]value of this IValue list.- Returns:
- the IValue[] value of this IValue list
-
toIValueMap
public java.util.Map<java.lang.String,IValue> toIValueMap()
Returns theMap<String, IValue>value of this IValue.- Returns:
- the Map<String, IValue> value of this IValue
-
toIValueTuple
public IValue[] toIValueTuple()
Returns theMap<String, IValue>value of this IValue.- Returns:
- the Map<String, IValue> value of this IValue
-
toNDList
public ai.djl.ndarray.NDList toNDList(PtNDManager manager)
Returns theNDListvalue of this IValue.- Parameters:
manager- the NDManager to create NDArray- Returns:
- the
NDListvalue of this IValue
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Overrides:
closein classai.djl.util.NativeResource<java.lang.Long>
-
-