| 113 | } |
| 114 | |
| 115 | Result<std::shared_ptr<Buffer>> SliceTensorBuffer(const Array& data_array, |
| 116 | const DataType& value_type, |
| 117 | std::span<const int64_t> shape) { |
| 118 | const int64_t byte_width = value_type.byte_width(); |
| 119 | ARROW_ASSIGN_OR_RAISE(const int64_t size, ComputeShapeProduct(shape)); |
| 120 | if (size != data_array.length()) { |
| 121 | return Status::Invalid("Expected data array of length ", size, ", got ", |
| 122 | data_array.length()); |
| 123 | } |
| 124 | |
| 125 | int64_t start_position = 0; |
| 126 | if (MultiplyWithOverflow(data_array.offset(), byte_width, &start_position)) { |
| 127 | return Status::Invalid("Data offset in bytes would not fit in 64-bit integer"); |
| 128 | } |
| 129 | int64_t size_bytes = 0; |
| 130 | if (MultiplyWithOverflow(size, byte_width, &size_bytes)) { |
| 131 | return Status::Invalid("Tensor byte size would not fit in 64-bit integer"); |
| 132 | } |
| 133 | |
| 134 | return SliceBufferSafe(data_array.data()->buffers[1], start_position, size_bytes); |
| 135 | } |
| 136 | |
| 137 | } // namespace arrow::internal |
no test coverage detected