From 8e75cf8acd691c22ca972a5c0c5bf12580af2e78 Mon Sep 17 00:00:00 2001 From: glisse Date: Sat, 11 Jul 2015 15:43:50 +0000 Subject: Clean-ups Avoid duplicate search with find+insert. No need to store 0 and 1 and return them by reference. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@702 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 28403136284a9fe2044b9d51bc2f10861b3a09e7 --- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 18 +++++++----------- .../include/gudhi/Persistent_cohomology/Multi_field.h | 6 +++--- 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'src/Persistent_cohomology') diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index 2a4c8692..a12019f8 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -41,9 +41,7 @@ class Field_Zp { Field_Zp() : Prime(0), - inverse_(), - mult_id_all(1), - add_id_all(0) { + inverse_() { } void init(int charac) { @@ -81,14 +79,14 @@ class Field_Zp { } /** \brief Returns the additive idendity \f$0_{\Bbbk}\f$ of the field.*/ - const Element& additive_identity() const { - return add_id_all; + Element additive_identity() const { + return 0; } /** \brief Returns the multiplicative identity \f$1_{\Bbbk}\f$ of the field.*/ - const Element& multiplicative_identity(Element = 0) const { - return mult_id_all; + Element multiplicative_identity(Element = 0) const { + return 1; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element P) { return std::pair(inverse_[x], P); } // <------ return the product of field characteristic for which x is invertible @@ -101,7 +99,7 @@ class Field_Zp { } /** \brief Returns the characteristic \f$p\f$ of the field.*/ - const int& characteristic() const { + int characteristic() const { return Prime; } @@ -109,8 +107,6 @@ class Field_Zp { int Prime; /** Property map Element -> Element, which associate to an element its inverse in the field.*/ std::vector inverse_; - const Element mult_id_all; - const Element add_id_all; }; } // namespace persistent_cohomology diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index c6fd5282..555d696f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -142,7 +142,7 @@ class Multi_field { return prod_characteristics_; } - /** Returns the inverse in the field. Modifies P.*/ + /** Returns the inverse in the field. Modifies P. ??? */ std::pair inverse(Element x, Element QS) { Element QR; mpz_gcd(QR.get_mpz_t(), x.get_mpz_t(), QS.get_mpz_t()); // QR <- gcd(x,QS) @@ -153,12 +153,12 @@ class Multi_field { mpz_invert(inv_qt.get_mpz_t(), x.get_mpz_t(), QT.get_mpz_t()); assert(prod_characteristics_ > 0); // division by zero + non negative values - return std::pair( - (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT); + return { (inv_qt * multiplicative_identity(QT)) % prod_characteristics_, QT }; } /** Returns -x * y.*/ Element times_minus(const Element& x, const Element& y) { assert(prod_characteristics_ > 0); // division by zero + non negative values + /* This assumes that (x*y)%pc cannot be zero, but Field_Zp has specific code for the 0 case ??? */ return prod_characteristics_ - ((x * y) % prod_characteristics_); } -- cgit v1.2.3