| 421 | |
| 422 | template <typename T> |
| 423 | void CheckToTensor(const std::vector<T>& values, const std::shared_ptr<DataType> typ, |
| 424 | const int32_t& element_size, const std::vector<int64_t>& element_shape, |
| 425 | const std::vector<int64_t>& element_permutation, |
| 426 | const std::vector<std::string>& element_dim_names, |
| 427 | const std::vector<int64_t>& tensor_shape, |
| 428 | const std::vector<std::string>& tensor_dim_names, |
| 429 | const std::vector<int64_t>& tensor_strides) { |
| 430 | auto buffer = Buffer::Wrap(values); |
| 431 | const std::shared_ptr<DataType> element_type = fixed_size_list(typ, element_size); |
| 432 | std::vector<std::shared_ptr<Buffer>> buffers = {nullptr, buffer}; |
| 433 | auto arr_data = std::make_shared<ArrayData>(typ, values.size(), buffers); |
| 434 | auto arr = std::make_shared<Int64Array>(arr_data); |
| 435 | ASSERT_OK_AND_ASSIGN(auto fsla_arr, FixedSizeListArray::FromArrays(arr, element_type)); |
| 436 | |
| 437 | ASSERT_OK_AND_ASSIGN( |
| 438 | auto expected_tensor, |
| 439 | Tensor::Make(typ, buffer, tensor_shape, tensor_strides, tensor_dim_names)); |
| 440 | const auto ext_type = |
| 441 | fixed_shape_tensor(typ, element_shape, element_permutation, element_dim_names); |
| 442 | |
| 443 | auto ext_arr = ExtensionType::WrapArray(ext_type, fsla_arr); |
| 444 | const auto tensor_array = std::static_pointer_cast<FixedShapeTensorArray>(ext_arr); |
| 445 | ASSERT_OK_AND_ASSIGN(const auto actual_tensor, tensor_array->ToTensor()); |
| 446 | ASSERT_OK(actual_tensor->Validate()); |
| 447 | |
| 448 | ASSERT_EQ(actual_tensor->type(), expected_tensor->type()); |
| 449 | ASSERT_EQ(actual_tensor->shape(), expected_tensor->shape()); |
| 450 | ASSERT_EQ(actual_tensor->strides(), expected_tensor->strides()); |
| 451 | ASSERT_EQ(actual_tensor->dim_names(), expected_tensor->dim_names()); |
| 452 | ASSERT_TRUE(actual_tensor->data()->Equals(*expected_tensor->data())); |
| 453 | ASSERT_TRUE(actual_tensor->Equals(*expected_tensor)); |
| 454 | } |
| 455 | |
| 456 | TEST_F(TestFixedShapeTensorType, ToTensor) { |
| 457 | std::vector<float_t> float_values = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |