Skip to content

Commit

Permalink
Pre-compute and store local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
heshpdx committed Sep 3, 2024
1 parent 8529162 commit aee65c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions libnestutil/numerics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const double numerics::nan = NAN;
const double numerics::nan = 0.0 / 0.0;
#endif

const double numerics::sqrt_log_two = std::sqrt( std::log( 2.0 ) );

// later also in namespace
long
ld_round( double x )
Expand Down
1 change: 1 addition & 0 deletions libnestutil/numerics.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace numerics
extern const double e;
extern const double pi;
extern const double nan;
extern const double sqrt_log_two;

/** Supply expm1() function independent of system.
* @note Implemented inline for efficiency.
Expand Down
12 changes: 9 additions & 3 deletions nestkernel/growth_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
// Includes from sli:
#include "dictutils.h"

// 1.0 / (2.0 * sqrt( log( 2.0 ) ))
#define INV_TWO_SQRT_LOG_TWO 0.6005612043932248974

/* ----------------------------------------------------------------
* GrowthCurveLinear
* ---------------------------------------------------------------- */
Expand Down Expand Up @@ -81,6 +78,7 @@ nest::GrowthCurveGaussian::GrowthCurveGaussian()
, eta_( 0.1 )
, eps_( 0.7 )
{
compute_local();
}

void
Expand All @@ -96,6 +94,7 @@ nest::GrowthCurveGaussian::set( const DictionaryDatum& d )
{
updateValue< double >( d, names::eps, eps_ );
updateValue< double >( d, names::eta, eta_ );
compute_local();
}

double
Expand Down Expand Up @@ -126,6 +125,13 @@ nest::GrowthCurveGaussian::update( double t,
return std::max( z_value, 0.0 );
}

void
nest::GrowthCurveGaussian::compute_local()
{
inv_zeta_ = 2.0 * numerics::sqrt_log_two / ( eta_ - eps_ );
xi_ = ( eta_ + eps_ ) * 0.5;
}

/* ----------------------------------------------------------------
* GrowthCurveSigmoid
* ---------------------------------------------------------------- */
Expand Down
4 changes: 4 additions & 0 deletions nestkernel/growth_curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,12 @@ class GrowthCurveGaussian : public GrowthCurve
update( double t, double t_minus, double Ca_minus, double z, double tau_Ca, double growth_rate ) const override;

private:
void compute_local();

double eta_;
double eps_;
double inv_zeta_;
double xi_;
};

/** @BeginDocumentation
Expand Down

0 comments on commit aee65c9

Please sign in to comment.