java.lang.Object
uk.ac.manchester.tornado.api.types.arrays.TornadoNativeArray
uk.ac.manchester.tornado.api.types.arrays.DoubleArray
DoubleArray relies on preview features of the Java platform:
DoubleArrayrefers 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 doubles stored in native memory.
The double data is stored in a
MemorySegmentPREVIEW, which represents a contiguous region of off-heap memory.
The class also encapsulates methods for setting and getting double values,
for initializing the double 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
ConstructorsConstructorDescriptionDoubleArray(int numberOfElements) Constructs a new instance of theDoubleArraythat will store a user-specified number of elements.DoubleArray(DoubleArray... arrays) Constructs a newDoubleArrayinstance by concatenating the contents of the given array ofDoubleArrayinstances. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all the values of theDoubleArrayinstance to zero.static DoubleArrayconcat(DoubleArray... arrays) Concatenates multipleDoubleArrayinstances into a singleDoubleArray.static DoubleArrayfromArray(double[] values) Creates a new instance of theDoubleArrayclass from an on-heap double array.static DoubleArrayfromDoubleBuffer(DoubleBuffer buffer) Creates a new instance of theDoubleArrayclass from aDoubleBuffer.static DoubleArrayfromElements(double... values) Creates a new instance of theDoubleArrayclass from a set of double values.static DoubleArrayfromSegment(MemorySegmentPREVIEW segment) static DoubleArrayfromSegmentShallow(MemorySegmentPREVIEW segment) Creates a new instance of theDoubleArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.doubleget(int index) Gets the double value stored at the specified index of theDoubleArrayinstance.intlongReturns the number of bytes of theMemorySegmentPREVIEW that is associated with theDoubleArrayinstance, excluding the header bytes.longReturns the total number of bytes that theMemorySegmentPREVIEW, associated with theDoubleArrayinstance, occupies.intgetSize()Returns the number of double elements stored in theDoubleArrayinstance.voidinit(double value) Initializes all the elements of theDoubleArrayinstance with a specified value.static voidinitialize(DoubleArray array, double value) Factory method to initialize aDoubleArray.voidset(int index, double value) Sets the double value at a specified index of theDoubleArrayinstance.slice(int offset, int length) Extracts a slice of elements from a givenDoubleArray, creating a newDoubleArrayinstance.double[]Converts the double data from off-heap to on-heap, by copying the values of aDoubleArrayinstance into a new on-heap array.
-
Constructor Details
-
DoubleArray
public DoubleArray(int numberOfElements) Constructs a new instance of theDoubleArraythat will store a user-specified number of elements.- Parameters:
numberOfElements- The number of elements in the array.
-
DoubleArray
Constructs a newDoubleArrayinstance by concatenating the contents of the given array ofDoubleArrayinstances.- Parameters:
arrays- An array ofDoubleArrayinstances to be concatenated into the new instance.
-
-
Method Details
-
fromArray
Creates a new instance of theDoubleArrayclass from an on-heap double array.- Parameters:
values- The on-heap double array to create the instance from.- Returns:
- A new
DoubleArrayinstance, initialized with values of the on-heap double array.
-
fromElements
Creates a new instance of theDoubleArrayclass from a set of double values.- Parameters:
values- The double values to initialize the array with.- Returns:
- A new
DoubleArrayinstance, initialized with the given values.
-
fromSegment
- Parameters:
segment- TheMemorySegmentPREVIEW containing the off-heap double data.- Returns:
- A new
DoubleArrayinstance, initialized with the segment data.
-
fromSegmentShallow
Creates a new instance of theDoubleArrayclass by wrapping an existingMemorySegmentPREVIEW without copying its contents.- Parameters:
segment- TheMemorySegmentPREVIEW containing *both* the off-heap double *header* and *data*.- Returns:
- A new
DoubleArrayinstance that wraps the given segment.
-
fromDoubleBuffer
Creates a new instance of theDoubleArrayclass from aDoubleBuffer.- Parameters:
buffer- TheDoubleBuffercontaining the double data.- Returns:
- A new
DoubleArrayinstance, initialized with the buffer data.
-
toHeapArray
public double[] toHeapArray()Converts the double data from off-heap to on-heap, by copying the values of aDoubleArrayinstance into a new on-heap array.- Returns:
- A new on-heap double array, initialized with the values stored in the
DoubleArrayinstance.
-
set
public void set(int index, double value) Sets the double value at a specified index of theDoubleArrayinstance.- Parameters:
index- The index at which to set the double value.value- The double value to store at the specified index.
-
get
public double get(int index) Gets the double value stored at the specified index of theDoubleArrayinstance.- Parameters:
index- The index of which to retrieve the double value.- Returns:
-
clear
public void clear()Sets all the values of theDoubleArrayinstance to zero.- Specified by:
clearin classTornadoNativeArray
-
getElementSize
public int getElementSize()- Specified by:
getElementSizein classTornadoNativeArray
-
init
public void init(double value) Initializes all the elements of theDoubleArrayinstance with a specified value.- Parameters:
value- The double value to initialize theDoubleArrayinstance with.
-
getSize
public int getSize()Returns the number of double elements stored in theDoubleArrayinstance.- Specified by:
getSizein classTornadoNativeArray- Returns:
-
getSegment
- Specified by:
getSegmentin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theDoubleArrayinstance.
-
getSegmentWithHeader
- Specified by:
getSegmentWithHeaderin classTornadoNativeArray- Returns:
- The
MemorySegmentPREVIEW associated with theDoubleArrayinstance.
-
getNumBytesOfSegmentWithHeader
public long getNumBytesOfSegmentWithHeader()Returns the total number of bytes that theMemorySegmentPREVIEW, associated with theDoubleArrayinstance, 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 theDoubleArrayinstance, 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 aDoubleArray. This method can be invoked from a Task-Graph.- Parameters:
array- Input Array.value- The float value to initialize theDoubleArrayinstance with.
-
concat
Concatenates multipleDoubleArrayinstances into a singleDoubleArray.- Parameters:
arrays- Variable number ofDoubleArrayobjects to be concatenated.- Returns:
- A new
DoubleArrayinstance containing all the elements of the input arrays, concatenated in the order they were provided.
-
slice
Extracts a slice of elements from a givenDoubleArray, creating a newDoubleArrayinstance.- 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
DoubleArrayinstance representing the specified slice of the original array. - Throws:
IllegalArgumentException- if the specified slice is out of the bounds of the original array.
-
DoubleArraywhen preview features are enabled.