From 1e7f46c9988838c513f8898816571ba3c1b24511 Mon Sep 17 00:00:00 2001 From: liyong Date: Fri, 23 Oct 2020 11:32:10 +0800 Subject: [PATCH] fix unorder_map hash --- .../dataset/kernels/data/data_utils.cc | 29 +++++++++++++++++-- .../dataset/kernels/data/data_utils.h | 4 --- .../dataset/kernels/data/unique_op.cc | 2 -- tests/ut/python/dataset/test_unique_op.py | 3 +- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc index 8a664620705..730cb0a39a3 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc @@ -707,11 +707,37 @@ Status TensorVectorToBatchTensor(const std::vector> &inp return Status::OK(); } -#ifndef ENABLE_ANDROID template struct UniqueOpHashMap { using map_type = std::unordered_map; }; +#ifndef ENABLE_ANDROID +template <> +struct UniqueOpHashMap { + using map_type = std::unordered_map; +}; + +#else +struct gn_hash { + size_t operator()(const float16 &f) const { return static_cast(f); } +}; + +template <> +struct UniqueOpHashMap { + using map_type = std::unordered_map; +}; + +#endif + +template <> +struct UniqueOpHashMap { + using map_type = std::unordered_map; +}; + +template <> +struct UniqueOpHashMap { + using map_type = std::unordered_map; +}; template Status UniqueHelper(const std::shared_ptr &input, std::shared_ptr *output, @@ -780,7 +806,6 @@ Status Unique(const std::shared_ptr &input, std::shared_ptr *out } return Status::OK(); } -#endif } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h index 0de1258c6a9..e46df4bbd17 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h @@ -19,9 +19,7 @@ #include #include #include -#ifndef ENABLE_ANDROID #include -#endif #include "minddata/dataset/core/constants.h" #include "minddata/dataset/core/cv_tensor.h" #include "minddata/dataset/core/data_type.h" @@ -179,7 +177,6 @@ Status BatchTensorToTensorVector(const std::shared_ptr &input, std::vect /// \return Status ok/error Status TensorVectorToBatchTensor(const std::vector> &input, std::shared_ptr *output); -#ifndef ENABLE_ANDROID /// Helper method that uniques the input tensor /// @tparam T type of the tensor /// \param input[in] input 1d tensor @@ -200,7 +197,6 @@ Status UniqueHelper(const std::shared_ptr &input, std::shared_ptr &input, std::shared_ptr *output, std::shared_ptr *output_idx, std::shared_ptr *output_cnt); -#endif } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/unique_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/data/unique_op.cc index 4915f88220c..1dea5f9e1d1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/unique_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/unique_op.cc @@ -23,7 +23,6 @@ namespace mindspore { namespace dataset { Status UniqueOp::Compute(const TensorRow &input, TensorRow *output) { -#ifndef ENABLE_ANDROID IO_CHECK_VECTOR(input, output); CHECK_FAIL_RETURN_UNEXPECTED(input.size() == 1, "Input should be one tensor"); @@ -47,7 +46,6 @@ Status UniqueOp::Compute(const TensorRow &input, TensorRow *output) { output->push_back(out); output->push_back(out_idx); output->push_back(out_cnt); -#endif return Status::OK(); } } // namespace dataset diff --git a/tests/ut/python/dataset/test_unique_op.py b/tests/ut/python/dataset/test_unique_op.py index a40faa3a028..098c04fd704 100644 --- a/tests/ut/python/dataset/test_unique_op.py +++ b/tests/ut/python/dataset/test_unique_op.py @@ -31,8 +31,7 @@ def compare(array, res, idx, cnt): np.testing.assert_array_equal(idx, d["y"]) np.testing.assert_array_equal(cnt, d["z"]) -# the test function name code will be start with 'test' later -def duplicate_basics(): +def test_duplicate_basics(): compare([0, 1, 2, 1, 2, 3], np.array([0, 1, 2, 3]), np.array([0, 1, 2, 1, 2, 3]), np.array([1, 2, 2, 1])) compare([0.0, 1.0, 2.0, 1.0, 2.0, 3.0], np.array([0.0, 1.0, 2.0, 3.0]),