Skip to content

Commit d4b8fbb

Browse files
committed
[hist] Mark input x of the declared TFormula function as const
Under the hood, a TFormula declares a function to the interpreter. This function is then used also for differentiating through the TFormula with Clad. However, only the gradient with respect to the parameters `p` is requested, and the upcoming Clad release expects the other input arguments to be marked `const` for optimization purposes.
1 parent 0efb03b commit d4b8fbb

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

hist/hist/src/TFormula.cxx

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "TMethod.h"
1515
#include "TF1.h"
1616
#include "TMethodCall.h"
17-
#include <TBenchmark.h>
1817
#include "TError.h"
1918
#include "TInterpreter.h"
2019
#include "TInterpreterValue.h"
@@ -804,9 +803,9 @@ prepareMethod(bool HasParameters, bool HasVariables, const char* FuncName,
804803
TString prototypeArguments = "";
805804
if (HasVariables || HasParameters) {
806805
if (IsVectorized)
807-
prototypeArguments.Append("ROOT::Double_v*");
806+
prototypeArguments.Append("ROOT::Double_v const*");
808807
else
809-
prototypeArguments.Append("Double_t*");
808+
prototypeArguments.Append("Double_t const*");
810809
}
811810
auto AddDoublePtrParam = [&prototypeArguments]() {
812811
prototypeArguments.Append(",");
@@ -2387,7 +2386,7 @@ void TFormula::ProcessFormula(TString &formula)
23872386
TString argType = fVectorized ? "ROOT::Double_v" : "Double_t";
23882387

23892388
// valid input formula - try to put into Cling (in case of no variables but only parameter we need to add the standard signature)
2390-
TString argumentsPrototype = TString::Format("%s%s%s", ( (hasVariables || hasParameters) ? (argType + " *x").Data() : ""),
2389+
TString argumentsPrototype = TString::Format("%s%s%s", ( (hasVariables || hasParameters) ? (argType + " const *x").Data() : ""),
23912390
(hasParameters ? "," : ""), (hasParameters ? "Double_t *p" : ""));
23922391

23932392
// set the name for Cling using the hash_function
@@ -3680,7 +3679,7 @@ TString TFormula::GetExpFormula(Option_t *option, const char *fl_format) const
36803679

36813680
TString TFormula::GetGradientFormula() const {
36823681
std::unique_ptr<TInterpreterValue> v = gInterpreter->MakeInterpreterValue();
3683-
std::string s("(void (&)(Double_t *, Double_t *, Double_t *)) ");
3682+
std::string s("(void (&)(Double_t const *, Double_t *, Double_t *)) ");
36843683
s += GetGradientFuncName();
36853684
gInterpreter->Evaluate(s.c_str(), *v);
36863685
return v->ToString();

0 commit comments

Comments
 (0)