+++ /dev/null
-#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
+++ /dev/null
-#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
+++ /dev/null
-#include "core/modelIR/Reader.h"
-
-// DO NOT REMOVE THIS FILE
-//
-// This file is introduced to check the self-completeness of 'Reader.h'
+++ /dev/null
-#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__
+++ /dev/null
-#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 ¤t(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_
+++ /dev/null
-#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_
+++ /dev/null
-#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_
+++ /dev/null
-#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_
#pragma once
#include "core/modelIR/Shape.h"
-#include "core/modelIR/Accessor.h"
-#include "core/modelIR/Reader.h"
#include "core/modelIR/ExternalRegion.h"
{
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));
}
#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
{
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)...};
convertedTensor->getElementSize());
};
- IndexRange(tensor->getShape()).iterate() << swap;
+ for (Index idx: ShapeRange(tensor->getShape()))
+ swap(idx);
return convertedTensor;
}
#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"
{
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;