[nnkit] Use IndexEnumerator instead of IndexRange (#3310)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 18 Apr 2019 07:46:42 +0000 (16:46 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 18 Apr 2019 07:46:42 +0000 (16:46 +0900)
This commit replaces all the occurrences of IndexRange (range function)
in nnkit code with IndexEnumerator.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/nnkit/actions/HDF5/Export.cpp
contrib/nnkit/actions/HDF5/Import.cpp
contrib/nnkit/actions/builtin/Randomize.cpp

index 3bc08f7..54d0e9e 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <nnkit/Action.h>
 
-#include <nncc/core/ADT/tensor/IndexRange.h>
+#include <nncc/core/ADT/tensor/IndexEnumerator.h>
 #include <nncc/core/ADT/tensor/LexicalLayout.h>
 
 #include <H5Cpp.h>
@@ -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);
 
index 0353d0e..7641b64 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <nnkit/Action.h>
 
-#include <nncc/core/ADT/tensor/IndexRange.h>
+#include <nncc/core/ADT/tensor/IndexEnumerator.h>
 #include <nncc/core/ADT/tensor/LexicalLayout.h>
 
 #include <H5Cpp.h>
@@ -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
index 2957ed8..9b023ef 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <nnkit/Action.h>
 
-#include <nncc/core/ADT/tensor/IndexRange.h>
+#include <nncc/core/ADT/tensor/IndexEnumerator.h>
 
 #include <chrono>
 #include <random>
@@ -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<float> &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);