Module tornado.api

Class IntArray

java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.IntArray

public final class IntArray extends TornadoNativeArray
IntArray relies on preview features of the Java platform:
Programs can only use IntArray when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This class represents an array of ints stored in native memory. The int data is stored in a MemorySegmentPREVIEW, which represents a contiguous region of off-heap memory. The class also encapsulates methods for setting and getting int values, for initializing the int array, and for converting the array to and from different representations.
  • Constructor Details

    • IntArray

      public IntArray(int numberOfElements)
      Constructs a new instance of the IntArray that will store a user-specified number of elements.
      Parameters:
      numberOfElements - The number of elements in the array.
    • IntArray

      public IntArray(IntArray... arrays)
      Constructs a new IntArray instance by concatenating the contents of the given array of IntArray instances.
      Parameters:
      arrays - An array of IntArray instances to be concatenated into the new instance.
  • Method Details

    • fromArray

      public static IntArray fromArray(int[] values)
      Creates a new instance of the IntArray class from an on-heap int array.
      Parameters:
      values - The on-heap int array to create the instance from.
      Returns:
      A new IntArray instance, initialized with values of the on-heap int array.
    • fromElements

      public static IntArray fromElements(int... values)
      Creates a new instance of the IntArray class from a set of int values.
      Parameters:
      values - The int values to initialize the array with.
      Returns:
      A new IntArray instance, initialized with the given values.
    • fromSegment

      public static IntArray fromSegment(MemorySegmentPREVIEW segment)
      Creates a new instance of the IntArray class from a MemorySegmentPREVIEW.
      Parameters:
      segment - The MemorySegmentPREVIEW containing the off-heap int data.
      Returns:
      A new IntArray instance, initialized with the segment data.
    • fromSegmentShallow

      public static IntArray fromSegmentShallow(MemorySegmentPREVIEW segment)
      Creates a new instance of the IntArray class by wrapping an existing MemorySegmentPREVIEW without copying its contents.
      Parameters:
      segment - The MemorySegmentPREVIEW containing *both* the off-heap int *header* and *data*.
      Returns:
      A new IntArray instance that wraps the given segment.
    • fromIntBuffer

      public static IntArray fromIntBuffer(IntBuffer buffer)
      Creates a new instance of the IntArray class from a IntBuffer.
      Parameters:
      buffer - The IntBuffer containing the int data.
      Returns:
      A new IntArray instance, initialized with the buffer data.
    • toHeapArray

      public int[] toHeapArray()
      Converts the int data from off-heap to on-heap, by copying the values of a IntArray instance into a new on-heap array.
      Returns:
      A new on-heap int array, initialized with the values stored in the IntArray instance.
    • set

      public void set(int index, int value)
      Sets the int value at a specified index of the IntArray instance.
      Parameters:
      index - The index at which to set the int value.
      value - The int value to store at the specified index.
    • get

      public int get(int index)
      Gets the int value stored at the specified index of the IntArray instance.
      Parameters:
      index - The index of which to retrieve the int value.
      Returns:
    • clear

      public void clear()
      Sets all the values of the IntArray instance to zero.
      Specified by:
      clear in class TornadoNativeArray
    • getElementSize

      public int getElementSize()
      Specified by:
      getElementSize in class TornadoNativeArray
    • init

      public void init(int value)
      Initializes all the elements of the IntArray instance with a specified value.
      Parameters:
      value - The int value to initialize the IntArray instance with.
    • getSize

      public int getSize()
      Returns the number of int elements stored in the IntArray instance.
      Specified by:
      getSize in class TornadoNativeArray
      Returns:
    • getNumBytesOfSegmentWithHeader

      public long getNumBytesOfSegmentWithHeader()
      Returns the total number of bytes that the MemorySegmentPREVIEW, associated with the IntArray instance, occupies.
      Specified by:
      getNumBytesOfSegmentWithHeader in class TornadoNativeArray
      Returns:
      The total number of bytes of the MemorySegmentPREVIEW.
    • getNumBytesOfSegment

      public long getNumBytesOfSegment()
      Returns the number of bytes of the MemorySegmentPREVIEW that is associated with the IntArray instance, excluding the header bytes.
      Specified by:
      getNumBytesOfSegment in class TornadoNativeArray
      Returns:
      The number of bytes of the raw data in the MemorySegmentPREVIEW.
    • getSegment

      public MemorySegmentPREVIEW getSegment()
      Returns the underlying MemorySegmentPREVIEW of the IntArray instance.
      Specified by:
      getSegment in class TornadoNativeArray
      Returns:
      The MemorySegmentPREVIEW associated with the IntArray instance.
    • getSegmentWithHeader

      public MemorySegmentPREVIEW getSegmentWithHeader()
      Returns the underlying MemorySegmentPREVIEW of the IntArray instance, including the header.
      Specified by:
      getSegmentWithHeader in class TornadoNativeArray
      Returns:
      The MemorySegmentPREVIEW associated with the IntArray instance.
    • initialize

      public static void initialize(IntArray array, int value)
      Factory method to initialize a IntArray. This method can be invoked from a Task-Graph.
      Parameters:
      array - Input Array.
      value - The float value to initialize the IntArray instance with.
    • concat

      public static IntArray concat(IntArray... arrays)
      Concatenates multiple IntArray instances into a single IntArray.
      Parameters:
      arrays - Variable number of IntArray objects to be concatenated.
      Returns:
      A new IntArray instance containing all the elements of the input arrays, concatenated in the order they were provided.
    • slice

      public IntArray slice(int offset, int length)
      Extracts a slice of elements from a given , creating a new instance.
      Parameters:
      offset - The starting index from which to begin the slice, inclusive.
      length - The number of elements to include in the slice.
      Returns:
      A new instance representing the specified slice of the original array.
      Throws:
      IllegalArgumentException - if the specified slice is out of the bounds of the original array.