java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.FloatArray
FloatArray relies on preview features of the Java platform:
FloatArrayrefers to one or more preview APIs:MemorySegment.
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.-
Field Summary
Fields inherited from class uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
ARRAY_HEADER -
Constructor Summary
ConstructorsConstructorDescriptionFloatArray(int numberOfElements) Constructs a new instance of theFloatArraythat will store a user-specified number of elements.FloatArray(FloatArray... arrays) Constructs a newFloatArrayinstance by concatenating the contents of the given array ofFloatArrayinstances. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values of theFloatArrayinstance to zero.static FloatArrayconcat(FloatArray... arrays) Concatenates multipleFloatArrayinstances into a singleFloatArray.static FloatArrayfromArray(float[] values) Creates a new instance of theFloatArrayclass from an on-heap float array.static FloatArrayfromElements(float... values) Creates a new instance of theFloatArrayclass from a set of float values.static FloatArrayfromFloatBuffer(FloatBuffer buffer) Creates a new instance of theFloatArrayclass from aFloatBuffer.static FloatArrayfromSegment(MemorySegmentPREVIEW segment) static FloatArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theFloatArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.floatget(int index) Gets the float value stored at the specified index of theFloatArrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theFloatArrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theFloatArrayinstance, occupies.intgetSize()Returns the number of float elements stored in theFloatArrayinstance.voidinit(float value) Initializes all the elements of theFloatArrayinstance with a specified value.static voidinitialize(FloatArray array, float value) Factory method to initialize aFloatArray.voidset(int index, float value) Sets the float value at a specified index of theFloatArrayinstance.slice(int offset, int length) Extracts a slice of elements from a givenFloatArray, creating a newFloatArrayinstance.float[]Converts the float data from off-heap to on-heap, by copying the values of aFloatArrayinstance into a new on-heap array.
-
Constructor Details
-
FloatArray
public FloatArray(int numberOfElements) Constructs a new instance of theFloatArraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
FloatArray
Constructs a newFloatArrayinstance by concatenating the contents of the given array ofFloatArrayinstances.- Parameters:
arrays- An array ofFloatArrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theFloatArrayclass from an on-heap float array.- Parameters:
values- The on-heap float array to create the instance from.- Returns:
- A new
FloatArrayinstance, initialized with values of the on-heap float array.
-
fromElements
Creates a new instance of theFloatArrayclass from a set of float values.- Parameters:
values- The float values to initialize the array with.- Returns:
- A new
FloatArrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap float data.- Returns:
- A new
FloatArrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theFloatArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap float *header* and *data*.- Returns:
- A new
FloatArrayinstance that wraps the given segment.
-
fromFloatBuffer
Creates a new instance of theFloatArrayclass from aFloatBuffer.- Parameters:
buffer- TheFloatBuffercontaining the float data.- Returns:
- A new
FloatArrayinstance, initialized with the buffer data.
-
toHeapArray
public float[] toHeapArray()Converts the float data from off-heap to on-heap, by copying the values of aFloatArrayinstance into a new on-heap array.- Returns:
- A new on-heap float array, initialized with the values stored in the
FloatArrayinstance.
-
set
public void set(int index, float value) Sets the float value at a specified index of theFloatArrayinstance.- 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 theFloatArrayinstance.- Parameters:
index- The index of which to retrieve the float value.- Returns:
-
clear
public void clear()Sets all the values of theFloatArrayinstance to zero.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
init
public void init(float value) Initializes all the elements of theFloatArrayinstance with a specified value.- Parameters:
value- The float value to initialize theFloatArrayinstance with.
-
getSize
public int getSize()Returns the number of float elements stored in theFloatArrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theFloatArrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theFloatArrayinstance.
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theFloatArrayinstance, occupies.- Specified by:
getNumBytesOfSegmentWithHeaderin classTornadoNativeArray- Returns:
- The total number of bytes of the
MemorySegmentPREVIEW.
-
getNumBytesOfSegment
public long getNumBytesOfSegment()Returns the number of bytes of theMemorySegmentPREVIEW that is associated with theFloatArrayinstance, excluding the header bytes.- Specified by:
getNumBytesOfSegmentin classTornadoNativeArray- Returns:
- The number of bytes of the raw data in the
MemorySegmentPREVIEW.
-
initialize
Factory method to initialize aFloatArray. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The float value to initialize theFloatArrayinstance with.
-
concat
Concatenates multipleFloatArrayinstances into a singleFloatArray.- Parameters:
arrays- Variable number ofFloatArrayobjects to be concatenated.- Returns:
- A new
FloatArrayinstance containing all the elements of the input arrays, concatenated in the order they were provided.
-
slice
Extracts a slice of elements from a givenFloatArray, creating a newFloatArrayinstance.- 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
FloatArrayinstance representing the specified slice of the original array. - Throws:
IllegalArgumentException- if the specified slice is out of the bounds of the original array.
-
FloatArraywhen preview features are enabled.