felipecrv commented on code in PR #42010:
URL: https://github.com/apache/arrow/pull/42010#discussion_r1639039522
##########
cpp/src/arrow/pretty_print.cc:
##########
@@ -413,18 +414,36 @@ Status ArrayPrinter::WriteValidityBitmap(const Array&
array) {
}
}
+Result<std::shared_ptr<Array>> CopyStartEndToCPU(const Array& arr, int window)
{
+ std::shared_ptr<Array> arr_sliced;
+ if (arr.length() > (2 * window + 1)) {
+ ARROW_ASSIGN_OR_RAISE(auto arr_start,
+ arr.Slice(0, window +
1)->CopyTo(default_cpu_memory_manager()));
+ ARROW_ASSIGN_OR_RAISE(
+ auto arr_end,
+ arr.Slice(arr.length() - window -
1)->CopyTo(default_cpu_memory_manager()));
+ ARROW_ASSIGN_OR_RAISE(arr_sliced, Concatenate({arr_start, arr_end}));
+ } else {
+ ARROW_ASSIGN_OR_RAISE(arr_sliced,
arr.CopyTo(default_cpu_memory_manager()));
Review Comment:
> CopyTo just naively copies all buffers of the array in its entirety, not
actually truncating and copying only the part of the buffer that is needed?
Yes, because `MemoryManager`s work in terms of Buffers, not ranges. We
recently added a function that can copy slices to CPU, but it falls back to
full buffer copy if the source `MemoryManager` is not a CPU memory manager.
The protocols for memory movement between devices might not allow for
range-based copies (@zeroshade might know better than me), so instead expanding
the `MemoryManager` interface we should probably have a way to slice the array
where it is (device-specific) and then copy the smaller array. (?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]