From 639ade38182887fbf77319d4b97eca4a310db55f Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Thu, 25 Oct 2018 13:37:02 +0200 Subject: Rename files for namespacing reasons. --- include/gudhi_laplacian/sparse_row.hpp | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/gudhi_laplacian/sparse_row.hpp (limited to 'include/gudhi_laplacian/sparse_row.hpp') diff --git a/include/gudhi_laplacian/sparse_row.hpp b/include/gudhi_laplacian/sparse_row.hpp new file mode 100644 index 0000000..9896625 --- /dev/null +++ b/include/gudhi_laplacian/sparse_row.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +namespace Gudhi_laplacian +{ + template + using Sparse_row = std::vector >; + + template + void compress_sparse_row(Sparse_row & row) + { + static_assert(std::is_arithmetic::value, "Only arithmetic types are supported."); + + Sparse_row tmp(row); + row.clear(); + std::sort(tmp.begin(), tmp.end()); + for (auto it = tmp.cbegin(); it != tmp.cend(); ++it) + { + if (row.empty()) + { + if (it->second != T()) + { + row.push_back(*it); + } + } + else if (it->first == row.back().first) + { + T x = row.back().second + it->second; + if (x == T()) + { + row.pop_back(); + } + else + { + row.back().second = x; + } + } + else if (it->second != T()) + { + row.push_back(*it); + } + } + } +} -- cgit v1.2.3