Module tornado.api

Class FloatArray

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

public final class FloatArray extends TornadoNativeArray
FloatArray relies on preview features of the Java platform:
Programs can only use FloatArray 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 floats stored in native memory. The float data is stored in a MemorySegmentPREVIEW, which represents a contiguous region of off-heap memory. The class also encapsulates methods for setting and getting float values, for initializing the float array, and for converting the array to and from different representations.
  • Constructor Details

    • FloatArray

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

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

    • fromArray

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

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

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

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

      public static FloatArray fromFloatBuffer(FloatBuffer buffer)
      Creates a new instance of the FloatArray class from a FloatBuffer.
      Parameters:
      buffer - The FloatBuffer containing the float data.
      Returns:
      A new FloatArray instance, initialized with the buffer data.
    • toHeapArray

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

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

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

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

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

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

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

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

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

      public long getNumBytesOfSegmentWithHeader()
      Returns the total number of bytes that the MemorySegmentPREVIEW, associated with the FloatArray 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 FloatArray instance, excluding the header bytes.
      Specified by:
      getNumBytesOfSegment in class TornadoNativeArray
      Returns:
      The number of bytes of the raw data in the MemorySegmentPREVIEW.
    • initialize

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

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

      public FloatArray slice(int offset, int length)
      Extracts a slice of elements from a given FloatArray, creating a new FloatArray 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 FloatArray instance representing the specified slice of the original array.
      Throws:
      IllegalArgumentException - if the specified slice is out of the bounds of the original array.