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

Function ASSERT_OK_AND_ASSIGN

cpp/src/arrow/extension/tensor_extension_array_test.cc:557–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555TEST_F(TestFixedShapeTensorType, RoundtripBatchFromTensor) {
556 auto exact_ext_type = internal::checked_pointer_cast<FixedShapeTensorType>(ext_type_);
557 ASSERT_OK_AND_ASSIGN(auto tensor, Tensor::Make(value_type_, Buffer::Wrap(values_),
558 shape_, {}, {"n", "x", "y"}));
559 ASSERT_OK_AND_ASSIGN(auto ext_arr, FixedShapeTensorArray::FromTensor(tensor));
560 ext_arr->data()->type = exact_ext_type;
561
562 auto ext_metadata =
563 key_value_metadata({{"ARROW:extension:name", ext_type_->extension_name()},
564 {"ARROW:extension:metadata", serialized_}});
565 auto ext_field = field("f0", ext_type_, true, ext_metadata);
566 auto batch = RecordBatch::Make(schema({ext_field}), ext_arr->length(), {ext_arr});
567 std::shared_ptr<RecordBatch> read_batch;
568 ASSERT_OK(RoundtripBatch(batch, &read_batch));
569 CompareBatch(*batch, *read_batch, /*compare_metadata=*/true);
570}
571
572TEST_F(TestFixedShapeTensorType, ComputeStrides) {
573 auto exact_ext_type = internal::checked_pointer_cast<FixedShapeTensorType>(ext_type_);
574
575 auto ext_type_1 = internal::checked_pointer_cast<FixedShapeTensorType>(
576 fixed_shape_tensor(int64(), element_shape_, {}, dim_names_));
577 auto ext_type_2 = internal::checked_pointer_cast<FixedShapeTensorType>(
578 fixed_shape_tensor(int64(), element_shape_, {}, dim_names_));
579 auto ext_type_3 = internal::checked_pointer_cast<FixedShapeTensorType>(
580 fixed_shape_tensor(int32(), element_shape_, {}, dim_names_));
581 ASSERT_TRUE(ext_type_1->Equals(*ext_type_2));
582 ASSERT_FALSE(ext_type_1->Equals(*ext_type_3));
583
584 auto ext_type_4 = internal::checked_pointer_cast<FixedShapeTensorType>(
585 fixed_shape_tensor(int64(), {3, 4, 7}, {}, {"x", "y", "z"}));
586 ASSERT_EQ(ext_type_4->strides(), (std::vector<int64_t>{224, 56, 8}));
587 ext_type_4 = internal::checked_pointer_cast<FixedShapeTensorType>(
588 fixed_shape_tensor(int64(), {3, 4, 7}, {0, 1, 2}, {"x", "y", "z"}));
589 ASSERT_EQ(ext_type_4->strides(), (std::vector<int64_t>{224, 56, 8}));
590
591 auto ext_type_5 = internal::checked_pointer_cast<FixedShapeTensorType>(
592 fixed_shape_tensor(int64(), {3, 4, 7}, {1, 0, 2}));
593 ASSERT_EQ(ext_type_5->strides(), (std::vector<int64_t>{56, 224, 8}));
594 ASSERT_EQ(ext_type_5->Serialize(), R"({"shape":[3,4,7],"permutation":[1,0,2]})");
595
596 auto ext_type_6 = internal::checked_pointer_cast<FixedShapeTensorType>(
597 fixed_shape_tensor(int64(), {3, 4, 7}, {1, 2, 0}, {}));
598 ASSERT_EQ(ext_type_6->strides(), (std::vector<int64_t>{56, 8, 224}));
599 ASSERT_EQ(ext_type_6->Serialize(), R"({"shape":[3,4,7],"permutation":[1,2,0]})");
600 auto ext_type_7 = internal::checked_pointer_cast<FixedShapeTensorType>(
601 fixed_shape_tensor(int32(), {3, 4, 7}, {2, 0, 1}, {}));
602 ASSERT_EQ(ext_type_7->strides(), (std::vector<int64_t>{4, 112, 16}));
603 ASSERT_EQ(ext_type_7->Serialize(), R"({"shape":[3,4,7],"permutation":[2,0,1]})");
604}
605
606TEST_F(TestFixedShapeTensorType, FixedShapeTensorToString) {
607 auto exact_ext_type = internal::checked_pointer_cast<FixedShapeTensorType>(ext_type_);
608
609 auto ext_type_1 = internal::checked_pointer_cast<FixedShapeTensorType>(
610 fixed_shape_tensor(int16(), {3, 4, 7}));
611 auto ext_type_2 = internal::checked_pointer_cast<FixedShapeTensorType>(
612 fixed_shape_tensor(int32(), {3, 4, 7}, {1, 0, 2}));
613 auto ext_type_3 = internal::checked_pointer_cast<FixedShapeTensorType>(
614 fixed_shape_tensor(int64(), {3, 4, 7}, {}, {"C", "H", "W"}));

Callers 3

TESTFunction · 0.70
TEST_FFunction · 0.70
TESTFunction · 0.70

Calls 15

key_value_metadataFunction · 0.85
RoundtripBatchFunction · 0.85
CompareBatchFunction · 0.85
fixed_shape_tensorFunction · 0.85
ArrayFromJSONFunction · 0.85
WrapFunction · 0.85
fixed_size_listFunction · 0.85
listFunction · 0.85
variable_shape_tensorFunction · 0.85
GetExtensionTypeFunction · 0.85
stridesMethod · 0.80
is_contiguousMethod · 0.80

Tested by

no test coverage detected