Skip to content

Commit b5c806c

Browse files
committed
[Math] Don't use vecCore::math functions
Now that we always use the `std::simd` backend of VecCore, we don't need to use `vecCore::math` anymore, because all the functions from `cmath` that VecCore wraps are also implemented for `std::simd`.
1 parent 23fa5f8 commit b5c806c

File tree

8 files changed

+29
-82
lines changed

8 files changed

+29
-82
lines changed

hist/hist/inc/Math/WrappedMultiTF1.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,7 @@ namespace ROOT {
373373
// case of polynomial function (no parameter dependency) (case for dim = 1)
374374
assert(fDim == 1);
375375
if (ipar == 0) return 1.0;
376-
#ifdef R__HAS_VECCORE
377-
return vecCore::math::Pow(x[0], static_cast<T>(ipar));
378-
#else
379-
return std::pow(x[0], static_cast<int>(ipar));
380-
#endif
376+
return pow(x[0], static_cast<int>(ipar));
381377
} else {
382378
// case of general linear function (built in TFormula with ++ )
383379
return GeneralLinearFunctionDerivation<T>::DoParameterDerivative(this, x, ipar);

hist/hist/inc/TFormula.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class TFormula : public TNamed
123123
static Bool_t IsDefaultVariableName(const TString &name);
124124
void ReplaceAllNames(TString &formula, std::map<TString, TString> &substitutions);
125125
void FillParametrizedFunctions(std::map<std::pair<TString, Int_t>, std::pair<TString, TString>> &functions);
126-
void FillVecFunctionsShurtCuts();
127126
void ReInitializeEvalMethod();
128127
std::string GetGradientFuncName() const {
129128
return std::string(GetUniqueFuncName().Data()) + "_grad_1";

hist/hist/src/TFormula.cxx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -955,42 +955,9 @@ void TFormula::FillDefaults()
955955
for (auto con : defconsts) {
956956
fConsts[con.first] = con.second;
957957
}
958-
if (fVectorized) {
959-
FillVecFunctionsShurtCuts();
960-
} else {
961-
for (auto fun : funShortcuts) {
962-
fFunctionsShortcuts[fun.first] = fun.second;
963-
}
964-
}
965-
}
966-
967-
////////////////////////////////////////////////////////////////////////////////
968-
/// Fill the shortcuts for vectorized functions
969-
/// We will replace for example sin with vecCore::Mat::Sin
970-
///
971-
972-
void TFormula::FillVecFunctionsShurtCuts() {
973-
#ifdef R__HAS_VECCORE
974-
const pair<TString,TString> vecFunShortcuts[] =
975-
{ {"sin","vecCore::math::Sin" },
976-
{"cos","vecCore::math::Cos" }, {"exp","vecCore::math::Exp"}, {"log","vecCore::math::Log"}, {"log10","vecCore::math::Log10"},
977-
{"tan","vecCore::math::Tan"},
978-
//{"sinh","vecCore::math::Sinh"}, {"cosh","vecCore::math::Cosh"},{"tanh","vecCore::math::Tanh"},
979-
{"asin","vecCore::math::ASin"},
980-
{"acos","TMath::Pi()/2-vecCore::math::ASin"},
981-
{"atan","vecCore::math::ATan"},
982-
{"atan2","vecCore::math::ATan2"}, {"sqrt","vecCore::math::Sqrt"},
983-
{"ceil","vecCore::math::Ceil"}, {"floor","vecCore::math::Floor"}, {"pow","vecCore::math::Pow"},
984-
{"cbrt","vecCore::math::Cbrt"},{"abs","vecCore::math::Abs"},
985-
{"min","vecCore::math::Min"},{"max","vecCore::math::Max"},{"sign","vecCore::math::Sign" }
986-
//{"sq","TMath::Sq"}, {"binomial","TMath::Binomial"} // this last two functions will not work in vectorized mode
987-
};
988-
// replace in the data member maps fFunctionsShortcuts
989-
for (auto fun : vecFunShortcuts) {
958+
for (auto fun : funShortcuts) {
990959
fFunctionsShortcuts[fun.first] = fun.second;
991960
}
992-
#endif
993-
// do nothing in case Veccore is not enabled
994961
}
995962

996963
////////////////////////////////////////////////////////////////////////////////
@@ -3148,7 +3115,6 @@ void TFormula::SetVectorized(Bool_t vectorized)
31483115

31493116
fMethod.reset();
31503117

3151-
FillVecFunctionsShurtCuts(); // to replace with the right vectorized signature (e.g. sin -> vecCore::math::Sin)
31523118
PreProcessFormula(fFormula);
31533119
PrepareFormula(fFormula);
31543120
}

math/mathcore/inc/Fit/FitUtil.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,10 @@ namespace FitUtil {
11611161
vecCore::Mask<T> validNegativeValuesMask = !positiveValuesMask && gradFunc[ipar] != 0;
11621162

11631163
if (!vecCore::MaskEmpty(validNegativeValuesMask)) {
1164-
const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1164+
const T kdmax1 = sqrt(vecCore::NumericLimits<T>::Max());
11651165
const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
11661166
T gg = kdmax1 * gradFunc[ipar];
1167-
pointContributionVec[ipar] = -vecCore::Blend(gg > 0, vecCore::math::Min(gg, kdmax2), vecCore::math::Max(gg, -kdmax2));
1167+
pointContributionVec[ipar] = -vecCore::Blend(gg > 0, min(gg, kdmax2), max(gg, -kdmax2));
11681168
}
11691169
}
11701170

@@ -1279,7 +1279,7 @@ namespace FitUtil {
12791279

12801280
(const_cast<IGradModelFunctionTempl<T> &>(func)).SetParameters(p);
12811281

1282-
const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1282+
const T kdmax1 = sqrt(vecCore::NumericLimits<T>::Max());
12831283
const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
12841284

12851285
auto mapFunction = [&](const unsigned int i) {
@@ -1324,8 +1324,8 @@ namespace FitUtil {
13241324
if (!vecCore::MaskEmpty(nonZeroGradientValues)) {
13251325
T gg = kdmax1 * gradFunc[kpar];
13261326
pointContributionVec[kpar] =
1327-
vecCore::Blend(nonZeroGradientValues && gg > 0, -vecCore::math::Min(gg, kdmax2),
1328-
-vecCore::math::Max(gg, -kdmax2));
1327+
vecCore::Blend(nonZeroGradientValues && gg > 0, -min(gg, kdmax2),
1328+
-max(gg, -kdmax2));
13291329
}
13301330
// if func derivative is zero term is also zero so do not add in g[kpar]
13311331
}

math/mathcore/inc/Math/Util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class TimingScope {
8080
static const T epsilon = T(2.0 * std::numeric_limits<double>::min());
8181
#ifdef R__HAS_VECCORE
8282
T logval =
83-
vecCore::Blend<T>(x <= epsilon, x / epsilon + vecCore::math::Log(epsilon) - T(1.0), vecCore::math::Log(x));
83+
vecCore::Blend<T>(x <= epsilon, x / epsilon + log(epsilon) - T(1.0), log(x));
8484
#else
8585
T logval = x <= epsilon ? x / epsilon + std::log(epsilon) - T(1.0) : std::log(x);
8686
#endif

math/mathcore/src/TMath.cxx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,19 +3276,3 @@ void TMath::KNNDensity(std::span<const double> observations, std::span<const dou
32763276
result[i] = factor == 0.0 ? 0.0 : factor * k_actual / ff;
32773277
}
32783278
}
3279-
3280-
//explicitly instantiate template functions from VecCore
3281-
#ifdef R__HAS_VECCORE
3282-
#include <Math/Types.h>
3283-
template ROOT::Double_v vecCore::math::Sin(const ROOT::Double_v & x);
3284-
template ROOT::Double_v vecCore::math::Cos(const ROOT::Double_v & x);
3285-
template ROOT::Double_v vecCore::math::ASin(const ROOT::Double_v & x);
3286-
template ROOT::Double_v vecCore::math::ATan(const ROOT::Double_v & x);
3287-
template ROOT::Double_v vecCore::math::ATan2(const ROOT::Double_v & x,const ROOT::Double_v & y);
3288-
// missing in veccore
3289-
// template ROOT::Double_v vecCore::math::ACos(const ROOT::Double_v & x);
3290-
// template ROOT::Double_v vecCore::math::Sinh(const ROOT::Double_v & x);
3291-
// template ROOT::Double_v vecCore::math::Cosh(const ROOT::Double_v & x);
3292-
// template ROOT::Double_v vecCore::math::Tanh(const ROOT::Double_v & x);
3293-
// template ROOT::Double_v vecCore::math::Cbrt(const ROOT::Double_v & x);
3294-
#endif

math/mathcore/src/VectorizedTMath.cxx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include "VectorizedTMath.h"
22

3+
#include <cmath>
4+
35
#ifdef ROOT_VECTORIZED_TMATH
46

57
namespace TMath {
68
////////////////////////////////////////////////////////////////////////////////
79
::ROOT::Double_v Log2(::ROOT::Double_v &x)
810
{
9-
return vecCore::math::Log2(x);
11+
return log2(x);
1012
}
1113

1214
////////////////////////////////////////////////////////////////////////////////
@@ -30,8 +32,8 @@ ::ROOT::Double_v Gaus(::ROOT::Double_v &x, Double_t mean, Double_t sigma, Bool_t
3032

3133
// For those entries of |arg| > 39 result is zero in double precision
3234
::ROOT::Double_v out =
33-
vecCore::Blend<::ROOT::Double_v>(vecCore::math::Abs(arg) < ::ROOT::Double_v(39.0),
34-
vecCore::math::Exp(::ROOT::Double_v(-0.5) * arg * arg), ::ROOT::Double_v(0.0));
35+
vecCore::Blend<::ROOT::Double_v>(abs(arg) < ::ROOT::Double_v(39.0),
36+
exp(::ROOT::Double_v(-0.5) * arg * arg), ::ROOT::Double_v(0.0));
3537
if (norm)
3638
out *= 0.3989422804014327 * inv_sigma; // 1/sqrt(2*Pi)=0.3989422804014327
3739
return out;
@@ -47,7 +49,7 @@ ::ROOT::Double_v Gaus(::ROOT::Double_v &x, Double_t mean, Double_t sigma, Bool_t
4749
::ROOT::Double_v LaplaceDist(::ROOT::Double_v &x, Double_t alpha, Double_t beta)
4850
{
4951
::ROOT::Double_v beta_v_inv = ::ROOT::Double_v(1.0) / ::ROOT::Double_v(beta);
50-
::ROOT::Double_v out = vecCore::math::Exp(-vecCore::math::Abs((x - ::ROOT::Double_v(alpha)) * beta_v_inv));
52+
::ROOT::Double_v out = exp(-abs((x - ::ROOT::Double_v(alpha)) * beta_v_inv));
5153
out *= ::ROOT::Double_v(0.5) * beta_v_inv;
5254
return out;
5355
}
@@ -64,8 +66,8 @@ ::ROOT::Double_v LaplaceDistI(::ROOT::Double_v &x, Double_t alpha, Double_t beta
6466
::ROOT::Double_v alpha_v = ::ROOT::Double_v(alpha);
6567
::ROOT::Double_v beta_v_inv = ::ROOT::Double_v(1.0) / ::ROOT::Double_v(beta);
6668
return vecCore::Blend<::ROOT::Double_v>(
67-
x <= alpha_v, 0.5 * vecCore::math::Exp(-vecCore::math::Abs((x - alpha_v) * beta_v_inv)),
68-
1 - 0.5 * vecCore::math::Exp(-vecCore::math::Abs((x - alpha_v) * beta_v_inv)));
69+
x <= alpha_v, 0.5 * exp(-abs((x - alpha_v) * beta_v_inv)),
70+
1 - 0.5 * exp(-abs((x - alpha_v) * beta_v_inv)));
6971
}
7072

7173
////////////////////////////////////////////////////////////////////////////////
@@ -92,7 +94,7 @@ ::ROOT::Double_v Freq(::ROOT::Double_v &x)
9294
q31 = 1.91308926107829841e-1, p32 = -2.26956593539686930e-1, q32 = 1.05167510706793207e+0,
9395
p33 = -2.78661308609647788e-1, q33 = 1.98733201817135256e+0, p34 = -2.23192459734184686e-2, q34 = 1;
9496

95-
::ROOT::Double_v v = vecCore::math::Abs(x) / w2;
97+
::ROOT::Double_v v = abs(x) / w2;
9698

9799
::ROOT::Double_v result{};
98100

@@ -114,12 +116,12 @@ ::ROOT::Double_v Freq(::ROOT::Double_v &x)
114116
result, mask2,
115117
::ROOT::Double_v(1.0) -
116118
(p20 + p21 * v + p22 * v2 + p23 * v3 + p24 * v4 + p25 * v5 + p26 * v6 + p27 * v7) /
117-
(vecCore::math::Exp(v2) * (q20 + q21 * v + q22 * v2 + q23 * v3 + q24 * v4 + q25 * v5 + q26 * v6 + v7)));
119+
(exp(v2) * (q20 + q21 * v + q22 * v2 + q23 * v3 + q24 * v4 + q25 * v5 + q26 * v6 + v7)));
118120
vecCore::MaskedAssign<::ROOT::Double_v>(result, mask3,
119121
::ROOT::Double_v(1.0) -
120122
(c1 + (p30 * v8 + p31 * v6 + p32 * v4 + p33 * v2 + p34) /
121123
((q30 * v8 + q31 * v6 + q32 * v4 + q33 * v2 + q34) * v2)) /
122-
(v * vecCore::math::Exp(v2)));
124+
(v * exp(v2)));
123125

124126
return vecCore::Blend<::ROOT::Double_v>(x > 0, ::ROOT::Double_v(0.5) + ::ROOT::Double_v(0.5) * result,
125127
::ROOT::Double_v(0.5) * (::ROOT::Double_v(1) - result));
@@ -130,7 +132,7 @@ ::ROOT::Double_v Freq(::ROOT::Double_v &x)
130132
::ROOT::Double_v BesselI0_Split_More(::ROOT::Double_v &ax)
131133
{
132134
::ROOT::Double_v y = 3.75 / ax;
133-
return (vecCore::math::Exp(ax) / vecCore::math::Sqrt(ax)) *
135+
return (exp(ax) / sqrt(ax)) *
134136
(0.39894228 +
135137
y * (1.328592e-2 +
136138
y * (2.25319e-3 +
@@ -149,7 +151,7 @@ ::ROOT::Double_v BesselI0_Split_Less(::ROOT::Double_v &x)
149151

150152
::ROOT::Double_v BesselI0(::ROOT::Double_v &x)
151153
{
152-
::ROOT::Double_v ax = vecCore::math::Abs(x);
154+
::ROOT::Double_v ax = abs(x);
153155

154156
return vecCore::Blend<::ROOT::Double_v>(ax <= 3.75, BesselI0_Split_Less(x), BesselI0_Split_More(ax));
155157
}
@@ -160,7 +162,7 @@ ::ROOT::Double_v BesselI1_Split_More(::ROOT::Double_v &ax, ::ROOT::Double_v &x)
160162
{
161163
::ROOT::Double_v y = 3.75 / ax;
162164
::ROOT::Double_v result =
163-
(vecCore::math::Exp(ax) / vecCore::math::Sqrt(ax)) *
165+
(exp(ax) / sqrt(ax)) *
164166
(0.39894228 + y * (-3.988024e-2 +
165167
y * (-3.62018e-3 +
166168
y * (1.63801e-3 + y * (-1.031555e-2 +
@@ -179,7 +181,7 @@ ::ROOT::Double_v BesselI1_Split_Less(::ROOT::Double_v &x)
179181

180182
::ROOT::Double_v BesselI1(::ROOT::Double_v &x)
181183
{
182-
::ROOT::Double_v ax = vecCore::math::Abs(x);
184+
::ROOT::Double_v ax = abs(x);
183185

184186
return vecCore::Blend<::ROOT::Double_v>(ax <= 3.75, BesselI1_Split_Less(x), BesselI1_Split_More(ax, x));
185187
}
@@ -195,8 +197,8 @@ ::ROOT::Double_v BesselJ0_Split1_More(::ROOT::Double_v &ax)
195197
1 + y * (-0.1098628627e-2 + y * (0.2734510407e-4 + y * (-0.2073370639e-5 + y * 0.2093887211e-6)));
196198
::ROOT::Double_v result2 =
197199
-0.1562499995e-1 + y * (0.1430488765e-3 + y * (-0.6911147651e-5 + y * (0.7621095161e-6 - y * 0.934935152e-7)));
198-
return vecCore::math::Sqrt(0.636619772 / ax) *
199-
(vecCore::math::Cos(xx) * result1 - z * vecCore::math::Sin(xx) * result2);
200+
return sqrt(0.636619772 / ax) *
201+
(cos(xx) * result1 - z * sin(xx) * result2);
200202
}
201203

202204
::ROOT::Double_v BesselJ0_Split1_Less(::ROOT::Double_v &x)
@@ -209,7 +211,7 @@ ::ROOT::Double_v BesselJ0_Split1_Less(::ROOT::Double_v &x)
209211

210212
::ROOT::Double_v BesselJ0(::ROOT::Double_v &x)
211213
{
212-
::ROOT::Double_v ax = vecCore::math::Abs(x);
214+
::ROOT::Double_v ax = abs(x);
213215
return vecCore::Blend<::ROOT::Double_v>(ax < 8, BesselJ0_Split1_Less(x), BesselJ0_Split1_More(ax));
214216
}
215217

@@ -225,7 +227,7 @@ ::ROOT::Double_v BesselJ1_Split1_More(::ROOT::Double_v &ax, ::ROOT::Double_v &x)
225227
::ROOT::Double_v result2 =
226228
0.04687499995 + y * (-0.2002690873e-3 + y * (0.8449199096e-5 + y * (-0.88228987e-6 - y * 0.105787412e-6)));
227229
::ROOT::Double_v result =
228-
vecCore::math::Sqrt(0.636619772 / ax) * (vecCore::math::Cos(xx) * result1 - z * vecCore::math::Sin(xx) * result2);
230+
sqrt(0.636619772 / ax) * (cos(xx) * result1 - z * sin(xx) * result2);
229231
vecCore::MaskedAssign<::ROOT::Double_v>(result, x < 0, -result);
230232
return result;
231233
}
@@ -241,7 +243,7 @@ ::ROOT::Double_v BesselJ1_Split1_Less(::ROOT::Double_v &x)
241243

242244
::ROOT::Double_v BesselJ1(::ROOT::Double_v &x)
243245
{
244-
::ROOT::Double_v ax = vecCore::math::Abs(x);
246+
::ROOT::Double_v ax = abs(x);
245247
return vecCore::Blend<::ROOT::Double_v>(ax < 8, BesselJ1_Split1_Less(x), BesselJ1_Split1_More(ax, x));
246248
}
247249

math/mathcore/test/testGradient.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ struct Model2D : public Model<T> {
208208
T res(0.0);
209209

210210
// Compute the function only when the arg meets the criteria, using the mask computed before
211-
vecCore::MaskedAssign<T>(res, mask, vecCore::math::Exp(-0.5 * arg * arg));
211+
vecCore::MaskedAssign<T>(res, mask, exp(-0.5 * arg * arg));
212212

213213
if (!norm)
214214
return res;

0 commit comments

Comments
 (0)