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

Function SliceTensorBuffer

cpp/src/arrow/extension/tensor_internal.cc:129–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129Result<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

Callers

nothing calls this directly

Calls 7

MultiplyWithOverflowFunction · 0.85
SliceBufferSafeFunction · 0.85
InvalidFunction · 0.50
byte_widthMethod · 0.45
lengthMethod · 0.45
offsetMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected