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

Function SliceTensorBuffer

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

Source from the content-addressed store, hash-verified

113}
114
115Result<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

Callers 2

DeserializeMethod · 0.85
DeserializeMethod · 0.85

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