Commits


sgilmore10 authored and GitHub committed 65e2f22a91d
GH-37597: [MATLAB] Add `toMATLAB` method to `arrow.array.ChunkedArray` class (#37613) ### Rationale for this change Currently, there is no way to easily convert an `arrow.array.ChunkedArray` into a corresponding MATLAB array, other than (1) manually iterating chunk by chunk, (2) calling `toMATLAB` on each chunk, and then (3) concatenating all of the converted chunks together into one contiguous MATLAB array. It would be helpful to add a toMATLAB method to `arrow.array.ChunkedArray` that abstracts away all of these steps. ### What changes are included in this PR? 1. Added `toMATLAB` method to `arrow.array.ChunkedArray` class 2. Added `preallocateMATLABArray` abstract method to `arrow.type.Type` class. This method is used by the `ChunkedArray` `toMATLAB` to pre-allocate a MATLAB array of the expected class type and shape. This is necessary to ensure `toMATLAB` returns the correct MATLAB array when the `ChunkedArray` has zero chunks. If `toMATLAB` stored the result of calling `toMATLAB` on each chunk in a `cell` array before concatenating the values, `toMATLAB` would return a 0x0 `double` array for zero-chunked arrays. The pre-allocation approach avoids this issue. 3. Implement `preallocateMATLABArray` on all `arrow.type.Type` classes. 4. Added an abstract class `arrow.type.NumericType` that all classes representing numeric data types inherit from. `NumericType` implements `preallocateMATLABArray` for its subclasses. ### Are these changes tested? Yes. Added unit tests to `tChunkedArray.m`. ### Are there any user-facing changes? Yes. Users can now call `toMATLAB` on `ChunkedArray`s. **Example** ```matlab >> a = arrow.array([1 2 NaN 4 5]); >> b = arrow.array([6 7 8 9 NaN 11]); >> c = arrow.array.ChunkedArray.fromArrays(a, b); >> data = toMATLAB(c) data = 1 2 NaN 4 5 6 7 8 9 NaN 11 ``` * Closes: #37597 Authored-by: Sarah Gilmore <sgilmore@mathworks.com> Signed-off-by: Kevin Gurney <kgurney@mathworks.com>