lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 9cd8cf7 7/8: Refactor: composite 'OtherVector


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9cd8cf7 7/8: Refactor: composite 'OtherVectors' in LedgerBase::PlusEq()
Date: Thu, 9 Apr 2020 18:33:05 -0400 (EDT)

branch: master
commit 9cd8cf7016d7fc1ea5de1514b0d51aff6b9e921b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Refactor: composite 'OtherVectors' in LedgerBase::PlusEq()
    
    Other vector maps had already been composited in LedgerBase::PlusEq();
    now, 'OtherVectors' is composited there too, for uniformity.
---
 ledger_base.cpp      | 60 +++++++++++++++++++++++++++++++++++++++++++++-------
 ledger_invariant.cpp | 13 ------------
 ledger_variant.cpp   | 13 ------------
 3 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/ledger_base.cpp b/ledger_base.cpp
index aa2f7c4..3022d56 100644
--- a/ledger_base.cpp
+++ b/ledger_base.cpp
@@ -179,15 +179,20 @@ double_vector_map const& LedgerBase::all_vectors() const
 
 namespace
 {
-// Special non-general helper function.
-// The sole use of this function is to multiply y, a vector of values in
-// a ledger, by z, a vector of inforce factors. For this sole intended use,
-// we know that z is nonzero and nondecreasing; therefore, if it ever
-// becomes zero, it remains zero. We can safely break at that point in the
-// interest of speed because adding y times zero to z is a NOP. Note that
-// the inforce factor becomes zero upon lapse.
+/// Special non-general helper function.
+///
+/// Multiplies y, a vector of ledger values, by z, a vector of inforce
+/// factors; then adds the result into x, a vector of composite-ledger
+/// values, up to the length of y (which is less than or equal to the
+/// length of x).
+///
+/// In this sole use case, z must be nonincreasing and nonnegative,
+/// because it is a survivorship function. Once it becomes zero (due
+/// to maturity or lapse), it remains zero thenceforth; therefore, it
+/// is appropriate and safe to break the loop at that point.
+
     static void x_plus_eq_y_times_z
-        (std::vector<double>& x
+        (std::vector<double>      & x
         ,std::vector<double> const& y
         ,std::vector<double> const& z
         )
@@ -217,6 +222,31 @@ namespace
                 }
             }
     }
+
+/// Special non-general helper function.
+///
+/// Adds y, a vector of ledger values, into x, a vector of composite-
+/// ledger values, up to the length of y (which is less than or equal
+/// to the length of x).
+///
+/// Equivalent to:
+///   // ET !! This is of the form 'x[iota rho y] gets y'.
+///   for(int j = 0; j < y.size(); ++j) {x[j] = y[j];}
+
+    static void x_sub_iota_rho_y_gets_y
+        (std::vector<double>      & x
+        ,std::vector<double> const& y
+        )
+    {
+        std::vector<double>::iterator ix = x.begin();
+        std::vector<double>::const_iterator iy = y.begin();
+        LMI_ASSERT(y.size() <= x.size());
+        while(iy != y.end())
+            {
+            LMI_ASSERT(ix != x.end());
+            *ix++ = *iy++;
+            }
+    }
 } // Unnamed namespace.
 
 //============================================================================
@@ -289,6 +319,20 @@ LedgerBase& LedgerBase::PlusEq
         }
     LMI_ASSERT(a_Addend_svmi == a_Addend.ForborneVectors.end());
 
+    a_Addend_svmi = a_Addend.OtherVectors.begin();
+    for
+        (double_vector_map::iterator svmi = OtherVectors.begin()
+        ;svmi != OtherVectors.end()
+        ;++svmi, ++a_Addend_svmi
+        )
+        {
+        x_sub_iota_rho_y_gets_y
+            (*(*svmi).second
+            ,*(*a_Addend_svmi).second
+            );
+        }
+    LMI_ASSERT(a_Addend_svmi == a_Addend.OtherVectors.end());
+
     scalar_map::const_iterator a_Addend_ssmi = 
a_Addend.ScalableScalars.begin();
     for
         (scalar_map::iterator ssmi = ScalableScalars.begin()
diff --git a/ledger_invariant.cpp b/ledger_invariant.cpp
index 627c13b..51f3866 100644
--- a/ledger_invariant.cpp
+++ b/ledger_invariant.cpp
@@ -772,22 +772,9 @@ LedgerInvariant& LedgerInvariant::PlusEq(LedgerInvariant 
const& a_Addend)
     // two lives with a ten-year age difference, the last ten would
     // depend on the younger life only, most likely producing a
     // discontinuity at the older life's maturity age).
-    //
-    // ET !! This is of the form 'x[iota rho y] gets y'.
     for(int j = 0; j < a_Addend.Length; ++j)
         {
-        IndvTaxBracket       [j] = a_Addend.IndvTaxBracket       [j];
-        CorpTaxBracket       [j] = a_Addend.CorpTaxBracket       [j];
-        AnnualFlatExtra      [j] = a_Addend.AnnualFlatExtra      [j];
-        HoneymoonValueSpread [j] = a_Addend.HoneymoonValueSpread [j];
-        PartMortTableMult    [j] = a_Addend.PartMortTableMult    [j];
-        AddonCompOnAssets    [j] = a_Addend.AddonCompOnAssets    [j];
-        AddonCompOnPremium   [j] = a_Addend.AddonCompOnPremium   [j];
         CorridorFactor       [j] = 0.0;
-        AnnLoanDueRate       [j] = a_Addend.AnnLoanDueRate       [j];
-        CurrMandE            [j] = a_Addend.CurrMandE            [j];
-        TotalIMF             [j] = a_Addend.TotalIMF             [j];
-        RefundableSalesLoad  [j] = a_Addend.RefundableSalesLoad  [j];
         }
 
     IsMec                         = a_Addend.IsMec        || IsMec;
diff --git a/ledger_variant.cpp b/ledger_variant.cpp
index f57649a..252660a 100644
--- a/ledger_variant.cpp
+++ b/ledger_variant.cpp
@@ -204,19 +204,6 @@ LedgerVariant& LedgerVariant::PlusEq
     InitTgtPremHiLoadRate       = std::max(InitTgtPremHiLoadRate, 
a_Addend.InitTgtPremHiLoadRate);
     InitMlyPolFee               = std::max(InitMlyPolFee        , 
a_Addend.InitMlyPolFee        );
     InitAnnLoanCredRate         = a_Addend.InitAnnLoanCredRate;
-    // ET !! This is of the form 'x[iota rho y] gets y'.
-    for(int j = 0; j < a_Addend.Length; ++j)
-        {
-        MlySAIntRate              [j]  = a_Addend.MlySAIntRate              
[j];
-        MlyGAIntRate              [j]  = a_Addend.MlyGAIntRate              
[j];
-        MlyHoneymoonValueRate     [j]  = a_Addend.MlyHoneymoonValueRate     
[j];
-        MlyPostHoneymoonRate      [j]  = a_Addend.MlyPostHoneymoonRate      
[j];
-        AnnSAIntRate              [j]  = a_Addend.AnnSAIntRate              
[j];
-        AnnGAIntRate              [j]  = a_Addend.AnnGAIntRate              
[j];
-        AnnHoneymoonValueRate     [j]  = a_Addend.AnnHoneymoonValueRate     
[j];
-        AnnPostHoneymoonRate      [j]  = a_Addend.AnnPostHoneymoonRate      
[j];
-        KFactor                   [j]  = a_Addend.KFactor                   
[j];
-        }
 
     LMI_ASSERT(a_Addend.GenBasis_ == GenBasis_);
     LMI_ASSERT(a_Addend.SepBasis_ == SepBasis_);



reply via email to

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