ADRs/0028 - Offset centralization.md
Proposed
Proposed by: Adam Gibson Oct 24,2024
The current nd4j codebase stores offsets in multiple locations, including opaque data buffers and data buffers. This scattered approach leads to inconsistencies, potential bugs, and difficulties in maintenance. Additionally, the current method of passing NDArray components from Java to C++ involves manually unpacking various elements, which is error-prone and cumbersome.
We propose to refactor the nd4j codebase to centralize offset storage within NDArrays and introduce a new OpaqueNDArray type for improved Java-C++ interoperability. The key features of this proposal include:
Example of the proposed change:
// Before void someOperation(void* dataBuffer, sd::LongType* shapeBuffer, sd::LongType offset, ...) { // Manual unpacking and offset handling }
// After typedef NDArray* OpaqueNDArray;
void someOperation(OpaqueNDArray array) { // Access all necessary information through the NDArray object sd::LongType offset = array->offset(); // ... }