Package ai.djl.pytorch.jni
Class IValue
java.lang.Object
ai.djl.util.NativeResource<Long>
ai.djl.pytorch.jni.IValue
- All Implemented Interfaces:
AutoCloseable
A class represent a PyTorch
IValue
data.
DJL doesn't support creating nested IValue.
-
Field Summary
Fields inherited from class ai.djl.util.NativeResource
handle
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static IValue
from
(boolean value) Creates a newIValue
of typeboolean
.static IValue
from
(double value) Creates a newIValue
of typedouble
.static IValue
from
(long value) Creates a newIValue
of typelong
.static IValue
Creates a newIValue
of typePtNDArray
.static IValue
Creates a newIValue
of typeString
.getType()
Returns the type of the IValue.boolean
Returns if the IValue is aboolean
type.boolean
Returns if the IValue is aboolean[]
type.boolean
isDouble()
Returns if the IValue is adouble
type.boolean
Returns if the IValue is adouble[]
type.boolean
isList()
Returns if the IValue is aIValue[]
type.boolean
isLong()
Returns if the IValue is along
type.boolean
Returns if the IValue is along[]
type.boolean
isMap()
Returns if the IValue is aMap<String, V>
type.boolean
isString()
Returns if the IValue is aString
type.boolean
isTensor()
Returns if the IValue is aTensor
type.boolean
Returns if the IValue is aIValue[]
type.boolean
isTuple()
Returns if the IValue is a tuple type.static IValue
listFrom
(boolean... list) Creates a newIValue
of typeboolean[]
.static IValue
listFrom
(double... list) Creates a newIValue
of typedouble[]
.static IValue
listFrom
(long... list) Creates a newIValue
of typelong[]
.static IValue
Creates a newIValue
of typeNDArray[]
.static IValue
Creates a newIValue
of typeNDArray[]
.static IValue
stringIValueMapFrom
(Map<String, IValue> map) Creates a newIValue
of typeMap[String, IValue]
.static IValue
stringMapFrom
(Map<String, PtNDArray> map) Creates a newIValue
of typeMap[String, PtNDArray]
.boolean
Returns theboolean
value of this IValue.boolean[]
Returns theboolean[]
value of this IValue.double
toDouble()
Returns thedouble
value of this IValue.double[]
Returns thedouble[]
value of this IValue.IValue[]
Returns theIValue[]
value of this IValue list.Returns theMap<String, IValue>
value of this IValue.IValue[]
Returns theMap<String, IValue>
value of this IValue.long
toLong()
Returns thelong
value of this IValue.long[]
Returns thelong[]
value of this IValue.ai.djl.ndarray.NDList
toNDList
(PtNDManager manager) Returns theNDList
value of this IValue.Returns theString
value of this IValue.toTensor
(PtNDManager manager) Returns theNDArray
value of this IValue.toTensorArray
(PtNDManager manager) Returns theNDArray[]
value of this IValue.static IValue
Creates a newIValue
of typeNDArray[]
.Methods inherited from class ai.djl.util.NativeResource
getHandle, getUid, isReleased, onClose
-
Method Details
-
getType
Returns the type of the IValue.- Returns:
- the type of the IValue
-
isTensor
public boolean isTensor()Returns if the IValue is aTensor
type.- Returns:
- if the IValue is a Tensor type
-
isBoolean
public boolean isBoolean()Returns if the IValue is aboolean
type.- Returns:
- if the IValue is a boolean type
-
isLong
public boolean isLong()Returns if the IValue is along
type.- Returns:
- if the IValue is a long type
-
isDouble
public boolean isDouble()Returns if the IValue is adouble
type.- Returns:
- if the IValue is a double type
-
isString
public boolean isString()Returns if the IValue is aString
type.- 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
Creates a newIValue
of typePtNDArray
.- Parameters:
array
- the NDArray- Returns:
- a new
IValue
of typePtNDArray
-
from
Creates a newIValue
of typeboolean
.- Parameters:
value
- the boolean value- Returns:
- a new
IValue
of typeboolean
-
from
Creates a newIValue
of typelong
.- Parameters:
value
- the long value- Returns:
- a new
IValue
of typelong
-
from
Creates a newIValue
of typedouble
.- Parameters:
value
- the double value- Returns:
- a new
IValue
of typedouble
-
from
Creates a newIValue
of typeString
.- Parameters:
value
- the String value- Returns:
- a new
IValue
of typeString
-
listFrom
Creates a newIValue
of typeboolean[]
.- Parameters:
list
- the boolean[] value- Returns:
- a new
IValue
of typeboolean[]
-
listFrom
Creates a newIValue
of typelong[]
.- Parameters:
list
- the long[] value- Returns:
- a new
IValue
of typelong[]
-
listFrom
Creates a newIValue
of typedouble[]
.- Parameters:
list
- the double[] value- Returns:
- a new
IValue
of typedouble[]
-
listFrom
Creates a newIValue
of typeNDArray[]
.- Parameters:
list
- the NDArray[] value- Returns:
- a new
IValue
of typeNDArray[]
-
listFrom
Creates a newIValue
of typeNDArray[]
.- Parameters:
list
- the NDArray[] value- Returns:
- a new
IValue
of typeNDArray[]
-
tupleFrom
Creates a newIValue
of typeNDArray[]
.- Parameters:
list
- the NDArray[] value- Returns:
- a new
IValue
of typeNDArray[]
-
stringMapFrom
Creates a newIValue
of typeMap[String, PtNDArray]
.- Parameters:
map
- the Map[String, IValue] value- Returns:
- a new
IValue
of typeMap[String, PtNDArray]
-
stringIValueMapFrom
Creates a newIValue
of typeMap[String, IValue]
.- Parameters:
map
- the Map[String, IValue] value- Returns:
- a new
IValue
of typeMap[String, IValue]
-
toBoolean
public boolean toBoolean()Returns theboolean
value of this IValue.- Returns:
- the boolean value of this IValue
-
toLong
public long toLong()Returns thelong
value of this IValue.- Returns:
- the long value of this IValue
-
toDouble
public double toDouble()Returns thedouble
value of this IValue.- Returns:
- the double value of this IValue
-
toStringValue
Returns theString
value 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
Returns theNDArray
value of this IValue.- Parameters:
manager
- theNDManager
to create the NDArray- Returns:
- the NDArray value of this IValue
-
toTensorArray
Returns theNDArray[]
value of this IValue.- Parameters:
manager
- the NDManager to create NDArray- Returns:
- the NDArray[] value of this IValue
-
toIValueArray
Returns theIValue[]
value of this IValue list.- Returns:
- the IValue[] value of this IValue list
-
toIValueMap
Returns theMap<String, IValue>
value of this IValue.- Returns:
- the Map<String, IValue> value of this IValue
-
toIValueTuple
Returns theMap<String, IValue>
value of this IValue.- Returns:
- the Map<String, IValue> value of this IValue
-
toNDList
Returns theNDList
value of this IValue.- Parameters:
manager
- the NDManager to create NDArray- Returns:
- the
NDList
value of this IValue
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classai.djl.util.NativeResource<Long>
-