From: 박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 18 Apr 2019 07:46:42 +0000 (+0900) Subject: [nnkit] Use IndexEnumerator instead of IndexRange (#3310) X-Git-Tag: nncc_backup~709 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=faa8b032dbfa8831f2b48d6ee5808e61ff2a2b8b;p=platform%2Fcore%2Fml%2Fnnfw.git [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 --- 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);