Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hist/hist/src/TFormula.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3419,7 +3419,7 @@ void TFormula::HessianPar(const Double_t *x, TFormula::CladStorage& result)
return;
}

if ((int)result.size() < fNpar) {
if ((int)result.size() < fNpar * fNpar) {
Warning("HessianPar",
"The size of hessian result is %zu but %d is required. Resizing.",
result.size(), fNpar * fNpar);
Expand Down
17 changes: 8 additions & 9 deletions hist/hist/test/TFormulaHessianTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ TEST(TFormulaHessianPar, ResultUpsize)
TFormula f("f", "std::sin([1]) - std::cos([0])");
double p[] = {60, 30};
f.SetParameters(p);
TFormula::CladStorage result;
// Two elements passed the old check, but a 2x2 Hessian needs four.
TFormula::CladStorage result(2);
double x[] = {2, 1};

ASSERT_TRUE(result.empty());
ROOT_EXPECT_WARNING(f.HessianPar(x, result),
"TFormula::HessianPar",
"The size of hessian result is 0 but 4 is required. Resizing."
);
ASSERT_TRUE(2 == result.size());
ROOT_EXPECT_WARNING(f.HessianPar(x, result), "TFormula::HessianPar",
"The size of hessian result is 2 but 4 is required. Resizing.");
ASSERT_TRUE(4 == result.size());

ASSERT_FLOAT_EQ(std::cos(p[0]), result[0]);
ASSERT_FLOAT_EQ(0, result[1]);
ASSERT_FLOAT_EQ(0, result[2]);
ASSERT_FLOAT_EQ(- std::sin(p[1]), result[3]);
ASSERT_TRUE(4 == result.size());
ASSERT_FLOAT_EQ(-std::sin(p[1]), result[3]);
}

TEST(TFormulaHessianPar, ResultDownsize)
Expand Down Expand Up @@ -86,4 +85,4 @@ TEST(TFormulaHessianPar, GetHessFormula)
#ifndef R__WIN32
ASSERT_THAT(s, testing::ContainsRegex("void TFormula____id[0-9]*_hessian_1"));
#endif // R__WIN32
}
}
Loading