From de85c55789660b213112770ec73bcf03d23ffaa4 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Tue, 6 Nov 2018 09:54:13 +0100 Subject: Renaming. --- include/gudhi_laplacian/simplex_tree.hpp | 22 +++++++------- include/gudhi_laplacian/sparse_row.hpp | 48 ------------------------------- include/gudhi_laplacian/sparse_vector.hpp | 48 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 include/gudhi_laplacian/sparse_row.hpp create mode 100644 include/gudhi_laplacian/sparse_vector.hpp diff --git a/include/gudhi_laplacian/simplex_tree.hpp b/include/gudhi_laplacian/simplex_tree.hpp index 72cae62..dafcd06 100644 --- a/include/gudhi_laplacian/simplex_tree.hpp +++ b/include/gudhi_laplacian/simplex_tree.hpp @@ -8,7 +8,7 @@ #include -#include "sparse_row.hpp" +#include "sparse_vector.hpp" #include "misc.hpp" namespace Gudhi_laplacian @@ -62,10 +62,10 @@ namespace Gudhi_laplacian return stratification; } - Sparse_row assemble_cbd_row(ST & st, ST::Simplex_handle s) + Sparse_vector assemble_cbd_row(ST & st, ST::Simplex_handle s) { std::cerr << "WARNING: This function has not been tested much." << std::endl; - Sparse_row ret; + Sparse_vector ret; // This is a specialization of face_sign. int sign = (st.dimension(s) % 2 == 0) ? 1 : -1; @@ -79,9 +79,9 @@ namespace Gudhi_laplacian return ret; } - Sparse_row assemble_laplacian_row(ST & st, const std::vector > & weights, ST::Simplex_handle s) + Sparse_vector assemble_laplacian_row(ST & st, const std::vector > & weights, ST::Simplex_handle s) { - Sparse_row row; + Sparse_vector row; int dim = st.dimension(s); ST::Simplex_key s_key = ST::key(s); @@ -121,7 +121,7 @@ namespace Gudhi_laplacian bd_s_sign *= -1; } - compress_sparse_row(row); + compress_sparse_vector(row); return row; } @@ -156,7 +156,7 @@ namespace Gudhi_laplacian // For indices. for (auto it = stratification[d+1].cbegin(); it != stratification[d+1].cend(); ++it) { - Sparse_row row = assemble_cbd_row(st, *it); + Sparse_vector row = assemble_cbd_row(st, *it); assert(row.size() == d+2); for (auto jt = row.cbegin(); jt != row.cend(); ++jt) { @@ -167,7 +167,7 @@ namespace Gudhi_laplacian // For values. for (auto it = stratification[d+1].cbegin(); it != stratification[d+1].cend(); ++it) { - Sparse_row row = assemble_cbd_row(st, *it); + Sparse_vector row = assemble_cbd_row(st, *it); assert(row.size() == d+2); for (auto jt = row.cbegin(); jt != row.cend(); ++jt) { @@ -211,7 +211,7 @@ namespace Gudhi_laplacian // First traversal (counting). for (auto it = stratification[d].cbegin(); it != stratification[d].cend(); ++it) { - Sparse_row row = assemble_laplacian_row(st, weights, *it); + Sparse_vector row = assemble_laplacian_row(st, weights, *it); num_nonzero += row.size(); num_nonzero_row.push_back(row.size()); } @@ -223,7 +223,7 @@ namespace Gudhi_laplacian // Second traversal (indices). for (auto it = stratification[d].cbegin(); it != stratification[d].cend(); ++it) { - Sparse_row row = assemble_laplacian_row(st, weights, *it); + Sparse_vector row = assemble_laplacian_row(st, weights, *it); for (auto jt = row.cbegin(); jt != row.cend(); ++jt) { write_be(file, jt->first); @@ -233,7 +233,7 @@ namespace Gudhi_laplacian // Third traversal (values). for (auto it = stratification[d].cbegin(); it != stratification[d].cend(); ++it) { - Sparse_row row = assemble_laplacian_row(st, weights, *it); + Sparse_vector row = assemble_laplacian_row(st, weights, *it); for (auto jt = row.cbegin(); jt != row.cend(); ++jt) { write_be(file, jt->second); diff --git a/include/gudhi_laplacian/sparse_row.hpp b/include/gudhi_laplacian/sparse_row.hpp deleted file mode 100644 index 9896625..0000000 --- a/include/gudhi_laplacian/sparse_row.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#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); - } - } - } -} diff --git a/include/gudhi_laplacian/sparse_vector.hpp b/include/gudhi_laplacian/sparse_vector.hpp new file mode 100644 index 0000000..58dd40c --- /dev/null +++ b/include/gudhi_laplacian/sparse_vector.hpp @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include +#include + +namespace Gudhi_laplacian +{ + template + using Sparse_vector = std::vector >; + + template + void compress_sparse_vector(Sparse_vector & row) + { + static_assert(std::is_arithmetic::value, "Only arithmetic types are supported."); + + Sparse_vector 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