MCPcopy Create free account
hub / github.com/apache/arrow / pack

Function pack

matlab/src/cpp/arrow/matlab/bit/pack.cc:46–74  ·  view source on GitHub ↗

Pack an unpacked MATLAB logical array into a bit-packed arrow::Buffer.

Source from the content-addressed store, hash-verified

44
45// Pack an unpacked MATLAB logical array into a bit-packed arrow::Buffer.
46arrow::Result<std::shared_ptr<arrow::Buffer>> pack(
47 const ::matlab::data::TypedArray<bool> matlab_logical_array) {
48 // Validate that the input arrow::Buffer has sufficient size to store a full bit-packed
49 // representation of the input MATLAB logical array.
50 const auto unpacked_buffer_length = matlab_logical_array.getNumberOfElements();
51
52 // Compute the bit packed length from the unpacked length.
53 const auto packed_buffer_length = packedLength(unpacked_buffer_length);
54
55 ARROW_ASSIGN_OR_RAISE(auto packed_validity_bitmap_buffer,
56 arrow::AllocateResizableBuffer(packed_buffer_length));
57
58 // Get pointers to the internal uint8_t arrays behind arrow::Buffer and mxArray
59 // Get raw bool array pointer from MATLAB logical array.
60 // Get an iterator to the raw bool data behind the MATLAB logical array.
61 auto unpacked_bool_data_iterator = matlab_logical_array.cbegin();
62
63 // Iterate over the mxLogical array and write bit-packed bools to the arrow::Buffer.
64 // Call into a loop-unrolled Arrow utility for better performance when bit-packing.
65 auto generator = [&]() -> bool { return *(unpacked_bool_data_iterator++); };
66 const int64_t start_offset = 0;
67
68 auto mutable_data = packed_validity_bitmap_buffer->mutable_data();
69
70 arrow::internal::GenerateBitsUnrolled(mutable_data, start_offset,
71 unpacked_buffer_length, generator);
72
73 return packed_validity_bitmap_buffer;
74}
75
76} // namespace arrow::matlab::bit

Callers 1

packValidFunction · 0.85

Calls 4

packedLengthFunction · 0.85
cbeginMethod · 0.80
GenerateBitsUnrolledFunction · 0.50
mutable_dataMethod · 0.45

Tested by

no test coverage detected