mindspore/tests/ut/cpp/ops/test_ops_floor.cc

61 lines
2.0 KiB
C++
Raw Normal View History

2020-12-26 14:58:47 +08:00
/**
2021-02-03 19:47:53 +08:00
* Copyright 2021 Huawei Technologies Co., Ltd
2020-12-26 14:58:47 +08:00
*
* 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 <vector>
#include <memory>
#include "common/common_test.h"
2021-02-03 19:47:53 +08:00
#include "ops/floor.h"
2020-12-26 14:58:47 +08:00
#include "ir/dtype/type.h"
2021-02-03 19:47:53 +08:00
#include "ir/value.h"
2020-12-26 14:58:47 +08:00
#include "abstract/dshape.h"
#include "utils/tensor_construct_utils.h"
2021-02-03 19:47:53 +08:00
2020-12-26 14:58:47 +08:00
namespace mindspore {
2021-02-03 19:47:53 +08:00
namespace ops {
class TestFloor : public UT::Common {
2020-12-26 14:58:47 +08:00
public:
2021-02-03 19:47:53 +08:00
TestFloor() {}
2020-12-26 14:58:47 +08:00
void SetUp() {}
void TearDown() {}
};
2021-02-03 19:47:53 +08:00
TEST_F(TestFloor, test_ops_floor1) {
auto floor = std::make_shared<Floor>();
floor->Init();
auto tensor_x = TensorConstructUtils::CreateOnesTensor(kNumberTypeFloat32, std::vector<int64_t>{2, 2});
2020-12-28 17:25:32 +08:00
MS_EXCEPTION_IF_NULL(tensor_x);
2021-02-03 19:47:53 +08:00
auto abstract = floor->Infer({tensor_x->ToAbstract()});
MS_EXCEPTION_IF_NULL(abstract);
EXPECT_EQ(abstract->isa<abstract::AbstractTensor>(), true);
auto shape_ptr = abstract->BuildShape();
2020-12-28 17:25:32 +08:00
MS_EXCEPTION_IF_NULL(shape_ptr);
EXPECT_EQ(shape_ptr->isa<abstract::Shape>(), true);
2021-02-03 19:47:53 +08:00
auto shape = shape_ptr->cast<abstract::ShapePtr>();
MS_EXCEPTION_IF_NULL(shape);
auto shape_vec = shape->shape();
auto type = abstract->BuildType();
2020-12-28 17:25:32 +08:00
MS_EXCEPTION_IF_NULL(type);
EXPECT_EQ(type->isa<TensorType>(), true);
auto tensor_type = type->cast<TensorTypePtr>();
MS_EXCEPTION_IF_NULL(tensor_type);
2021-02-03 19:47:53 +08:00
auto data_type = tensor_type->element();
MS_EXCEPTION_IF_NULL(data_type);
EXPECT_EQ(data_type->type_id(), kNumberTypeFloat32);
EXPECT_EQ(shape_vec.size(), 2);
EXPECT_EQ(shape_vec[0], 2);
EXPECT_EQ(shape_vec[1], 2);
2020-12-26 14:58:47 +08:00
}
2021-02-03 19:47:53 +08:00
} // namespace ops
2020-12-26 14:58:47 +08:00
} // namespace mindspore