summaryrefslogtreecommitdiff
path: root/include/util/tensor
diff options
context:
space:
mode:
Diffstat (limited to 'include/util/tensor')
-rw-r--r--include/util/tensor/Comparator.h65
-rw-r--r--include/util/tensor/Diff.h51
-rw-r--r--include/util/tensor/Index.h69
-rw-r--r--include/util/tensor/IndexEnumerator.h101
-rw-r--r--include/util/tensor/IndexFormatter.h52
-rw-r--r--include/util/tensor/IndexIterator.h70
-rw-r--r--include/util/tensor/NonIncreasingStride.h61
-rw-r--r--include/util/tensor/Object.h72
-rw-r--r--include/util/tensor/Reader.h40
-rw-r--r--include/util/tensor/Shape.h84
-rw-r--r--include/util/tensor/Zipper.h69
11 files changed, 0 insertions, 734 deletions
diff --git a/include/util/tensor/Comparator.h b/include/util/tensor/Comparator.h
deleted file mode 100644
index f0ab4ab20..000000000
--- a/include/util/tensor/Comparator.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_COMPARATOR_H__
-#define __NNFW_UTIL_TENSOR_COMPARATOR_H__
-
-#include "util/tensor/Index.h"
-#include "util/tensor/Shape.h"
-#include "util/tensor/Reader.h"
-#include "util/tensor/Diff.h"
-
-#include <functional>
-
-#include <vector>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-class Comparator
-{
-public:
- Comparator(const std::function<bool (float lhs, float rhs)> &fn) : _compare_fn{fn}
- {
- // DO NOTHING
- }
-
-public:
- struct Observer
- {
- virtual void notify(const Index &index, float expected, float obtained) = 0;
- };
-
-public:
- // NOTE Observer should live longer than comparator
- std::vector<Diff<float>> compare(const Shape &shape,
- const Reader<float> &expected,
- const Reader<float> &obtained,
- Observer *observer = nullptr) const;
-
-private:
- std::function<bool (float lhs, float rhs)> _compare_fn;
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_COMPARATOR_H__
diff --git a/include/util/tensor/Diff.h b/include/util/tensor/Diff.h
deleted file mode 100644
index 25a9bafcf..000000000
--- a/include/util/tensor/Diff.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_DIFF_H__
-#define __NNFW_UTIL_TENSOR_DIFF_H__
-
-#include "util/tensor/Index.h"
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-template<typename T> struct Diff
-{
- Index index;
-
- T expected;
- T obtained;
-
- Diff(const Index &i) : index(i)
- {
- // DO NOTHING
- }
-
- Diff(const Index &i, const T &e, const T &o) : index(i), expected{e}, obtained{o}
- {
- // DO NOTHING
- }
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_DIFF_H__
diff --git a/include/util/tensor/Index.h b/include/util/tensor/Index.h
deleted file mode 100644
index bc41d3c8e..000000000
--- a/include/util/tensor/Index.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_INDEX_H__
-#define __NNFW_UTIL_TENSOR_INDEX_H__
-
-#include <cstdint>
-#include <cstddef>
-
-#include <vector>
-#include <initializer_list>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-struct Index
-{
-public:
- Index(size_t rank) { _offsets.resize(rank); }
-
-public:
- Index(std::initializer_list<int32_t> offsets) : _offsets{offsets}
- {
- // DO NOTHING
- }
-
-public:
- size_t rank(void) const { return _offsets.size(); }
-
-public:
- int32_t at(size_t n) const { return _offsets.at(n); }
- int32_t &at(size_t n) { return _offsets.at(n); }
-
-private:
- std::vector<int32_t> _offsets;
-};
-
-// This is used to convert NNAPI tensor index to ARM tensor index or vice versa
-inline static Index copy_reverse(const Index &origin)
-{
- size_t rank = origin.rank();
- Index target(rank);
- for (int i = 0; i < rank; i++)
- target.at(i) = origin.at(rank-1 -i);
- return target;
-}
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_INDEX_H__
diff --git a/include/util/tensor/IndexEnumerator.h b/include/util/tensor/IndexEnumerator.h
deleted file mode 100644
index 30325cbfa..000000000
--- a/include/util/tensor/IndexEnumerator.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_INDEX_ENUMERATOR_H__
-#define __NNFW_UTIL_TENSOR_INDEX_ENUMERATOR_H__
-
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-class IndexEnumerator
-{
-public:
- explicit IndexEnumerator(const Shape &shape) : _shape(shape), _index(shape.rank()), _cursor(0)
- {
- const size_t rank = _shape.rank();
-
- for (size_t axis = 0; axis < rank; ++axis)
- {
- _index.at(axis) = 0;
- }
-
- for (_cursor = 0; _cursor < rank; ++_cursor)
- {
- if (_index.at(_cursor) < _shape.dim(_cursor))
- {
- break;
- }
- }
- }
-
-public:
- IndexEnumerator(IndexEnumerator &&) = delete;
- IndexEnumerator(const IndexEnumerator &) = delete;
-
-public:
- bool valid(void) const { return _cursor < _shape.rank(); }
-
-public:
- const Index &curr(void) const { return _index; }
-
-public:
- void advance(void)
- {
- const size_t rank = _shape.rank();
-
- // Find axis to be updated
- while((_cursor < rank) && !(_index.at(_cursor) + 1 < _shape.dim(_cursor)))
- {
- ++_cursor;
- }
-
- if(_cursor == rank)
- {
- return;
- }
-
- // Update index
- _index.at(_cursor) += 1;
-
- for (size_t axis = 0; axis < _cursor; ++axis)
- {
- _index.at(axis) = 0;
- }
-
- // Update cursor
- _cursor = 0;
- }
-
-public:
- const Shape _shape;
-
-private:
- size_t _cursor;
- Index _index;
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_INDEX_ENUMERATOR_H__
diff --git a/include/util/tensor/IndexFormatter.h b/include/util/tensor/IndexFormatter.h
deleted file mode 100644
index 8014a42b6..000000000
--- a/include/util/tensor/IndexFormatter.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_INDEX_FORMATTER_H__
-#define __NNFW_UTIL_TENSOR_INDEX_FORMATTER_H__
-
-#include "util/tensor/Index.h"
-
-#include <ostream>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-class IndexFormatter
-{
-public:
- IndexFormatter(const nnfw::util::tensor::Index &index) : _index(index)
- {
- // DO NOTHING
- }
-
-public:
- const nnfw::util::tensor::Index &index(void) const { return _index; }
-
-private:
- const nnfw::util::tensor::Index &_index;
-};
-
-std::ostream &operator<<(std::ostream &os, const IndexFormatter &fmt);
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_INDEX_FORMATTER_H__
diff --git a/include/util/tensor/IndexIterator.h b/include/util/tensor/IndexIterator.h
deleted file mode 100644
index cbe895166..000000000
--- a/include/util/tensor/IndexIterator.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_INDEX_ITERATOR_H__
-#define __NNFW_UTIL_TENSOR_INDEX_ITERATOR_H__
-
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
-#include "util/tensor/IndexEnumerator.h"
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-class IndexIterator
-{
-public:
- IndexIterator(const Shape &shape) : _shape(shape)
- {
- // DO NOTHING
- }
-
-public:
- // Allow move, but disallow copy
- IndexIterator(IndexIterator &&) = default;
- IndexIterator(const IndexIterator &) = delete;
-
-public:
- template <typename Callable> IndexIterator &iter(Callable fn)
- {
- for (IndexEnumerator e{_shape}; e.valid(); e.advance())
- {
- fn(e.curr());
- }
-
- return (*this);
- }
-
-private:
- const Shape &_shape;
-};
-
-inline IndexIterator iterate(const Shape &shape) { return IndexIterator{shape}; }
-
-template <typename Callable> IndexIterator &operator<<(IndexIterator &&it, Callable cb)
-{
- return it.iter(cb);
-}
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_INDEX_ITERATOR_H__
diff --git a/include/util/tensor/NonIncreasingStride.h b/include/util/tensor/NonIncreasingStride.h
deleted file mode 100644
index ff013ffa2..000000000
--- a/include/util/tensor/NonIncreasingStride.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_NON_INCREASING_STRIDE_H__
-#define __NNFW_UTIL_TENSOR_NON_INCREASING_STRIDE_H__
-
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
-
-#include <vector>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-// As its name suggests, stride[N-1] >= stride[N] holds for all N < rank in NonIncreasingStride.
-class NonIncreasingStride
-{
-public:
- void init(const Shape &shape)
- {
- _stride.resize(shape.rank());
- _stride.at(shape.rank() - 1) = 1;
-
- for (uint32_t axis = shape.rank() - 1; axis > 0; --axis)
- {
- _stride.at(axis - 1) = _stride.at(axis) * shape.dim(axis);
- }
- }
-
-public:
- uint32_t at(uint32_t axis) const { return _stride.at(axis); }
-
-public:
- uint32_t offset(const Index &index) const;
-
-private:
- std::vector<uint32_t> _stride;
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_NON_INCREASING_STRIDE_H__
diff --git a/include/util/tensor/Object.h b/include/util/tensor/Object.h
deleted file mode 100644
index 7afd089ea..000000000
--- a/include/util/tensor/Object.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_OBJECT_H__
-#define __NNFW_UTIL_TENSOR_OBJECT_H__
-
-#include "util/tensor/Shape.h"
-#include "util/tensor/Index.h"
-#include "util/tensor/IndexIterator.h"
-#include "util/tensor/NonIncreasingStride.h"
-#include "util/tensor/Reader.h"
-
-#include <vector>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-template <typename T> class Object final : public Reader<T>
-{
-public:
- using Generator = std::function<T(const Shape &shape, const Index &index)>;
-
-public:
- Object(const Shape &shape, const Generator &fn) : _shape{shape}
- {
- // Set 'stride'
- _stride.init(shape);
-
- // Pre-allocate buffer
- _values.resize(_shape.dim(0) * _stride.at(0));
-
- // Set 'value'
- iterate(_shape) <<
- [this, &fn](const Index &index) { _values.at(_stride.offset(index)) = fn(_shape, index); };
- }
-
-public:
- const Shape &shape(void) const { return _shape; }
-
-public:
- T at(const Index &index) const override { return _values.at(_stride.offset(index)); }
-
-private:
- Shape _shape;
- NonIncreasingStride _stride;
-
-private:
- std::vector<T> _values;
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_FEATURE_OBJECT_H__
diff --git a/include/util/tensor/Reader.h b/include/util/tensor/Reader.h
deleted file mode 100644
index 654214880..000000000
--- a/include/util/tensor/Reader.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_READER_H__
-#define __NNFW_UTIL_TENSOR_READER_H__
-
-#include "util/tensor/Index.h"
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-template <typename T> struct Reader
-{
- virtual ~Reader() = default;
-
- virtual T at(const Index &index) const = 0;
-};
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_READER_H__
diff --git a/include/util/tensor/Shape.h b/include/util/tensor/Shape.h
deleted file mode 100644
index a4401c1ed..000000000
--- a/include/util/tensor/Shape.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_SHAPE_H__
-#define __NNFW_UTIL_TENSOR_SHAPE_H__
-
-#include <cstdint>
-#include <cstddef>
-#include <deque>
-#include <initializer_list>
-#include <ostream>
-#include <string>
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-class Shape
-{
-public:
- Shape(size_t rank) { _dimensions.resize(rank); }
-
-public:
- Shape(const std::initializer_list<int32_t> &dimensions) : _dimensions{dimensions}
- {
- // DO NOTHING
- }
-
- Shape(const Shape &origin) = default;
-
-public:
- void prepend(int32_t d) { _dimensions.emplace_front(d); }
- void append(int32_t d) { _dimensions.emplace_back(d); }
-
-public:
- size_t rank(void) const { return _dimensions.size(); }
-
-public:
- int32_t dim(size_t n) const { return _dimensions.at(n); }
- int32_t &dim(size_t n) { return _dimensions.at(n); }
-
-public:
- size_t element_nums() const
- {
- size_t nums = 1;
- for (auto d : _dimensions)
- {
- nums *= d;
- }
- return nums;
- }
-
-private:
- std::deque<int32_t> _dimensions;
-
-public:
- static Shape from(const std::string &s);
-};
-
-bool operator==(const Shape &, const Shape &);
-
-std::ostream &operator<<(std::ostream &os, const Shape &shape);
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_SHAPE_H__
diff --git a/include/util/tensor/Zipper.h b/include/util/tensor/Zipper.h
deleted file mode 100644
index 5d40736f3..000000000
--- a/include/util/tensor/Zipper.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __NNFW_UTIL_TENSOR_ZIPPER_H__
-#define __NNFW_UTIL_TENSOR_ZIPPER_H__
-
-#include "util/tensor/Index.h"
-#include "util/tensor/IndexIterator.h"
-#include "util/tensor/Reader.h"
-
-namespace nnfw
-{
-namespace util
-{
-namespace tensor
-{
-
-template <typename T> class Zipper
-{
-public:
- Zipper(const Shape &shape, const Reader<T> &lhs, const Reader<T> &rhs)
- : _shape{shape}, _lhs{lhs}, _rhs{rhs}
- {
- // DO NOTHING
- }
-
-public:
- template <typename Callable> void zip(Callable cb) const
- {
- iterate(_shape) <<
- [this, &cb](const Index &index) { cb(index, _lhs.at(index), _rhs.at(index)); };
- }
-
-private:
- const Shape &_shape;
- const Reader<T> &_lhs;
- const Reader<T> &_rhs;
-};
-
-template <typename T, typename Callable>
-const Zipper<T> &operator<<(const Zipper<T> &zipper, Callable cb)
-{
- zipper.zip(cb);
- return zipper;
-}
-
-template <typename T> Zipper<T> zip(const Shape &shape, const Reader<T> &lhs, const Reader<T> &rhs)
-{
- return Zipper<T>{shape, lhs, rhs};
-}
-
-} // namespace tensor
-} // namespace util
-} // namespace nnfw
-
-#endif // __NNFW_UTIL_TENSOR_ZIPPER_H__