You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sliding_window_op_test.cc 2.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "common/common.h"
  17. #include "minddata/dataset/text/kernels/sliding_window_op.h"
  18. #include "utils/log_adapter.h"
  19. using namespace mindspore::dataset;
  20. using mindspore::MsLogLevel::INFO;
  21. using mindspore::ExceptionType::NoExceptionType;
  22. using mindspore::LogStream;
  23. class MindDataTestSlidingWindowOp : public UT::Common {
  24. protected:
  25. MindDataTestSlidingWindowOp() {}
  26. };
  27. TEST_F(MindDataTestSlidingWindowOp, Compute) {
  28. MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->Compute.";
  29. std::vector<std::string> strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
  30. TensorShape shape({static_cast<dsize_t>(strings.size())});
  31. std::shared_ptr<Tensor> input;
  32. Tensor::CreateFromVector(strings, shape, &input);
  33. std::shared_ptr<Tensor> output;
  34. std::unique_ptr<SlidingWindowOp> op(new SlidingWindowOp(3, 0));
  35. Status s = op->Compute(input, &output);
  36. std::vector<std::string> out = {"one", "two", "three", "two", "three", "four", "three", "four", "five",
  37. "four", "five", "six", "five", "six", "seven", "six", "seven", "eight"};
  38. std::shared_ptr<Tensor> expected;
  39. Tensor::CreateFromVector(out, TensorShape({6, 3}), &expected);
  40. ASSERT_TRUE(output->shape() == expected->shape());
  41. ASSERT_TRUE(output->type() == expected->type());
  42. MS_LOG(DEBUG) << *output << std::endl;
  43. MS_LOG(DEBUG) << *expected << std::endl;
  44. ASSERT_TRUE(*output == *expected);
  45. MS_LOG(INFO) << "MindDataTestSlidingWindowOp end.";
  46. }
  47. TEST_F(MindDataTestSlidingWindowOp, OutputShape) {
  48. MS_LOG(INFO) << "Doing MindDataTestSlidingWindowOp->OutputShape.";
  49. std::vector<std::string> strings = {"one", "two", "three", "four", "five", "six", "seven", "eight"};
  50. TensorShape shape({static_cast<dsize_t>(strings.size())});
  51. std::shared_ptr<Tensor> input;
  52. Tensor::CreateFromVector(strings, shape, &input);
  53. std::vector<TensorShape> input_shape = {input->shape()};
  54. std::vector<TensorShape> output_shape = {TensorShape({})};
  55. std::unique_ptr<SlidingWindowOp> op(new SlidingWindowOp(3, 0));
  56. Status s = op->OutputShape(input_shape, output_shape);
  57. MS_LOG(DEBUG) << "input_shape" << input_shape[0];
  58. MS_LOG(DEBUG) << "output_shape" << output_shape[0];
  59. ASSERT_TRUE(output_shape[0] == TensorShape({6, 3}));
  60. MS_LOG(INFO) << "MindDataTestSlidingWindowOp end.";
  61. }