java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.IntArray
IntArray relies on preview features of the Java platform:
IntArrayrefers 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 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.-
Field Summary
Fields inherited from class uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
ARRAY_HEADER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values of theIntArrayinstance to zero.static IntArraystatic IntArrayfromArray(int[] values) Creates a new instance of theIntArrayclass from an on-heap int array.static IntArrayfromElements(int... values) Creates a new instance of theIntArrayclass from a set of int values.static IntArrayfromIntBuffer(IntBuffer buffer) static IntArrayfromSegment(MemorySegmentPREVIEW segment) static IntArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theIntArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.intget(int index) Gets the int value stored at the specified index of theIntArrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theIntArrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theIntArrayinstance, occupies.intgetSize()Returns the number of int elements stored in theIntArrayinstance.voidinit(int value) Initializes all the elements of theIntArrayinstance with a specified value.static voidinitialize(IntArray array, int value) Factory method to initialize aIntArray.voidset(int index, int value) Sets the int value at a specified index of theIntArrayinstance.slice(int offset, int length) Extracts a slice of elements from a given , creating a new instance.int[]Converts the int data from off-heap to on-heap, by copying the values of aIntArrayinstance into a new on-heap array.
-
Constructor Details
-
IntArray
public IntArray(int numberOfElements) Constructs a new instance of theIntArraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
IntArray
Constructs a newIntArrayinstance by concatenating the contents of the given array ofIntArrayinstances.- Parameters:
arrays- An array ofIntArrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theIntArrayclass from an on-heap int array.- Parameters:
values- The on-heap int array to create the instance from.- Returns:
- A new
IntArrayinstance, initialized with values of the on-heap int array.
-
fromElements
Creates a new instance of theIntArrayclass from a set of int values.- Parameters:
values- The int values to initialize the array with.- Returns:
- A new
IntArrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap int data.- Returns:
- A new
IntArrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theIntArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap int *header* and *data*.- Returns:
- A new
IntArrayinstance that wraps the given segment.
-
fromIntBuffer
-
toHeapArray
public int[] toHeapArray()Converts the int data from off-heap to on-heap, by copying the values of aIntArrayinstance into a new on-heap array.- Returns:
- A new on-heap int array, initialized with the values stored in the
IntArrayinstance.
-
set
public void set(int index, int value) Sets the int value at a specified index of theIntArrayinstance.- 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 theIntArrayinstance.- Parameters:
index- The index of which to retrieve the int value.- Returns:
-
clear
public void clear()Sets all the values of theIntArrayinstance to zero.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
init
public void init(int value) Initializes all the elements of theIntArrayinstance with a specified value.- Parameters:
value- The int value to initialize theIntArrayinstance with.
-
getSize
public int getSize()Returns the number of int elements stored in theIntArrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theIntArrayinstance, 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 theIntArrayinstance, excluding the header bytes.- Specified by:
getNumBytesOfSegmentin classTornadoNativeArray- Returns:
- The number of bytes of the raw data in the
MemorySegmentPREVIEW.
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theIntArrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theIntArrayinstance.
-
initialize
Factory method to initialize aIntArray. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The float value to initialize theIntArrayinstance with.
-
concat
-
slice
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.
-
IntArraywhen preview features are enabled.