diff options
author | Chunseok Lee <chunseok.lee@samsung.com> | 2018-09-18 16:53:40 +0900 |
---|---|---|
committer | Chunseok Lee <chunseok.lee@samsung.com> | 2018-09-18 16:53:40 +0900 |
commit | 91f4ba45449f700a047a4aeea00b1a7c84e94c75 (patch) | |
tree | c60eecdba0861c51010fb0519f8a59668d90a6d2 /libs/util/src/tensor | |
parent | 07659ccd9fe7b1cf1547cc6cad78bcf489f0a361 (diff) | |
download | nnfw-91f4ba45449f700a047a4aeea00b1a7c84e94c75.tar.gz nnfw-91f4ba45449f700a047a4aeea00b1a7c84e94c75.tar.bz2 nnfw-91f4ba45449f700a047a4aeea00b1a7c84e94c75.zip |
Imported Upstream version 0.2upstream/0.2submit/tizen/20180918.075952
Diffstat (limited to 'libs/util/src/tensor')
-rw-r--r-- | libs/util/src/tensor/Comparator.cpp | 40 | ||||
-rw-r--r-- | libs/util/src/tensor/Shape.cpp | 55 |
2 files changed, 94 insertions, 1 deletions
diff --git a/libs/util/src/tensor/Comparator.cpp b/libs/util/src/tensor/Comparator.cpp new file mode 100644 index 000000000..89cd687e9 --- /dev/null +++ b/libs/util/src/tensor/Comparator.cpp @@ -0,0 +1,40 @@ +#include "util/tensor/Comparator.h" +#include "util/tensor/Zipper.h" + +#include "util/fp32.h" + +namespace nnfw +{ +namespace util +{ +namespace tensor +{ + +std::vector<Diff<float>> Comparator::compare(const Shape &shape, const Reader<float> &expected, + const Reader<float> &obtained, + Observer *observer) const +{ + std::vector<Diff<float>> res; + + zip(shape, expected, obtained) << + [&](const Index &index, float expected_value, float obtained_value) { + const auto relative_diff = nnfw::util::fp32::relative_diff(expected_value, obtained_value); + + if (!_compare_fn(expected_value, obtained_value)) + { + res.emplace_back(index, expected_value, obtained_value); + } + + // Update max_diff_index, if necessary + if (observer != nullptr) + { + observer->notify(index, expected_value, obtained_value); + } + }; + + return res; +} + +} // namespace tensor +} // namespace util +} // namespace nnfw diff --git a/libs/util/src/tensor/Shape.cpp b/libs/util/src/tensor/Shape.cpp index d177d1382..f1de26fdc 100644 --- a/libs/util/src/tensor/Shape.cpp +++ b/libs/util/src/tensor/Shape.cpp @@ -16,6 +16,8 @@ #include "util/tensor/Shape.h" +#include <cassert> + namespace nnfw { namespace util @@ -32,7 +34,7 @@ bool operator==(const Shape &lhs, const Shape &rhs) for (size_t axis = 0; axis < lhs.rank(); ++axis) { - if(lhs.dim(axis) != rhs.dim(axis)) + if (lhs.dim(axis) != rhs.dim(axis)) { return false; } @@ -41,6 +43,57 @@ bool operator==(const Shape &lhs, const Shape &rhs) return true; } +Shape Shape::from(const std::string &str) +{ + Shape shape(0); + + bool pending = false; + int value = 0; + + for (const char *cur = str.c_str(); true; ++cur) + { + if (*cur == ',' || *cur == '\0') + { + if (pending) + { + shape.append(value); + } + + if (*cur == '\0') + { + break; + } + + pending = false; + value = 0; + continue; + } + + assert(*cur >= '0' && *cur <= '9'); + + pending = true; + value *= 10; + value += *cur - '0'; + } + + return shape; +} + +std::ostream &operator<<(std::ostream &os, const Shape &shape) +{ + if (shape.rank() > 0) + { + os << shape.dim(0); + + for (uint32_t axis = 1; axis < shape.rank(); ++axis) + { + os << "," << shape.dim(axis); + } + } + + return os; +} + } // namespace tensor } // namespace util } // namespace nnfw |