Skip to content

Commit 110fa7f

Browse files
committed
[RF] Don't derefernce pointers in code emitted by RooFit codegen
Differentiating through Cling runtime checks in pointer dereferncing can result in errors: ```txt warning: attempted differentiation of function 'cling_runtime_internal_throwIfInvalidPointer' without definition and no suitable overload was found in namespace 'custom_derivatives' note: numerical differentiation is not viable for 'cling_runtime_internal_throwIfInvalidPointer'; considering 'cling_runtime_internal_throwIfInvalidPointer' as 0 <<< cling interactive line includer >>>:1:1: error: read-only variable is not assignable ^ ```
1 parent 747738a commit 110fa7f

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

roofit/codegen/src/CodegenImpl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void rooHistTranslateImpl(RooAbsArg const &arg, CodegenContext &ctx, int intOrde
102102
}
103103
std::string const &offset = dataHist.calculateTreeIndexForCodeSquash(ctx, obs);
104104
std::string weightArr = dataHist.declWeightArrayForCodeSquash(ctx, correctForBinSize);
105-
ctx.addResult(&arg, "*(" + weightArr + " + " + offset + ")");
105+
ctx.addResult(&arg, "(" + weightArr + ")[" + offset + "]");
106106
}
107107

108108
std::string realSumPdfTranslateImpl(CodegenContext &ctx, RooAbsArg const &arg, RooArgList const &funcList,

roofit/roofitcore/src/RooDataHist.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,16 @@ std::string RooDataHist::calculateTreeIndexForCodeSquash(RooFit::Experimental::C
10251025
return "";
10261026
}
10271027

1028-
code += " + " + binning->translateBinNumber(ctx, *theVar, idxMult);
1028+
if (i > 0)
1029+
code += " + ";
1030+
code += binning->translateBinNumber(ctx, *theVar, idxMult);
10291031

10301032
// Use RooAbsLValue here because it also generalized to categories, which
10311033
// is useful in the future. dynamic_cast because it's a cross-cast.
10321034
idxMult *= dynamic_cast<RooAbsLValue const *>(internalVar)->numBins();
10331035
}
10341036

1035-
return "(" + code + ")";
1037+
return _vars.size() == 1 ? code : "(" + code + ")";
10361038
}
10371039

10381040
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)