[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 61a04eb 08/14: Make commutation functions def
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 61a04eb 08/14: Make commutation functions default constructible |
Date: |
Mon, 5 Apr 2021 18:26:46 -0400 (EDT) |
branch: master
commit 61a04eb41f1ae95d8fb3d43c291e67d84709a976
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Make commutation functions default constructible
Got rid of useless data members. It is not necessary to store copies of
or references to ctor arguments because these classes have no member
functions that are not defaulted, save only their explicit ctors.
---
commutation_functions.cpp | 60 +++++++++++++++++++-----------------------
commutation_functions.hpp | 31 +++++++---------------
commutation_functions_test.cpp | 8 ++++++
3 files changed, 44 insertions(+), 55 deletions(-)
diff --git a/commutation_functions.cpp b/commutation_functions.cpp
index a2b6716..547b846 100644
--- a/commutation_functions.cpp
+++ b/commutation_functions.cpp
@@ -44,23 +44,21 @@
/// unit test's mete_olcf().
OLCommFns::OLCommFns
- (std::vector<double> const& a_q
- ,std::vector<double> const& a_i
+ (std::vector<double> const& q
+ ,std::vector<double> const& i
)
- :q {a_q}
- ,i {a_i}
{
- Length = lmi::ssize(q);
+ int length = lmi::ssize(q);
LMI_ASSERT(lmi::ssize(i) == lmi::ssize(q));
#if defined VECTORIZE
- ed.resize(Length);
- d .resize(Length);
- c .resize(Length);
- n .resize(Length);
- m .resize(Length);
+ ed.resize(length);
+ d .resize(length);
+ c .resize(length);
+ n .resize(length);
+ m .resize(length);
- std::vector<double> v(Length);
+ std::vector<double> v(length);
v += 1.0 / (1.0 + i);
ed += v * (1.0 - q);
@@ -71,13 +69,13 @@ OLCommFns::OLCommFns
c += d * v * q;
#else // !defined VECTORIZE
- d.resize(1 + Length);
- c.resize( Length);
- n.resize( Length);
- m.resize( Length);
+ d.resize(1 + length);
+ c.resize( length);
+ n.resize( length);
+ m.resize( length);
d[0] = 1.0;
- for(int j = 0; j < Length; ++j)
+ for(int j = 0; j < length; ++j)
{
LMI_ASSERT(-1.0 != i[j]);
double v = 1.0 / (1.0 + i[j]);
@@ -115,33 +113,28 @@ OLCommFns::OLCommFns
/// processing. This is most often monthly, but need not be.
ULCommFns::ULCommFns
- (std::vector<double> const& a_qc
- ,std::vector<double> const& a_ic
- ,std::vector<double> const& a_ig
+ (std::vector<double> const& qc
+ ,std::vector<double> const& ic
+ ,std::vector<double> const& ig
,mcenum_dbopt_7702 dbo
,mcenum_mode mode
)
- :qc {a_qc}
- ,ic {a_ic}
- ,ig {a_ig}
- ,dbo_ {dbo}
- ,mode_ {mode}
{
- Length = lmi::ssize(qc);
+ int length = lmi::ssize(qc);
LMI_ASSERT(lmi::ssize(ic) == lmi::ssize(qc));
LMI_ASSERT(lmi::ssize(ig) == lmi::ssize(qc));
- ad.resize(1 + Length);
- kd.resize( Length);
- kc.resize( Length);
- an.resize( Length);
- km.resize( Length);
+ ad.resize(1 + length);
+ kd.resize( length);
+ kc.resize( length);
+ an.resize( length);
+ km.resize( length);
- int periods_per_year = mode_;
+ int periods_per_year = mode;
int months_per_period = 12 / periods_per_year;
ad[0] = 1.0;
- for(int j = 0; j < Length; ++j)
+ for(int j = 0; j < length; ++j)
{
LMI_ASSERT( 0.0 <= qc[j] && qc[j] <= 1.0);
LMI_ASSERT(-1.0 < ic[j]);
@@ -155,7 +148,8 @@ ULCommFns::ULCommFns
// Eckley equation (12).
double q = f * g;
// Eckley equation (19).
- if(mce_option2_for_7702 == dbo_)
+ // SOMEDAY !! It would be nice to let dbo vary by year.
+ if(mce_option2_for_7702 == dbo)
{
i = i - q;
}
diff --git a/commutation_functions.hpp b/commutation_functions.hpp
index 3354cc4..47075e0 100644
--- a/commutation_functions.hpp
+++ b/commutation_functions.hpp
@@ -34,9 +34,10 @@
class LMI_SO OLCommFns final
{
public:
- OLCommFns
- (std::vector<double> const& a_q
- ,std::vector<double> const& a_i
+ OLCommFns() = default;
+ explicit OLCommFns
+ (std::vector<double> const& q
+ ,std::vector<double> const& i
);
double Domega() const {return ed.back();}
@@ -47,11 +48,6 @@ class LMI_SO OLCommFns final
std::vector<double> const& M() const {return m;}
private:
- int Length;
-
- std::vector<double> const& q;
- std::vector<double> const& i;
-
std::vector<double> ed;
std::vector<double> d;
std::vector<double> c;
@@ -77,10 +73,11 @@ class LMI_SO OLCommFns final
class LMI_SO ULCommFns final
{
public:
- ULCommFns
- (std::vector<double> const& a_qc
- ,std::vector<double> const& a_ic
- ,std::vector<double> const& a_ig
+ ULCommFns() = default;
+ explicit ULCommFns
+ (std::vector<double> const& qc
+ ,std::vector<double> const& ic
+ ,std::vector<double> const& ig
,mcenum_dbopt_7702 dbo
,mcenum_mode mode
);
@@ -94,16 +91,6 @@ class LMI_SO ULCommFns final
std::vector<double> const& kM() const {return km;}
private:
- std::vector<double> qc;
- std::vector<double> ic;
- std::vector<double> ig;
-
- // SOMEDAY !! It would be nice to let dbo_ vary by year.
- mcenum_dbopt_7702 dbo_;
- mcenum_mode mode_;
-
- int Length;
-
std::vector<double> ead;
std::vector<double> ad;
std::vector<double> kd;
diff --git a/commutation_functions_test.cpp b/commutation_functions_test.cpp
index ed8a162..e0c1b0c 100644
--- a/commutation_functions_test.cpp
+++ b/commutation_functions_test.cpp
@@ -53,6 +53,13 @@ std::vector<double> const& sample_q()
}
} // Unnamed namespace.
+void test_fundamentals()
+{
+ // default ctors
+ OLCommFns();
+ ULCommFns();
+}
+
/// Exactly reproduce Table 2 from Eckley's paper.
///
/// Table 2 on pages 25-26 of TSA XXIX uses annual functions, and
@@ -715,6 +722,7 @@ void assay_speed()
int test_main(int, char*[])
{
+ test_fundamentals();
ULCommFnsTest();
OLCommFnsTest();
Test_1980_CSO_Male_ANB();
- [lmi-commits] [lmi] master updated (dd6ee0a -> 8aa09b9), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 40218dc 03/14: Factor out commutation-function speed tests, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b8f43e0 06/14: Transpose several unit-test functions, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master e6ed669 01/14: Test guideline premium calculations with more complications, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b1eecea 02/14: Stabilize unit-test timing, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 28cabc2 04/14: Prefer lambdas to std::bind(), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 61a04eb 08/14: Make commutation functions default constructible,
Greg Chicares <=
- [lmi-commits] [lmi] master df25463 12/14: Avoid operator new, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master b657767 13/14: Remove conditionals that serve no further purpose, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 23fe71f 11/14: Do away with an undesirable smart pointer [290], Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 485e19b 07/14: Favor the rule of zero, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 762056e 05/14: Prefer PETE's operator<<=() to assign(), Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master ed251fc 09/14: Test implicit special member functions, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master c2087ae 10/14: Update a comment, Greg Chicares, 2021/04/05
- [lmi-commits] [lmi] master 8aa09b9 14/14: Expunge some pointless defect markers [287], Greg Chicares, 2021/04/05