| 127 | } |
| 128 | |
| 129 | Result<std::shared_ptr<Buffer>> SliceTensorBuffer(const Array& data_array, |
| 130 | const DataType& value_type, |
| 131 | std::span<const int64_t> shape) { |
| 132 | const int64_t byte_width = value_type.byte_width(); |
| 133 | ARROW_ASSIGN_OR_RAISE(const int64_t size, ComputeShapeProduct(shape)); |
| 134 | if (size != data_array.length()) { |
| 135 | return Status::Invalid("Expected data array of length ", size, ", got ", |
| 136 | data_array.length()); |
| 137 | } |
| 138 | |
| 139 | int64_t start_position = 0; |
| 140 | if (MultiplyWithOverflow(data_array.offset(), byte_width, &start_position)) { |
| 141 | return Status::Invalid("Data offset in bytes would not fit in 64-bit integer"); |
| 142 | } |
| 143 | int64_t size_bytes = 0; |
| 144 | if (MultiplyWithOverflow(size, byte_width, &size_bytes)) { |
| 145 | return Status::Invalid("Tensor byte size would not fit in 64-bit integer"); |
| 146 | } |
| 147 | |
| 148 | return SliceBufferSafe(data_array.data()->buffers[1], start_position, size_bytes); |
| 149 | } |
| 150 | |
| 151 | } // namespace arrow::internal |
nothing calls this directly
no test coverage detected