This is an automated email from the ASF dual-hosted git repository.
kevingurney pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 49838858ea GH-38630: [MATLAB] `arrow.array.BooleanArray`'s `toMATLAB`
method does not take slice offsets into account (#38636)
49838858ea is described below
commit 49838858eab984fc4a7e8595d7dd1883b00350ea
Author: sgilmore10 <[email protected]>
AuthorDate: Thu Nov 9 11:14:31 2023 -0500
GH-38630: [MATLAB] `arrow.array.BooleanArray`'s `toMATLAB` method does not
take slice offsets into account (#38636)
### Rationale for this change
While working on #38415, I noticed that the `toMATLAB` method of
`arrow.array.BooleanArray` does not take the slice offset into account. This
will cause the `toMATLAB` method to return the wrong value.
### What changes are included in this PR?
1. Updated `arrow::matlab::bit::unpack` function to accept a `start_offset`
as input.
2. Updated clients (`BooleanArray::toMATLAB` and `Array::getValid`) to
supply the array `offset` as the `start_offset`.
### Are these changes tested?
The existing tests cover these changes. Additionally, the changes for
#38415 will include tests that verify the `toMATLAB` method returns the correct
MATLAB array when the underlying Arrow array has been sliced.
### Are there any user-facing changes?
No.
* Closes: #38630
Authored-by: Sarah Gilmore <[email protected]>
Signed-off-by: Kevin Gurney <[email protected]>
---
matlab/src/cpp/arrow/matlab/array/proxy/array.cc | 2 +-
matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc | 2 +-
matlab/src/cpp/arrow/matlab/bit/unpack.cc | 3 +--
matlab/src/cpp/arrow/matlab/bit/unpack.h | 2 +-
4 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
index 4e52c990d3..09d9473df4 100644
--- a/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/array.cc
@@ -100,7 +100,7 @@ namespace arrow::matlab::array::proxy {
}
auto validity_bitmap = array->null_bitmap();
- auto valid_elements_mda = bit::unpack(validity_bitmap, array_length);
+ auto valid_elements_mda = bit::unpack(validity_bitmap, array_length,
array->offset());
context.outputs[0] = valid_elements_mda;
}
diff --git a/matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
b/matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
index 6a6e478274..da3560ce52 100644
--- a/matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
+++ b/matlab/src/cpp/arrow/matlab/array/proxy/boolean_array.cc
@@ -53,7 +53,7 @@ namespace arrow::matlab::array::proxy {
void BooleanArray::toMATLAB(libmexclass::proxy::method::Context&
context) {
auto array_length = array->length();
auto packed_logical_data_buffer =
std::static_pointer_cast<arrow::BooleanArray>(array)->values();
- auto logical_array_mda = bit::unpack(packed_logical_data_buffer,
array_length);
+ auto logical_array_mda = bit::unpack(packed_logical_data_buffer,
array_length, array->offset());
context.outputs[0] = logical_array_mda;
}
}
diff --git a/matlab/src/cpp/arrow/matlab/bit/unpack.cc
b/matlab/src/cpp/arrow/matlab/bit/unpack.cc
index 7135d593cf..6cc88d48ed 100644
--- a/matlab/src/cpp/arrow/matlab/bit/unpack.cc
+++ b/matlab/src/cpp/arrow/matlab/bit/unpack.cc
@@ -20,7 +20,7 @@
#include "arrow/util/bitmap_visit.h"
namespace arrow::matlab::bit {
- ::matlab::data::TypedArray<bool> unpack(const
std::shared_ptr<arrow::Buffer>& packed_buffer, int64_t length) {
+ ::matlab::data::TypedArray<bool> unpack(const
std::shared_ptr<arrow::Buffer>& packed_buffer, int64_t length, int64_t
start_offset) {
const auto packed_buffer_ptr = packed_buffer->data();
::matlab::data::ArrayFactory factory;
@@ -31,7 +31,6 @@ namespace arrow::matlab::bit {
auto unpacked_buffer_ptr = unpacked_buffer.get();
auto visitFcn = [&](const bool is_valid) { *unpacked_buffer_ptr++ =
is_valid; };
- const int64_t start_offset = 0;
arrow::internal::VisitBitsUnrolled(packed_buffer_ptr, start_offset,
length, visitFcn);
::matlab::data::TypedArray<bool> unpacked_matlab_logical_Array =
factory.createArrayFromBuffer({array_length, 1}, std::move(unpacked_buffer));
diff --git a/matlab/src/cpp/arrow/matlab/bit/unpack.h
b/matlab/src/cpp/arrow/matlab/bit/unpack.h
index b6debb85f8..6cd633e76f 100644
--- a/matlab/src/cpp/arrow/matlab/bit/unpack.h
+++ b/matlab/src/cpp/arrow/matlab/bit/unpack.h
@@ -22,6 +22,6 @@
#include "MatlabDataArray.hpp"
namespace arrow::matlab::bit {
- ::matlab::data::TypedArray<bool> unpack(const
std::shared_ptr<arrow::Buffer>& packed_buffer, int64_t length);
+ ::matlab::data::TypedArray<bool> unpack(const
std::shared_ptr<arrow::Buffer>& packed_buffer, int64_t length, int64_t
start_offset);
const uint8_t* extract_ptr(const ::matlab::data::TypedArray<bool>&
unpacked_validity_bitmap);
}