/** * Copyright 2020 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 "common/common.h" #include "minddata/dataset/text/kernels/sliding_window_op.h" #include "utils/log_adapter.h" using namespace mindspore::dataset; using mindspore::MsLogLevel::INFO; using mindspore::ExceptionType::NoExceptionType; using mindspore::LogStream; class MindDataTestSlidingWindowOp : public UT::Common { protected: MindDataTestSlidingWindowOp() {} }; TEST_F(MindDataTestSlidingWindowOp, Compute) { MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->Compute."; std::vector strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; TensorShape shape({static_cast(strings.size())}); std::shared_ptr input = std::make_shared(strings, shape); std::shared_ptr output; std::unique_ptr op(new SlidingWindowOp(3, 0)); Status s = op->Compute(input, &output); std::vector out = {"one", "two", "three", "two", "three", "four", "three", "four", "five", "four", "five", "six", "five", "six", "seven", "six", "seven", "eight"}; std::shared_ptr expected = std::make_shared(out, TensorShape({6, 3})); ASSERT_TRUE(output->shape() == expected->shape()); ASSERT_TRUE(output->type() == expected->type()); MS_LOG(DEBUG) << *output << std::endl; MS_LOG(DEBUG) << *expected << std::endl; ASSERT_TRUE(*output == *expected); MS_LOG(INFO) << "MindDataTestSlidingWindowOp end."; } TEST_F(MindDataTestSlidingWindowOp, OutputShape) { MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->OutputShape."; std::vector strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; TensorShape shape({static_cast(strings.size())}); std::shared_ptr input = std::make_shared(strings, shape); std::vector input_shape = {input->shape()}; std::vector output_shape = {TensorShape({})}; std::unique_ptr op(new SlidingWindowOp(3, 0)); Status s = op->OutputShape(input_shape, output_shape); MS_LOG(DEBUG) << "input_shape" << input_shape[0]; MS_LOG(DEBUG) << "output_shape" << output_shape[0]; ASSERT_TRUE(output_shape[0] == TensorShape({6, 3})); MS_LOG(INFO) << "MindDataTestSlidingWindowOp end."; }