/** * Copyright 2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include "common/common_test.h" #include "ops/unsqueeze.h" #include "ir/dtype/type.h" #include "ir/value.h" #include "abstract/dshape.h" #include "utils/tensor_construct_utils.h" namespace mindspore { namespace ops { class TestUnsqueeze : public UT::Common { public: TestUnsqueeze() {} void SetUp() {} void TearDown() {} }; /*TEST_F(TestUnsqueeze, test_unsqueeze_1) { auto unsqueeze = std::make_shared(); std::vector axis = {}; unsqueeze->Init(axis); auto tensor_x = std::make_shared(kNumberTypeFloat16, std::vector{1, 3, 2}); MS_EXCEPTION_IF_NULL(tensor_x); auto tensor_x_data = reinterpret_cast(tensor_x->data_c()); *tensor_x_data = 1; tensor_x_data++; *tensor_x_data = 2; tensor_x_data++; *tensor_x_data = 3; tensor_x_data++; *tensor_x_data = 4; tensor_x_data++; *tensor_x_data = 5; tensor_x_data++; *tensor_x_data = 6; tensor_x_data++; auto abstract = unsqueeze->Infer({tensor_x->ToAbstract()}); MS_EXCEPTION_IF_NULL(abstract); EXPECT_EQ(abstract->isa(), true); auto shape_ptr = abstract->BuildShape(); MS_EXCEPTION_IF_NULL(shape_ptr); EXPECT_EQ(shape_ptr->isa(), true); auto shape = shape_ptr->cast(); MS_EXCEPTION_IF_NULL(shape); auto shape_vec = shape->shape(); EXPECT_EQ(shape_vec.size(), 2); EXPECT_EQ(shape_vec[0], 3); EXPECT_EQ(shape_vec[1], 2); auto type = abstract->BuildType(); MS_EXCEPTION_IF_NULL(type); EXPECT_EQ(type->isa(), true); auto tensor_type = type->cast(); MS_EXCEPTION_IF_NULL(tensor_type); auto data_type = tensor_type->element(); MS_EXCEPTION_IF_NULL(data_type); EXPECT_EQ(data_type->type_id(), kNumberTypeFloat16); } */ TEST_F(TestUnsqueeze, test_unsqueeze_1) { auto unsqueeze = std::make_shared(); std::vector axis = {1, 2}; unsqueeze->Init(axis); auto tensor_x = std::make_shared(kNumberTypeFloat32, std::vector{1, 3}); MS_EXCEPTION_IF_NULL(tensor_x); auto tensor_x_data = reinterpret_cast(tensor_x->data_c()); *tensor_x_data = 1; tensor_x_data++; *tensor_x_data = 2; tensor_x_data++; *tensor_x_data = 3; tensor_x_data++; auto abstract = unsqueeze->Infer({tensor_x->ToAbstract()}); MS_EXCEPTION_IF_NULL(abstract); EXPECT_EQ(abstract->isa(), true); auto shape_ptr = abstract->BuildShape(); MS_EXCEPTION_IF_NULL(shape_ptr); EXPECT_EQ(shape_ptr->isa(), true); auto shape = shape_ptr->cast(); MS_EXCEPTION_IF_NULL(shape); auto shape_vec = shape->shape(); EXPECT_EQ(shape_vec.size(), 4); EXPECT_EQ(shape_vec[0], 1); EXPECT_EQ(shape_vec[1], 1); EXPECT_EQ(shape_vec[2], 1); EXPECT_EQ(shape_vec[3], 3); auto type = abstract->BuildType(); MS_EXCEPTION_IF_NULL(type); EXPECT_EQ(type->isa(), true); auto tensor_type = type->cast(); MS_EXCEPTION_IF_NULL(tensor_type); auto data_type = tensor_type->element(); MS_EXCEPTION_IF_NULL(data_type); EXPECT_EQ(data_type->type_id(), kNumberTypeFloat32); } } // namespace ops } // namespace mindspore