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

Method MakeTensor

cpp/src/arrow/extension/fixed_shape_tensor.cc:193–226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193Result<std::shared_ptr<Tensor>> FixedShapeTensorType::MakeTensor(
194 const std::shared_ptr<ExtensionScalar>& scalar) {
195 const auto& ext_scalar = internal::checked_cast<const ExtensionScalar&>(*scalar);
196 const auto& ext_type =
197 internal::checked_cast<const FixedShapeTensorType&>(*scalar->type);
198 if (!is_fixed_width(*ext_type.value_type())) {
199 return Status::TypeError("Cannot convert non-fixed-width values to Tensor.");
200 }
201 const auto& array =
202 internal::checked_cast<const FixedSizeListScalar*>(ext_scalar.value.get())->value;
203 if (array->null_count() > 0) {
204 return Status::Invalid("Cannot convert data with nulls to Tensor.");
205 }
206 std::vector<int64_t> permutation = ext_type.permutation();
207 if (permutation.empty()) {
208 permutation.resize(ext_type.ndim());
209 std::iota(permutation.begin(), permutation.end(), 0);
210 }
211
212 std::vector<int64_t> shape = ext_type.shape();
213 internal::Permute<int64_t>(permutation, &shape);
214
215 std::vector<std::string> dim_names = ext_type.dim_names();
216 if (!dim_names.empty()) {
217 internal::Permute<std::string>(permutation, &dim_names);
218 }
219
220 ARROW_ASSIGN_OR_RAISE(
221 auto strides, internal::ComputeStrides(ext_type.value_type(), shape, permutation));
222 ARROW_ASSIGN_OR_RAISE(const auto buffer, internal::SliceTensorBuffer(
223 *array, *ext_type.value_type(), shape));
224
225 return Tensor::Make(ext_type.value_type(), buffer, shape, strides, dim_names);
226}
227
228Result<std::shared_ptr<FixedShapeTensorArray>> FixedShapeTensorArray::FromTensor(
229 const std::shared_ptr<Tensor>& tensor) {

Callers 2

ASSERT_OK_AND_ASSIGNFunction · 0.45
TEST_FFunction · 0.45

Calls 12

is_fixed_widthFunction · 0.85
resizeMethod · 0.80
MakeFunction · 0.70
TypeErrorFunction · 0.50
InvalidFunction · 0.50
value_typeMethod · 0.45
getMethod · 0.45
null_countMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
shapeMethod · 0.45

Tested by 2

ASSERT_OK_AND_ASSIGNFunction · 0.36
TEST_FFunction · 0.36