Class IValue

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class IValue
    extends ai.djl.util.NativeResource<java.lang.Long>
    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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      static IValue from​(boolean value)
      Creates a new IValue of type boolean.
      static IValue from​(double value)
      Creates a new IValue of type double.
      static IValue from​(long value)
      Creates a new IValue of type long.
      static IValue from​(PtNDArray array)
      Creates a new IValue of type PtNDArray.
      static IValue from​(java.lang.String value)
      Creates a new IValue of type String.
      java.lang.String getType()
      Returns the type of the IValue.
      boolean isBoolean()
      Returns if the IValue is a boolean type.
      boolean isBooleanList()
      Returns if the IValue is a boolean[] type.
      boolean isDouble()
      Returns if the IValue is a double type.
      boolean isDoubleList()
      Returns if the IValue is a double[] type.
      boolean isList()
      Returns if the IValue is a IValue[] type.
      boolean isLong()
      Returns if the IValue is a long type.
      boolean isLongList()
      Returns if the IValue is a long[] type.
      boolean isMap()
      Returns if the IValue is a Map&lt;String, V&gt; type.
      boolean isString()
      Returns if the IValue is a String type.
      boolean isTensor()
      Returns if the IValue is a Tensor type.
      boolean isTensorList()
      Returns if the IValue is a IValue[] type.
      boolean isTuple()
      Returns if the IValue is a tuple type.
      static IValue listFrom​(boolean... list)
      Creates a new IValue of type boolean[].
      static IValue listFrom​(double... list)
      Creates a new IValue of type double[].
      static IValue listFrom​(long... list)
      Creates a new IValue of type long[].
      static IValue listFrom​(PtNDArray... list)
      Creates a new IValue of type NDArray[].
      static IValue listFrom​(IValue... list)
      Creates a new IValue of type NDArray[].
      static IValue stringIValueMapFrom​(java.util.Map<java.lang.String,​IValue> map)
      Creates a new IValue of type Map[String, IValue].
      static IValue stringMapFrom​(java.util.Map<java.lang.String,​PtNDArray> map)
      Creates a new IValue of type Map[String, PtNDArray].
      boolean toBoolean()
      Returns the boolean value of this IValue.
      boolean[] toBooleanArray()
      Returns the boolean[] value of this IValue.
      double toDouble()
      Returns the double value of this IValue.
      double[] toDoubleArray()
      Returns the double[] value of this IValue.
      IValue[] toIValueArray()
      Returns the IValue[] value of this IValue list.
      java.util.Map<java.lang.String,​IValue> toIValueMap()
      Returns the Map&lt;String, IValue&gt; value of this IValue.
      IValue[] toIValueTuple()
      Returns the Map&lt;String, IValue&gt; value of this IValue.
      long toLong()
      Returns the long value of this IValue.
      long[] toLongArray()
      Returns the long[] value of this IValue.
      ai.djl.ndarray.NDList toNDList​(PtNDManager manager)
      Returns the NDList value of this IValue.
      java.lang.String toStringValue()
      Returns the String value of this IValue.
      PtNDArray toTensor​(PtNDManager manager)
      Returns the NDArray value of this IValue.
      PtNDArray[] toTensorArray​(PtNDManager manager)
      Returns the NDArray[] value of this IValue.
      static IValue tupleFrom​(IValue... list)
      Creates a new IValue of type NDArray[].
      • Methods inherited from class ai.djl.util.NativeResource

        getHandle, getUid, isReleased, onClose
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 a Tensor type.
        Returns:
        if the IValue is a Tensor type
      • isBoolean

        public boolean isBoolean()
        Returns if the IValue is a boolean type.
        Returns:
        if the IValue is a boolean type
      • isLong

        public boolean isLong()
        Returns if the IValue is a long type.
        Returns:
        if the IValue is a long type
      • isDouble

        public boolean isDouble()
        Returns if the IValue is a double type.
        Returns:
        if the IValue is a double type
      • isString

        public boolean isString()
        Returns if the IValue is a String type.
        Returns:
        if the IValue is a String type
      • isBooleanList

        public boolean isBooleanList()
        Returns if the IValue is a boolean[] type.
        Returns:
        if the IValue is a boolean[] type
      • isLongList

        public boolean isLongList()
        Returns if the IValue is a long[] type.
        Returns:
        if the IValue is a long[] type
      • isDoubleList

        public boolean isDoubleList()
        Returns if the IValue is a double[] type.
        Returns:
        if the IValue is a double[] type
      • isTensorList

        public boolean isTensorList()
        Returns if the IValue is a IValue[] 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 a IValue[] 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 a Map&lt;String, V&gt; 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 new IValue of type PtNDArray.
        Parameters:
        array - the NDArray
        Returns:
        a new IValue of type PtNDArray
      • from

        public static IValue from​(boolean value)
        Creates a new IValue of type boolean.
        Parameters:
        value - the boolean value
        Returns:
        a new IValue of type boolean
      • from

        public static IValue from​(long value)
        Creates a new IValue of type long.
        Parameters:
        value - the long value
        Returns:
        a new IValue of type long
      • from

        public static IValue from​(double value)
        Creates a new IValue of type double.
        Parameters:
        value - the double value
        Returns:
        a new IValue of type double
      • from

        public static IValue from​(java.lang.String value)
        Creates a new IValue of type String.
        Parameters:
        value - the String value
        Returns:
        a new IValue of type String
      • listFrom

        public static IValue listFrom​(boolean... list)
        Creates a new IValue of type boolean[].
        Parameters:
        list - the boolean[] value
        Returns:
        a new IValue of type boolean[]
      • listFrom

        public static IValue listFrom​(long... list)
        Creates a new IValue of type long[].
        Parameters:
        list - the long[] value
        Returns:
        a new IValue of type long[]
      • listFrom

        public static IValue listFrom​(double... list)
        Creates a new IValue of type double[].
        Parameters:
        list - the double[] value
        Returns:
        a new IValue of type double[]
      • listFrom

        public static IValue listFrom​(PtNDArray... list)
        Creates a new IValue of type NDArray[].
        Parameters:
        list - the NDArray[] value
        Returns:
        a new IValue of type NDArray[]
      • listFrom

        public static IValue listFrom​(IValue... list)
        Creates a new IValue of type NDArray[].
        Parameters:
        list - the NDArray[] value
        Returns:
        a new IValue of type NDArray[]
      • tupleFrom

        public static IValue tupleFrom​(IValue... list)
        Creates a new IValue of type NDArray[].
        Parameters:
        list - the NDArray[] value
        Returns:
        a new IValue of type NDArray[]
      • stringMapFrom

        public static IValue stringMapFrom​(java.util.Map<java.lang.String,​PtNDArray> map)
        Creates a new IValue of type Map[String, PtNDArray].
        Parameters:
        map - the Map[String, IValue] value
        Returns:
        a new IValue of type Map[String, PtNDArray]
      • stringIValueMapFrom

        public static IValue stringIValueMapFrom​(java.util.Map<java.lang.String,​IValue> map)
        Creates a new IValue of type Map[String, IValue].
        Parameters:
        map - the Map[String, IValue] value
        Returns:
        a new IValue of type Map[String, IValue]
      • toBoolean

        public boolean toBoolean()
        Returns the boolean value of this IValue.
        Returns:
        the boolean value of this IValue
      • toLong

        public long toLong()
        Returns the long value of this IValue.
        Returns:
        the long value of this IValue
      • toDouble

        public double toDouble()
        Returns the double value of this IValue.
        Returns:
        the double value of this IValue
      • toStringValue

        public java.lang.String toStringValue()
        Returns the String value of this IValue.
        Returns:
        the String value of this IValue
      • toBooleanArray

        public boolean[] toBooleanArray()
        Returns the boolean[] value of this IValue.
        Returns:
        the boolean[] value of this IValue
      • toLongArray

        public long[] toLongArray()
        Returns the long[] value of this IValue.
        Returns:
        the long[] value of this IValue
      • toDoubleArray

        public double[] toDoubleArray()
        Returns the double[] value of this IValue.
        Returns:
        the double[] value of this IValue
      • toTensor

        public PtNDArray toTensor​(PtNDManager manager)
        Returns the NDArray value of this IValue.
        Parameters:
        manager - the NDManager to create the NDArray
        Returns:
        the NDArray value of this IValue
      • toTensorArray

        public PtNDArray[] toTensorArray​(PtNDManager manager)
        Returns the NDArray[] value of this IValue.
        Parameters:
        manager - the NDManager to create NDArray
        Returns:
        the NDArray[] value of this IValue
      • toIValueArray

        public IValue[] toIValueArray()
        Returns the IValue[] value of this IValue list.
        Returns:
        the IValue[] value of this IValue list
      • toIValueMap

        public java.util.Map<java.lang.String,​IValue> toIValueMap()
        Returns the Map&lt;String, IValue&gt; value of this IValue.
        Returns:
        the Map<String, IValue> value of this IValue
      • toIValueTuple

        public IValue[] toIValueTuple()
        Returns the Map&lt;String, IValue&gt; value of this IValue.
        Returns:
        the Map<String, IValue> value of this IValue
      • toNDList

        public ai.djl.ndarray.NDList toNDList​(PtNDManager manager)
        Returns the NDList 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 interface java.lang.AutoCloseable
        Overrides:
        close in class ai.djl.util.NativeResource<java.lang.Long>