/usr/include/casacore/scimath/Functionals/Compound2Function.tcc is in casacore-dev 2.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | //# Compound2Function.cc: Compound of functions AutoDiff specialization
//# Copyright (C) 2001,2002,2004
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
//# $Id$
#ifndef SCIMATH_COMPOUND2FUNCTION_TCC
#define SCIMATH_COMPOUND2FUNCTION_TCC
//# Includes
#include <casacore/scimath/Functionals/CompoundFunction.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Constructors
//# Operators
template <class T>
AutoDiff<T> CompoundFunction<AutoDiff<T> >::
eval(typename Function<AutoDiff<T> >::FunctionArg x) const {
if (this->parset_p) fromParam_p();
AutoDiff<T> tmp(T(0), this->nparameters());
tmp.value() = 0;
for (uInt j=0; j<tmp.nDerivatives(); j++) tmp.deriv(j) = 0.0;
// function value
for (uInt i = 0; i< this->nFunctions(); ++i) {
AutoDiff<T> t = this->function(i)(x);
tmp.value() += t.value();
for (uInt j=0; j<t.nDerivatives(); ++j) {
tmp.deriv(this->paroff_p[i]+j) += t.deriv(j);
}
}
return tmp;
}
//# Member functions
template <class T>
uInt CompoundFunction<AutoDiff<T> >::
addFunction(const Function<AutoDiff<T> > &newFunction) {
uInt nf = CompoundParam<AutoDiff<T> >::addFunction(newFunction);
toParam_p();
return nf;
}
template <class T>
void CompoundFunction<AutoDiff<T> >::fromParam_p() const {
if (this->parset_p) {
for (uInt i=0; i<this->nparameters(); ++i) {
uInt k = this->functionPtr_p[this->funpar_p[i]]->nparameters();
uInt l = (*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].nDerivatives();
// Set correct number of derivatives in sub-functions
if (this->param_p[i].nDerivatives() < this->paroff_p[this->funpar_p[i]] + k) {
if (l != 0) (*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]] = AutoDiff<T>();
l = 0;
} else if (k != l) {
(*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]] = AutoDiff<T>(T(0), k);
l = k;
}
// Set the parameter data
for (uInt j=0; j<l; ++j) {
(*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].deriv(j) =
this->param_p[i].deriv(j+this->paroff_p[this->funpar_p[i]]);
}
(*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].value() = this->param_p[i].value();
this->functionPtr_p[this->funpar_p[i]]->mask(this->locpar_p[i]) = this->param_p.mask(i);
}
this->parset_p = False;
}
}
template <class T>
void CompoundFunction<AutoDiff<T> >::toParam_p() {
for (uInt i=0; i<this->nparameters(); ++i) {
// Set derivatives
if (this->nparameters() != this->param_p[i].nDerivatives()) {
this->param_p[i] = AutoDiff<T>(this->param_p[i].value(), this->nparameters());
}
uInt k = this->functionPtr_p[this->funpar_p[i]]->nparameters();
uInt l = (*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].nDerivatives();
// Set correct number of derivatives in sub-functions
if (this->param_p[i].nDerivatives() < this->paroff_p[this->funpar_p[i]] + k) {
if (l != 0) (*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]] = AutoDiff<T>();
l = 0;
} else if (k != l) {
(*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]] = AutoDiff<T>(T(0), k);
l = k;
}
// Set the parameter data
for (uInt j=0; j<l; ++j) {
this->param_p[i].deriv(j+this->paroff_p[this->funpar_p[i]]) =
(*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].deriv(j);
}
this->param_p[i].value() = (*this->functionPtr_p[this->funpar_p[i]])[this->locpar_p[i]].value();
this->param_p.mask(i) = this->functionPtr_p[this->funpar_p[i]]->mask(this->locpar_p[i]);
}
}
} //# NAMESPACE CASACORE - END
#endif
|