From faa8b032dbfa8831f2b48d6ee5808e61ff2a2b8b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/On-Device=20Lab=28SR=29/Staff?= =?utf8?q?=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 18 Apr 2019 16:46:42 +0900 Subject: [PATCH] [nnkit] Use IndexEnumerator instead of IndexRange (#3310) This commit replaces all the occurrences of IndexRange (range function) in nnkit code with IndexEnumerator. Signed-off-by: Jonghyun Park --- contrib/nnkit/actions/HDF5/Export.cpp | 10 ++++++---- contrib/nnkit/actions/HDF5/Import.cpp | 10 ++++++---- contrib/nnkit/actions/builtin/Randomize.cpp | 10 ++++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/contrib/nnkit/actions/HDF5/Export.cpp b/contrib/nnkit/actions/HDF5/Export.cpp index 3bc08f7..54d0e9e 100644 --- a/contrib/nnkit/actions/HDF5/Export.cpp +++ b/contrib/nnkit/actions/HDF5/Export.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include @@ -60,15 +60,17 @@ public: float *data = new float[nncc::core::ADT::tensor::num_elements(shape)]; - using nncc::core::ADT::tensor::range; using nncc::core::ADT::tensor::Index; + using nncc::core::ADT::tensor::IndexEnumerator; using nncc::core::ADT::tensor::LexicalLayout; LexicalLayout layout{}; - range(shape).iterate() << [data, &t, &shape, &layout](const Index &i) { + for (IndexEnumerator e{shape}; e.valid(); e.advance()) + { + auto i = e.current(); data[layout.offset(shape, i)] = t.at(i); - }; + } dataset.write(data, H5::PredType::NATIVE_FLOAT); diff --git a/contrib/nnkit/actions/HDF5/Import.cpp b/contrib/nnkit/actions/HDF5/Import.cpp index 0353d0e..7641b64 100644 --- a/contrib/nnkit/actions/HDF5/Import.cpp +++ b/contrib/nnkit/actions/HDF5/Import.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include @@ -60,15 +60,17 @@ public: dataset.read(buffer.data(), H5::PredType::NATIVE_FLOAT); - using nncc::core::ADT::tensor::range; using nncc::core::ADT::tensor::Index; + using nncc::core::ADT::tensor::IndexEnumerator; using nncc::core::ADT::tensor::LexicalLayout; LexicalLayout layout{}; - range(shape).iterate() << [&buffer, &t, &shape, &layout](const Index &i) { + for (IndexEnumerator e{shape}; e.valid(); e.advance()) + { + auto i = e.current(); t.at(i) = buffer[layout.offset(shape, i)]; - }; + } }; try diff --git a/contrib/nnkit/actions/builtin/Randomize.cpp b/contrib/nnkit/actions/builtin/Randomize.cpp index 2957ed8..9b023ef 100644 --- a/contrib/nnkit/actions/builtin/Randomize.cpp +++ b/contrib/nnkit/actions/builtin/Randomize.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include #include @@ -37,11 +37,13 @@ struct RandomizeAction final : public nnkit::Action using nncc::core::ADT::tensor::Accessor; auto fn = [&dist, &rand](const TensorContext &ctx, uint32_t n, Accessor &t) { - using nncc::core::ADT::tensor::range; using nncc::core::ADT::tensor::Index; + using nncc::core::ADT::tensor::IndexEnumerator; - range(ctx.shape(n)).iterate() - << [&t, &dist, &rand](const Index &i) { t.at(i) = dist(rand); }; + for (IndexEnumerator e{ctx.shape(n)}; e.valid(); e.advance()) + { + t.at(e.current()) = dist(rand); + } }; ctx.getMutableFloatTensor(n, fn); -- 2.7.4