Remove redundant classes from modelIR (#1642)
authorEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Wed, 26 Sep 2018 17:22:51 +0000 (20:22 +0300)
committerРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Wed, 26 Sep 2018 17:22:51 +0000 (20:22 +0300)
Remove
 - IndexEnumerator class that duplicates functionality from ShapeInference
 - Redundant interface classes

Signed-off-by: Efimov Alexander <a.efimov@samsung.com>
contrib/nnc/core/modelIR/IndexEnumerator.cpp [deleted file]
contrib/nnc/core/modelIR/IndexRange.cpp [deleted file]
contrib/nnc/core/modelIR/Reader.cpp [deleted file]
contrib/nnc/include/core/modelIR/Accessor.h [deleted file]
contrib/nnc/include/core/modelIR/IndexEnumerator.h [deleted file]
contrib/nnc/include/core/modelIR/IndexRange.h [deleted file]
contrib/nnc/include/core/modelIR/Iterable.h [deleted file]
contrib/nnc/include/core/modelIR/Reader.h [deleted file]
contrib/nnc/include/core/modelIR/Tensor.h
contrib/nnc/include/core/modelIR/TensorUtil.h
contrib/nnc/passes/tflite_frontend/tflite_ir_visitor.cpp

diff --git a/contrib/nnc/core/modelIR/IndexEnumerator.cpp b/contrib/nnc/core/modelIR/IndexEnumerator.cpp
deleted file mode 100644 (file)
index 780d74d..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#include "core/modelIR/IndexEnumerator.h"
-
-#include <cassert>
-
-using nncc::contrib::core::data::Shape;
-
-inline uint32_t axis_of(const Shape &shape, uint32_t cursor)
-{
-  const uint32_t rank = shape.rank();
-  assert(cursor < rank);
-  return rank - cursor - 1;
-}
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-IndexEnumerator::IndexEnumerator(const Shape &shape) : _shape{shape}, _cursor(0)
-{
-  const uint32_t rank = _shape.rank();
-
-  // Initialize _index
-  _index.resize(rank);
-  for (uint32_t axis = 0; axis < rank; ++axis)
-  {
-    _index.at(axis) = 0;
-  }
-
-  // Initialize _cursor
-  for (_cursor = 0; _cursor < rank; ++_cursor)
-  {
-    const auto axis = axis_of(_shape, _cursor);
-
-    if (_index.at(axis) < _shape.dim(axis))
-    {
-      break;
-    }
-  }
-}
-
-void IndexEnumerator::advance(void)
-{
-  const uint32_t rank = _shape.rank();
-
-  // Find axis to be updated
-  while (_cursor < rank)
-  {
-    const auto axis = axis_of(_shape, _cursor);
-
-    if ((_index.at(axis)) + 1 < _shape.dim(axis))
-    {
-      break;
-    }
-
-    ++_cursor;
-  }
-
-  if (_cursor == rank)
-  {
-    return;
-  }
-
-  // Update index
-  _index.at(axis_of(_shape, _cursor)) += 1;
-
-  for (uint32_t pos = 0; pos < _cursor; ++pos)
-  {
-    const auto axis = axis_of(_shape, pos);
-    _index.at(axis) = 0;
-  }
-
-  // Reset cursor
-  _cursor = 0;
-}
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
diff --git a/contrib/nnc/core/modelIR/IndexRange.cpp b/contrib/nnc/core/modelIR/IndexRange.cpp
deleted file mode 100644 (file)
index 4578b8f..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "core/modelIR/IndexRange.h"
-#include "core/modelIR/IndexEnumerator.h"
-
-#include <cassert>
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-IndexRange::IndexRange(const Shape &shape) : _shape(shape)
-{
-  // DO NOTHING
-}
-
-bool IndexRange::member(const Index &index) const
-{
-  if (index.rank() != _shape.rank())
-  {
-    return false;
-  }
-
-  const auto rank = _shape.rank();
-
-  for (uint32_t axis = 0; axis < rank; ++axis)
-  {
-    if (!(index.at(axis) < _shape.dim(axis)))
-    {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-void IndexRange::iterate(const std::function<void(const Index &)> &f) const
-{
-  for (IndexEnumerator e{_shape}; e.valid(); e.advance())
-  {
-    f(e.current());
-  }
-}
-
-IndexRange range(const Shape &shape) { return IndexRange{shape}; }
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
diff --git a/contrib/nnc/core/modelIR/Reader.cpp b/contrib/nnc/core/modelIR/Reader.cpp
deleted file mode 100644 (file)
index 983a71f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#include "core/modelIR/Reader.h"
-
-// DO NOT REMOVE THIS FILE
-//
-// This file is introduced to check the self-completeness of 'Reader.h'
diff --git a/contrib/nnc/include/core/modelIR/Accessor.h b/contrib/nnc/include/core/modelIR/Accessor.h
deleted file mode 100644 (file)
index bdc7511..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _NNC_CORE_LINALG_ACCESSOR_H_
-#define _NNC_CORE_LINALG_ACCESSOR_H_
-
-#include "core/modelIR/Index.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-template <typename T> struct Accessor
-{
-  virtual ~Accessor() = default;
-
-  virtual T &at(const Index &) = 0;
-};
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
-
-#endif // _NNC_CORE_LINALG_ACCESSOR_H__
diff --git a/contrib/nnc/include/core/modelIR/IndexEnumerator.h b/contrib/nnc/include/core/modelIR/IndexEnumerator.h
deleted file mode 100644 (file)
index 9262d36..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#ifndef _NNC_CORE_LINALG_INDEX_ENUMERATE_H_
-#define _NNC_CORE_LINALG_INDEX_ENUMERATE_H_
-
-#include "core/modelIR/Index.h"
-#include "core/modelIR/Shape.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-class IndexEnumerator
-{
-public:
-  explicit IndexEnumerator(const Shape &shape);
-
-public:
-  IndexEnumerator(IndexEnumerator &&) = delete;
-  IndexEnumerator(const IndexEnumerator &) = delete;
-
-public:
-  bool valid(void) const { return _cursor < _shape.rank(); }
-
-public:
-  const Index &current(void) const { return _index; }
-
-public:
-  void advance(void);
-
-private:
-  const Shape _shape;
-  Index _index;
-
-private:
-  uint32_t _cursor;
-};
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
-
-#endif // _NNC_CORE_LINALG_INDEX_ENUMERATE_H_
diff --git a/contrib/nnc/include/core/modelIR/IndexRange.h b/contrib/nnc/include/core/modelIR/IndexRange.h
deleted file mode 100644 (file)
index 32b7567..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef _NNC_CORE_LINALG_INDEX_RANGE_H_
-#define _NNC_CORE_LINALG_INDEX_RANGE_H_
-
-#include "core/modelIR/Index.h"
-#include "core/modelIR/Shape.h"
-
-#include "core/modelIR/Iterable.h"
-
-#include <functional>
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-class IndexRange
-{
-public:
-  explicit IndexRange(const Shape &shape);
-
-public:
-  bool member(const Index &index) const;
-
-public:
-  void iterate(const std::function<void(const Index &)> &) const;
-
-public:
-  Iterable<IndexRange> iterate(void) const { return Iterable<IndexRange>{this}; }
-
-private:
-  const Shape _shape;
-};
-
-IndexRange range(const Shape &shape);
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
-
-#endif // _NNC_CORE_LINALG_INDEX_RANGE_H_
diff --git a/contrib/nnc/include/core/modelIR/Iterable.h b/contrib/nnc/include/core/modelIR/Iterable.h
deleted file mode 100644 (file)
index 3722308..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef _NNC_CORE_LINALG_ITERABLE_H_
-#define _NNC_CORE_LINALG_ITERABLE_H_
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-template<typename T>
-class Iterable
-{
-public:
-  Iterable(const T *ptr) : _ptr{ptr}
-  {
-    // DO NOTHING
-  }
-
-public:
-  const T &get(void) const
-  { return *_ptr; }
-
-private:
-  const T *const _ptr;
-};
-
-template<typename T, typename Callable>
-const Iterable<T> &operator<<(const Iterable<T> &it, Callable cb)
-{
-  it.get().iterate(cb);
-  return it;
-}
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
-
-#endif // _NNC_CORE_LINALG_ITERABLE_H_
diff --git a/contrib/nnc/include/core/modelIR/Reader.h b/contrib/nnc/include/core/modelIR/Reader.h
deleted file mode 100644 (file)
index 92b0b44..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef _NNC_CORE_LINALG_READER_H_
-#define _NNC_CORE_LINALG_READER_H_
-
-#include "core/modelIR/Index.h"
-
-namespace nncc
-{
-namespace contrib
-{
-namespace core
-{
-namespace data
-{
-
-template <typename T> struct Reader
-{
-  virtual ~Reader() = default;
-
-  virtual T at(const Index &) const = 0;
-};
-
-} // namespace data
-} // namespace core
-} // namespace contrib
-} // namespace nncc
-
-#endif // _NNC_CORE_LINALG_READER_H_
index f6b1492..fb587f2 100644 (file)
@@ -1,8 +1,6 @@
 #pragma once
 
 #include "core/modelIR/Shape.h"
-#include "core/modelIR/Accessor.h"
-#include "core/modelIR/Reader.h"
 
 #include "core/modelIR/ExternalRegion.h"
 
@@ -18,18 +16,18 @@ namespace data
 {
 
 template<typename T>
-class Tensor final : public Accessor<T>, public Reader<T> {
+class Tensor final{
  public:
   Tensor() = delete;
 
   explicit Tensor(const ADT::TensorVariant &t) : _proxy(t), _shape(t.getShape()) {
   }
 
-  T at(const Index &id) const override {
+  T at(const Index &id) const {
     return *reinterpret_cast<T *>(this->_proxy.at(id));
   }
 
-  T &at(const Index &id) override {
+  T &at(const Index &id) {
     return *reinterpret_cast<T *>(this->_proxy.at(id));
   }
 
index e17b5a2..a1ca3d5 100644 (file)
@@ -7,7 +7,7 @@
 #include "core/modelIR/TensorVariant.h"
 #include "core/modelIR/Shape.h"
 #include "core/modelIR/Index.h"
-#include "core/modelIR/IndexRange.h"
+#include "core/modelIR/ShapeRange.h"
 
 namespace nncc
 {
@@ -29,7 +29,6 @@ static std::shared_ptr <TensorVariant>
 transposeTensor(std::shared_ptr <TensorVariant> tensor)
 {
   using nncc::contrib::core::data::Index;
-  using nncc::contrib::core::data::IndexRange;
 
   const Shape &inShape = tensor->getShape();
   Shape targetShape{inShape.dim(Ints)...};
@@ -53,7 +52,8 @@ transposeTensor(std::shared_ptr <TensorVariant> tensor)
                 convertedTensor->getElementSize());
   };
 
-  IndexRange(tensor->getShape()).iterate() << swap;
+  for (Index idx: ShapeRange(tensor->getShape()))
+    swap(idx);
 
   return convertedTensor;
 }
index 3a664d6..67d8fbb 100644 (file)
@@ -5,7 +5,6 @@
 #include "pass/PassException.h"
 #include "core/modelIR/Shape.h"
 #include "core/modelIR/Index.h"
-#include "core/modelIR/IndexRange.h"
 #include "core/modelIR/TensorUtil.h"
 #include "core/modelIR/operations/variable_op.h"
 
@@ -25,7 +24,6 @@ namespace tflite
 {
 
 using nncc::contrib::core::data::Index;
-using nncc::contrib::core::data::IndexRange;
 using VariableOp = nncc::contrib::core::IR::model::ops::VariableOp;
 using nncc::contrib::core::data::Shape;
 using nncc::contrib::core::data::util::transposeTensor;