lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 7e90324 4/4: Prefer cso_table() calls to inli


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 7e90324 4/4: Prefer cso_table() calls to inline literals
Date: Fri, 15 Mar 2019 09:19:31 -0400 (EDT)

branch: master
commit 7e903249e2f52018b8d7e192b782aa68b99d10d0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Prefer cso_table() calls to inline literals
---
 Makefile.am                    |  3 +++
 actuarial_table_test.cpp       | 32 +++++++++++---------------------
 commutation_functions_test.cpp | 30 ++++++++++++------------------
 gpt_test.cpp                   | 27 ++++++++++-----------------
 objects.make                   |  3 +++
 print_matrix_test.cpp          | 30 ++++++++++++------------------
 6 files changed, 51 insertions(+), 74 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0e1531e..fe5ae91 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -631,6 +631,7 @@ test_commutation_functions_SOURCES = \
   $(common_test_objects) \
   commutation_functions.cpp \
   commutation_functions_test.cpp \
+  cso_table.cpp \
   timer.cpp
 test_commutation_functions_CXXFLAGS = $(AM_CXXFLAGS)
 
@@ -720,6 +721,7 @@ test_global_settings_LDADD = \
 test_gpt_SOURCES = \
   $(common_test_objects) \
   commutation_functions.cpp \
+  cso_table.cpp \
   gpt_commutation_functions.cpp \
   gpt_test.cpp \
   ihs_irc7702.cpp \
@@ -960,6 +962,7 @@ test_premium_tax_LDADD = \
 
 test_print_matrix_SOURCES = \
   $(common_test_objects) \
+  cso_table.cpp \
   miscellany.cpp \
   print_matrix_test.cpp
 test_print_matrix_CXXFLAGS = $(AM_CXXFLAGS)
diff --git a/actuarial_table_test.cpp b/actuarial_table_test.cpp
index d5cbefa..a8b5cfd 100644
--- a/actuarial_table_test.cpp
+++ b/actuarial_table_test.cpp
@@ -27,6 +27,7 @@
 #include "cso_table.hpp"
 #include "miscellany.hpp"
 #include "oecumenic_enumerations.hpp"
+#include "ssize_lmi.hpp"
 #include "test_tools.hpp"
 #include "timer.hpp"
 
@@ -61,30 +62,19 @@ std::vector<double> table_750()
     return std::vector<double>(q, q + n);
 }
 
-/// 'qx_cso' table 42: "1980 US CSO Male Age nearest"
-///
-/// Table type: Aggregate.
-///
-/// Parameters:
-///   min age 0; max age 99
+/// 1980 CSO Ultimate ANB Male Unismoke (i.e., 'qx_cso' table 42)
 
 std::vector<double> table_42(int age)
 {
-    static int const n = 100;
-    static double const q[n] =
-        //     0        1        2        3        4        5        6        
7        8        9
-        {0.00418, 0.00107, 0.00099, 0.00098, 0.00095, 0.00090, 0.00086, 
0.00080, 0.00076, 0.00074 // 00
-        ,0.00073, 0.00077, 0.00085, 0.00099, 0.00115, 0.00133, 0.00151, 
0.00167, 0.00178, 0.00186 // 10
-        ,0.00190, 0.00191, 0.00189, 0.00186, 0.00182, 0.00177, 0.00173, 
0.00171, 0.00170, 0.00171 // 20
-        ,0.00173, 0.00178, 0.00183, 0.00191, 0.00200, 0.00211, 0.00224, 
0.00240, 0.00258, 0.00279 // 30
-        ,0.00302, 0.00329, 0.00356, 0.00387, 0.00419, 0.00455, 0.00492, 
0.00532, 0.00574, 0.00621 // 40
-        ,0.00671, 0.00730, 0.00796, 0.00871, 0.00956, 0.01047, 0.01146, 
0.01249, 0.01359, 0.01477 // 50
-        ,0.01608, 0.01754, 0.01919, 0.02106, 0.02314, 0.02542, 0.02785, 
0.03044, 0.03319, 0.03617 // 60
-        ,0.03951, 0.04330, 0.04765, 0.05264, 0.05819, 0.06419, 0.07053, 
0.07712, 0.08390, 0.09105 // 70
-        ,0.09884, 0.10748, 0.11725, 0.12826, 0.14025, 0.15295, 0.16609, 
0.17955, 0.19327, 0.20729 // 80
-        ,0.22177, 0.23698, 0.25345, 0.27211, 0.29590, 0.32996, 0.38455, 
0.48020, 0.65798, 1.00000 // 90
-        };
-    return std::vector<double>(q + age, q + n);
+    static std::vector<double> const q = cso_table
+        (oe_1980cso
+        ,oe_orthodox
+        ,oe_age_nearest_birthday_ties_younger
+        ,mce_male
+        ,mce_unismoke
+        );
+    LMI_ASSERT(0 <= age && age < lmi::ssize(q));
+    return std::vector<double>(q.begin() + age, q.end());
 }
 
 /// 'qx_ins' table 256: "1934 UK A1924-29, Male+Female, Age nearest"
diff --git a/commutation_functions_test.cpp b/commutation_functions_test.cpp
index 43d5457..0a435f9 100644
--- a/commutation_functions_test.cpp
+++ b/commutation_functions_test.cpp
@@ -23,6 +23,7 @@
 
 #include "commutation_functions.hpp"
 
+#include "cso_table.hpp"
 #include "et_vector.hpp"
 #include "math_functions.hpp"
 #include "ssize_lmi.hpp"
@@ -39,25 +40,18 @@
 
 namespace
 {
-// SOA database 'qx_cso' table 42: "1980 US CSO Male Age nearest"
+/// 1980 CSO Ultimate ANB Male Unismoke
+
 std::vector<double> const& sample_q()
-    {
-    static int const n = 100;
-    static double const q[n] =
-        //     0        1        2        3        4        5        6        
7        8        9
-        {0.00418, 0.00107, 0.00099, 0.00098, 0.00095, 0.00090, 0.00086, 
0.00080, 0.00076, 0.00074 // 00
-        ,0.00073, 0.00077, 0.00085, 0.00099, 0.00115, 0.00133, 0.00151, 
0.00167, 0.00178, 0.00186 // 10
-        ,0.00190, 0.00191, 0.00189, 0.00186, 0.00182, 0.00177, 0.00173, 
0.00171, 0.00170, 0.00171 // 20
-        ,0.00173, 0.00178, 0.00183, 0.00191, 0.00200, 0.00211, 0.00224, 
0.00240, 0.00258, 0.00279 // 30
-        ,0.00302, 0.00329, 0.00356, 0.00387, 0.00419, 0.00455, 0.00492, 
0.00532, 0.00574, 0.00621 // 40
-        ,0.00671, 0.00730, 0.00796, 0.00871, 0.00956, 0.01047, 0.01146, 
0.01249, 0.01359, 0.01477 // 50
-        ,0.01608, 0.01754, 0.01919, 0.02106, 0.02314, 0.02542, 0.02785, 
0.03044, 0.03319, 0.03617 // 60
-        ,0.03951, 0.04330, 0.04765, 0.05264, 0.05819, 0.06419, 0.07053, 
0.07712, 0.08390, 0.09105 // 70
-        ,0.09884, 0.10748, 0.11725, 0.12826, 0.14025, 0.15295, 0.16609, 
0.17955, 0.19327, 0.20729 // 80
-        ,0.22177, 0.23698, 0.25345, 0.27211, 0.29590, 0.32996, 0.38455, 
0.48020, 0.65798, 1.00000 // 90
-        };
-    static std::vector<double> const v(q, q + n);
-    return v;
+{
+    static std::vector<double> const q = cso_table
+        (oe_1980cso
+        ,oe_orthodox
+        ,oe_age_nearest_birthday_ties_younger
+        ,mce_male
+        ,mce_unismoke
+        );
+    return q;
 }
 } // Unnamed namespace.
 
diff --git a/gpt_test.cpp b/gpt_test.cpp
index c2c25bf..b553a7f 100644
--- a/gpt_test.cpp
+++ b/gpt_test.cpp
@@ -25,6 +25,7 @@
 #include "ihs_irc7702.hpp"
 
 #include "assert_lmi.hpp"
+#include "cso_table.hpp"
 #include "materially_equal.hpp"
 #include "math_functions.hpp"
 #include "ssize_lmi.hpp"
@@ -45,26 +46,18 @@ std::vector<double> a_to_m(std::vector<double> const& q_a)
     return q_m;
 }
 
-/// SOA database table 42: "1980 US CSO Male Age nearest".
+/// 1980 CSO Ultimate ANB Male Unismoke
 
 std::vector<double> sample_q(int age)
 {
-    static int const n = 100;
-    LMI_ASSERT(0 <= age && age < n);
-    static double const q[n] =
-        //     0        1        2        3        4        5        6        
7        8        9
-        {0.00418, 0.00107, 0.00099, 0.00098, 0.00095, 0.00090, 0.00086, 
0.00080, 0.00076, 0.00074 // 00
-        ,0.00073, 0.00077, 0.00085, 0.00099, 0.00115, 0.00133, 0.00151, 
0.00167, 0.00178, 0.00186 // 10
-        ,0.00190, 0.00191, 0.00189, 0.00186, 0.00182, 0.00177, 0.00173, 
0.00171, 0.00170, 0.00171 // 20
-        ,0.00173, 0.00178, 0.00183, 0.00191, 0.00200, 0.00211, 0.00224, 
0.00240, 0.00258, 0.00279 // 30
-        ,0.00302, 0.00329, 0.00356, 0.00387, 0.00419, 0.00455, 0.00492, 
0.00532, 0.00574, 0.00621 // 40
-        ,0.00671, 0.00730, 0.00796, 0.00871, 0.00956, 0.01047, 0.01146, 
0.01249, 0.01359, 0.01477 // 50
-        ,0.01608, 0.01754, 0.01919, 0.02106, 0.02314, 0.02542, 0.02785, 
0.03044, 0.03319, 0.03617 // 60
-        ,0.03951, 0.04330, 0.04765, 0.05264, 0.05819, 0.06419, 0.07053, 
0.07712, 0.08390, 0.09105 // 70
-        ,0.09884, 0.10748, 0.11725, 0.12826, 0.14025, 0.15295, 0.16609, 
0.17955, 0.19327, 0.20729 // 80
-        ,0.22177, 0.23698, 0.25345, 0.27211, 0.29590, 0.32996, 0.38455, 
0.48020, 0.65798, 1.00000 // 90
-        };
-    static std::vector<double> const q_a(q, q + n);
+    static std::vector<double> const q_a = cso_table
+        (oe_1980cso
+        ,oe_orthodox
+        ,oe_age_nearest_birthday_ties_younger
+        ,mce_male
+        ,mce_unismoke
+        );
+    LMI_ASSERT(0 <= age && age < lmi::ssize(q_a));
     static std::vector<double> const q_m(a_to_m(q_a));
     return std::vector<double>(q_m.begin() + age, q_m.end());
 }
diff --git a/objects.make b/objects.make
index 8a5393e..05c045c 100644
--- a/objects.make
+++ b/objects.make
@@ -563,6 +563,7 @@ commutation_functions_test$(EXEEXT): \
   $(common_test_objects) \
   commutation_functions.o \
   commutation_functions_test.o \
+  cso_table.o \
   timer.o \
 
 configurable_settings_test$(EXEEXT): \
@@ -639,6 +640,7 @@ global_settings_test$(EXEEXT): \
 gpt_test$(EXEEXT): \
   $(common_test_objects) \
   commutation_functions.o \
+  cso_table.o \
   gpt_commutation_functions.o \
   gpt_test.o \
   ihs_irc7702.o \
@@ -851,6 +853,7 @@ premium_tax_test$(EXEEXT): \
 
 print_matrix_test$(EXEEXT): \
   $(common_test_objects) \
+  cso_table.o \
   miscellany.o \
   print_matrix_test.o \
 
diff --git a/print_matrix_test.cpp b/print_matrix_test.cpp
index 4430459..88397cc 100644
--- a/print_matrix_test.cpp
+++ b/print_matrix_test.cpp
@@ -23,29 +23,23 @@
 
 #include "print_matrix.hpp"
 
+#include "cso_table.hpp"
 #include "test_tools.hpp"
 
 namespace
 {
-// SOA database 'qx_cso' table 42: "1980 US CSO Male Age nearest"
+/// 1980 CSO Ultimate ANB Male Unismoke
+
 std::vector<double> const& sample_q()
 {
-    static int const n = 100;
-    static double const q[n] =
-        //     0        1        2        3        4        5        6        
7        8        9
-        {0.00418, 0.00107, 0.00099, 0.00098, 0.00095, 0.00090, 0.00086, 
0.00080, 0.00076, 0.00074 // 00
-        ,0.00073, 0.00077, 0.00085, 0.00099, 0.00115, 0.00133, 0.00151, 
0.00167, 0.00178, 0.00186 // 10
-        ,0.00190, 0.00191, 0.00189, 0.00186, 0.00182, 0.00177, 0.00173, 
0.00171, 0.00170, 0.00171 // 20
-        ,0.00173, 0.00178, 0.00183, 0.00191, 0.00200, 0.00211, 0.00224, 
0.00240, 0.00258, 0.00279 // 30
-        ,0.00302, 0.00329, 0.00356, 0.00387, 0.00419, 0.00455, 0.00492, 
0.00532, 0.00574, 0.00621 // 40
-        ,0.00671, 0.00730, 0.00796, 0.00871, 0.00956, 0.01047, 0.01146, 
0.01249, 0.01359, 0.01477 // 50
-        ,0.01608, 0.01754, 0.01919, 0.02106, 0.02314, 0.02542, 0.02785, 
0.03044, 0.03319, 0.03617 // 60
-        ,0.03951, 0.04330, 0.04765, 0.05264, 0.05819, 0.06419, 0.07053, 
0.07712, 0.08390, 0.09105 // 70
-        ,0.09884, 0.10748, 0.11725, 0.12826, 0.14025, 0.15295, 0.16609, 
0.17955, 0.19327, 0.20729 // 80
-        ,0.22177, 0.23698, 0.25345, 0.27211, 0.29590, 0.32996, 0.38455, 
0.48020, 0.65798, 1.00000 // 90
-        };
-    static std::vector<double> const v(q, q + n);
-    return v;
+    static std::vector<double> const q = cso_table
+        (oe_1980cso
+        ,oe_orthodox
+        ,oe_age_nearest_birthday_ties_younger
+        ,mce_male
+        ,mce_unismoke
+        );
+    return q;
 }
 } // Unnamed namespace.
 
@@ -53,7 +47,7 @@ std::vector<double> const& sample_q()
 int test_main(int, char*[])
 {
     {
-    std::vector<double> q(sample_q());
+    std::vector<double> const& q(sample_q());
     std::vector<int> dimensions {10, 1, 1, 2, 5};
     print_matrix(std::cout, q, dimensions);
     std::cout << std::endl;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]