Class NDArray


public class NDArray extends NDArrayBase
Lightweight NDArray class of TVM runtime.
  • Field Summary

    Fields inherited from class org.apache.tvm.NDArrayBase

    handle, isView

    Fields inherited from class org.apache.tvm.TVMValue

    typeCode
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Return a copied flat java array of current array (row-major).
    char[]
    Return a copied flat java array of current array (row-major).
    double[]
    Return a copied flat java array of current array (row-major).
    float[]
    Return a copied flat java array of current array (row-major).
    int[]
    Return a copied flat java array of current array (row-major).
    long[]
    Return a copied flat java array of current array (row-major).
    short[]
    Return a copied flat java array of current array (row-major).
    void
    copyFrom(byte[] sourceArray)
    Copy from a native array.
    void
    copyFrom(char[] sourceArray)
    Copy from a native array.
    void
    copyFrom(double[] sourceArray)
    Copy from a native array.
    void
    copyFrom(float[] sourceArray)
    Copy from a native array.
    void
    copyFrom(int[] sourceArray)
    Copy from a native array.
    void
    copyFrom(long[] sourceArray)
    Copy from a native array.
    void
    copyFrom(short[] sourceArray)
    Copy from a native array.
    void
    copyFromRaw(byte[] sourceArray)
    Copy from a raw byte array.
    Get the device of current array.
    static NDArray
    empty(long[] shape)
    Create an empty float32 array on cpu given shape.
    static NDArray
    empty(long[] shape, Device dev)
    Create an empty float32 array given shape and device.
    static NDArray
    empty(long[] shape, TVMType dtype)
    Create an empty array on cpu given shape and type.
    static NDArray
    empty(long[] shape, TVMType dtype, Device dev)
    Create an empty array given shape, type and device.
    protected void
     
    byte[]
    Return a copied internal byte array of current array (row-major).
    long[]
    Get shape of current NDArray.
    long
    Get total size of current NDArray.

    Methods inherited from class org.apache.tvm.NDArrayBase

    asNDArray, copyTo, release

    Methods inherited from class org.apache.tvm.TVMValue

    asBytes, asDouble, asFunction, asLong, asModule, asString

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class NDArrayBase
      Throws:
      Throwable
    • copyFrom

      public void copyFrom(double[] sourceArray)
      Copy from a native array. The NDArray type must by float64
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(float[] sourceArray)
      Copy from a native array. The NDArray type must by float32
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(long[] sourceArray)
      Copy from a native array. The NDArray type must by int64
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(int[] sourceArray)
      Copy from a native array. The NDArray type must by float32
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(short[] sourceArray)
      Copy from a native array. The NDArray type must by int16
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(byte[] sourceArray)
      Copy from a native array. The NDArray type must by int8
      Parameters:
      sourceArray - the source data
    • copyFrom

      public void copyFrom(char[] sourceArray)
      Copy from a native array. The NDArray type must by uint16
      Parameters:
      sourceArray - the source data
    • copyFromRaw

      public void copyFromRaw(byte[] sourceArray)
      Copy from a raw byte array.
      Parameters:
      sourceArray - the source data
    • shape

      public long[] shape()
      Get shape of current NDArray.
      Returns:
      an array representing shape of current ndarray
    • size

      public long size()
      Get total size of current NDArray.
      Returns:
      size of current NDArray.
    • asDoubleArray

      public double[] asDoubleArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be float64
      Returns:
      A copy of array content.
    • asFloatArray

      public float[] asFloatArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be float32
      Returns:
      A copy of array content.
    • asLongArray

      public long[] asLongArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be int64
      Returns:
      A copy of array content.
    • asIntArray

      public int[] asIntArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be int32
      Returns:
      A copy of array content.
    • asShortArray

      public short[] asShortArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be int16
      Returns:
      A copy of array content.
    • asCharArray

      public char[] asCharArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be uint16
      Returns:
      A copy of array content.
    • asByteArray

      public byte[] asByteArray()
      Return a copied flat java array of current array (row-major). The NDArray dtype must be int8
      Returns:
      A copy of array content.
    • internal

      public byte[] internal()
      Return a copied internal byte array of current array (row-major).
      Returns:
      A copy of array content.
    • device

      public Device device()
      Get the device of current array.
      Returns:
      the device.
    • empty

      public static NDArray empty(long[] shape, TVMType dtype, Device dev)
      Create an empty array given shape, type and device.
      Parameters:
      shape - The shape of the array.
      dtype - The data type of the array.
      dev - The device of the array.
      Returns:
      The array tvm supported.
    • empty

      public static NDArray empty(long[] shape, TVMType dtype)
      Create an empty array on cpu given shape and type.
      Parameters:
      shape - The shape of the array.
      dtype - The data type of the array.
      Returns:
      The array tvm supported.
    • empty

      public static NDArray empty(long[] shape)
      Create an empty float32 array on cpu given shape.
      Parameters:
      shape - The shape of the array.
      Returns:
      The array tvm supported.
    • empty

      public static NDArray empty(long[] shape, Device dev)
      Create an empty float32 array given shape and device.
      Parameters:
      shape - The shape of the array.
      dev - The device of the array.
      Returns:
      The array tvm supported.