From fdd19289c7ec3686d6190b871927cc781d9d2f84 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Tue, 27 Oct 2015 11:56:03 +0100 Subject: [PATCH] add MeasTable::posArgDeriv and aber*ArgDeriv Returns derivative of MeasTable::posArg and aber*Arg Polynomial, which is also computed only once and the cached. Avoids unnecessary Polynomial creations in some places which involved several small Array allocations. --- measures/Measures/Aberration.cc | 11 ++---- measures/Measures/MeasTable.cc | 67 +++++++++++++++++++++++++++++++++ measures/Measures/MeasTable.h | 4 ++ measures/Measures/SolarPos.cc | 4 +- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/measures/Measures/Aberration.cc b/measures/Measures/Aberration.cc index 6bc9ad8a782..6e616fa2acf 100644 --- a/measures/Measures/Aberration.cc +++ b/measures/Measures/Aberration.cc @@ -167,9 +167,8 @@ void Aberration::calcAber(Double t) { case B1950: { for (i=0; i<12; i++) { - const Polynomial& aberArgP = MeasTable::aber1950Arg(i); - fa(i) = aberArgP(t); - dfa(i) = (aberArgP.derivative())(t); + fa(i) = MeasTable::aber1950Arg(i)(t); + dfa(i) = MeasTable::aber1950ArgDeriv(i)(t); } CountedPtr > mul = MeasTable::mulAber1950(t, 1e-6); DebugAssert (mul->contiguousStorage(), AipsError); @@ -213,10 +212,8 @@ void Aberration::calcAber(Double t) { } } else { for (i=0; i<13; i++) { - const Polynomial& aberArgP = MeasTable::aberArg(i); - - fa(i) = aberArgP(t); - dfa(i) = (aberArgP.derivative())(t); + fa(i) = MeasTable::aberArg(i)(t); + dfa(i) = MeasTable::aberArgDeriv(i)(t); } CountedPtr > mul = MeasTable::mulAber(t, 1e-6); DebugAssert (mul->contiguousStorage(), AipsError); diff --git a/measures/Measures/MeasTable.cc b/measures/Measures/MeasTable.cc index a5c45c19586..515dd60f028 100644 --- a/measures/Measures/MeasTable.cc +++ b/measures/Measures/MeasTable.cc @@ -3236,6 +3236,28 @@ const Polynomial &MeasTable::aberArg(uInt which) { return polyArray[which]; } +// Derivative aber +const Polynomial &MeasTable::aberArgDeriv(uInt which) { + static volatile Bool needInit = True; + static Polynomial polyArray[13]; + + if (needInit) { + const Polynomial * polyArray_ptrs[13]; + for (int i=0; i<13; i++) { + polyArray_ptrs[i] = &aberArg(i); + } + ScopedMutexLock locker(theirMutex); + if (needInit) { + for (int i=0; i<13; i++) { + polyArray[i] = polyArray_ptrs[i]->derivative(); + } + needInit = False; + } + } + DebugAssert(which < 13, AipsError); + return polyArray[which]; +} + const Polynomial &MeasTable::aber1950Arg(uInt which) { static volatile Bool needInit = True; static Polynomial polyArray[12]; @@ -3271,6 +3293,28 @@ const Polynomial &MeasTable::aber1950Arg(uInt which) { return polyArray[which]; } +// Derivative aber1950 +const Polynomial &MeasTable::aber1950ArgDeriv(uInt which) { + static volatile Bool needInit = True; + static Polynomial polyArray[12]; + + if (needInit) { + const Polynomial * polyArray_ptrs[12]; + for (int i=0; i<12; i++) { + polyArray_ptrs[i] = &aber1950Arg(i); + } + ScopedMutexLock locker(theirMutex); + if (needInit) { + for (int i=0; i<12; i++) { + polyArray[i] = polyArray_ptrs[i]->derivative(); + } + needInit = False; + } + } + DebugAssert(which < 12, AipsError); + return polyArray[which]; +} + const Double* MeasTable::mulAberArg(uInt which) { static const Double ABERARG[80][6] = { { 0, 0, 1, 0, 0, 0}, @@ -3827,6 +3871,29 @@ const Polynomial &MeasTable::posArg(uInt which) { POSFUND[i][j]*C::degree); } } + + needInit = False; + } + } + DebugAssert(which < 12, AipsError); + return polyArray[which]; +} + +// Derivative of Earth and Sun position polynomial +const Polynomial &MeasTable::posArgDeriv(uInt which) { + static volatile Bool needInit = True; + static Polynomial polyArray[12]; + + if (needInit) { + const Polynomial * polyArray_ptrs[12]; + for (int i=0; i<12; i++) { + polyArray_ptrs[i] = &posArg(i); + } + ScopedMutexLock locker(theirMutex); + if (needInit) { + for (int i=0; i<12; i++) { + polyArray[i] = polyArray_ptrs[i]->derivative(); + } needInit = False; } } diff --git a/measures/Measures/MeasTable.h b/measures/Measures/MeasTable.h index 77b50013a8b..a4cee896abc 100644 --- a/measures/Measures/MeasTable.h +++ b/measures/Measures/MeasTable.h @@ -289,7 +289,9 @@ class MeasTable { // (B1950). // static const Polynomial &aberArg(uInt which); + static const Polynomial &aberArgDeriv(uInt which); static const Polynomial &aber1950Arg(uInt which); + static const Polynomial &aber1950ArgDeriv(uInt which); // // Generate the 'which' vector of the aberration series arguments @@ -344,6 +346,8 @@ class MeasTable { // Fundamental arguments for Soma et al. methods // static const Polynomial &posArg(uInt which); + // Precomputed derivative of PosArg + static const Polynomial &posArgDeriv(uInt which); // // Generate the which' vector of the position series arguments // diff --git a/measures/Measures/SolarPos.cc b/measures/Measures/SolarPos.cc index 989c1e8dbc8..28fc2edb70c 100644 --- a/measures/Measures/SolarPos.cc +++ b/measures/Measures/SolarPos.cc @@ -226,7 +226,7 @@ void SolarPos::calcEarth(Double t) { } else { for (i=0; i<12; i++) { fa(i) = MeasTable::posArg(i)(t); - dfa(i) = (MeasTable::posArg(i).derivative())(t); + dfa(i) = MeasTable::posArgDeriv(i)(t); } CountedPtr > mul = MeasTable::mulPosEarthXY(t, 1e-6); DebugAssert (mul->contiguousStorage(), AipsError); @@ -301,7 +301,7 @@ void SolarPos::calcSun(Double t) { } else { for (i=0; i<12; i++) { fa(i) = MeasTable::posArg(i)(t); - dfa(i) = (MeasTable::posArg(i).derivative())(t); + dfa(i) = MeasTable::posArgDeriv(i)(t); } CountedPtr > mul = MeasTable::mulPosSunXY(t, 1e-6); DebugAssert (mul->contiguousStorage(), AipsError);