Skip to content

Commit

Permalink
add MeasTable::posArgDeriv and aber1950ArgDeriv
Browse files Browse the repository at this point in the history
Returns derivative of MeasTable::posArg and aber1950Arg Polynomial,
which is also computed only once and the cached. Avoids unnecessary
Polynomial creations in some places which involved several small Array
allocations.
  • Loading branch information
juliantaylor committed Oct 27, 2015
1 parent 00a7605 commit 9a24a2e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion measures/Measures/Aberration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void Aberration::calcAber(Double t) {
for (i=0; i<12; i++) {
const Polynomial<Double>& aberArgP = MeasTable::aber1950Arg(i);
fa(i) = aberArgP(t);
dfa(i) = (aberArgP.derivative())(t);
dfa(i) = MeasTable::aber1950ArgDeriv(i)(t);
}
CountedPtr<Matrix<Double> > mul = MeasTable::mulAber1950(t, 1e-6);
DebugAssert (mul->contiguousStorage(), AipsError);
Expand Down
45 changes: 45 additions & 0 deletions measures/Measures/MeasTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,28 @@ const Polynomial<Double> &MeasTable::aber1950Arg(uInt which) {
return polyArray[which];
}

// Derivative aber1950
const Polynomial<Double> &MeasTable::aber1950ArgDeriv(uInt which) {
static volatile Bool needInit = True;
static Polynomial<Double> polyArray[12];

if (needInit) {
const Polynomial<Double> * 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},
Expand Down Expand Up @@ -3827,6 +3849,29 @@ const Polynomial<Double> &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<Double> &MeasTable::posArgDeriv(uInt which) {
static volatile Bool needInit = True;
static Polynomial<Double> polyArray[12];

if (needInit) {
const Polynomial<Double> * 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;
}
}
Expand Down
3 changes: 3 additions & 0 deletions measures/Measures/MeasTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class MeasTable {
// <group>
static const Polynomial<Double> &aberArg(uInt which);
static const Polynomial<Double> &aber1950Arg(uInt which);
static const Polynomial<Double> &aber1950ArgDeriv(uInt which);
// </group>

// Generate the 'which' vector of the aberration series arguments
Expand Down Expand Up @@ -344,6 +345,8 @@ class MeasTable {
// Fundamental arguments for Soma et al. methods
// <group>
static const Polynomial<Double> &posArg(uInt which);
// Precomputed derivative of PosArg
static const Polynomial<Double> &posArgDeriv(uInt which);
// </group>
// Generate the which' vector of the position series arguments
// <group>
Expand Down
4 changes: 2 additions & 2 deletions measures/Measures/SolarPos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Matrix<Double> > mul = MeasTable::mulPosEarthXY(t, 1e-6);
DebugAssert (mul->contiguousStorage(), AipsError);
Expand Down Expand Up @@ -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<Matrix<Double> > mul = MeasTable::mulPosSunXY(t, 1e-6);
DebugAssert (mul->contiguousStorage(), AipsError);
Expand Down

0 comments on commit 9a24a2e

Please sign in to comment.