Skip to content

Commit 63a817f

Browse files
committed
[Python] Format code in tf_pycallables.py
Code-formatting with black to make the ruff linter happy.
1 parent eebd439 commit 63a817f

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

bindings/pyroot/pythonizations/test/tf_pycallables.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Cppyy that creates a C++ wrapper to invoke the Python callable.
66
"""
77

8-
import unittest
98
import math
9+
import unittest
1010

1111
import ROOT
1212

@@ -23,14 +23,17 @@ class pyf_tf1_callable:
2323
def __call__(self, x, p):
2424
return p[0] * x[0] + p[1]
2525

26+
2627
def pyf_func(x, pars):
2728
return pars[0] * x[0] * x[2] + x[1] * pars[1]
2829

30+
2931
def pyf_tf1_gauss(x, p):
30-
return p[0] * 1.0 / math.sqrt(2.0 * math.pi * p[2]**2) * math.exp(-(x[0] - p[1])**2 / 2.0 / p[2]**2)
32+
return p[0] * 1.0 / math.sqrt(2.0 * math.pi * p[2] ** 2) * math.exp(-((x[0] - p[1]) ** 2) / 2.0 / p[2] ** 2)
33+
3134

3235
def pyf_tf1_coulomb(x, p):
33-
return p[1] * x[0] * x[1] / (p[0]**2) * math.exp(-p[2] / p[0])
36+
return p[1] * x[0] * x[1] / (p[0] ** 2) * math.exp(-p[2] / p[0])
3437

3538

3639
class TF1(unittest.TestCase):
@@ -73,24 +76,23 @@ def test_callable(self):
7376
for x in [0.0, -1.0, 42.0]:
7477
self.assertEqual(f.Eval(x), pycallable([x], [par1, par2]))
7578

76-
7779
def test_fitgauss(self):
7880
"""
7981
Test fitting a histogram to a Python function
8082
"""
8183
# Gaus function
8284
f = ROOT.TF1("tf1_fitgauss", pyf_tf1_gauss, -4, 4, 3)
83-
f.SetParameter(0, 10.0) # scale
84-
f.SetParameter(1, -1.0) # mean
85-
f.SetParameter(2, 2.0) # standard deviation
85+
f.SetParameter(0, 10.0) # scale
86+
f.SetParameter(1, -1.0) # mean
87+
f.SetParameter(2, 2.0) # standard deviation
8688

8789
# Sample gauss in histogram
8890
h = ROOT.TH1F("h", "test", 100, -4, 4)
8991
h.FillRandom("gaus", 100000)
90-
h.Scale(1.0 / 100000.0 * 100.0 / 8.0) # Normalize as density
92+
h.Scale(1.0 / 100000.0 * 100.0 / 8.0) # Normalize as density
9193

9294
# Fit to histogram and get parameters
93-
h.Fit( f, "0Q" )
95+
h.Fit(f, "0Q")
9496
scale = f.GetParameter(0)
9597
mean = f.GetParameter(1)
9698
std = f.GetParameter(2)
@@ -108,13 +110,7 @@ def test_evalpar(self):
108110
rtf1_coulomb = ROOT.TF1("my_func", pyf_tf1_coulomb, -10, 10)
109111

110112
# x dataset: 5 pairs of particle charges
111-
x = np.array([
112-
[1.0, 10, 2.0],
113-
[1.5, 10, 2.5],
114-
[2.0, 10, 3.0],
115-
[2.5, 10, 3.5],
116-
[3.0, 10, 4.0]
117-
])
113+
x = np.array([[1.0, 10, 2.0], [1.5, 10, 2.5], [2.0, 10, 3.0], [2.5, 10, 3.5], [3.0, 10, 4.0]])
118114

119115
params = np.array(
120116
[
@@ -130,7 +126,7 @@ def test_evalpar(self):
130126
for i in range(len(x)):
131127
expected_value = pyf_tf1_coulomb(x[i, ::2], params)
132128
self.assertEqual(res[i], expected_value)
133-
129+
134130
def test_evalpar_dynamic(self):
135131
"""
136132
Test the 2D NumPy pythonizations with dynamic TF1 data dimensions
@@ -141,12 +137,9 @@ def test_evalpar_dynamic(self):
141137
rtf1_func = ROOT.TF1("my_func", pyf_func, -10, 10)
142138

143139
# x dataset with ndims 3
144-
x = np.array([[2., 2, 1],
145-
[1., 2, 3],
146-
[2., 2, 1],
147-
[4., 3, 2]])
140+
x = np.array([[2.0, 2, 1], [1.0, 2, 3], [2.0, 2, 1], [4.0, 3, 2]])
148141

149-
pars = np.array([2., 3.])
142+
pars = np.array([2.0, 3.0])
150143
res = rtf1_func.EvalPar(x, pars)
151144

152145
for i in range(len(x)):
@@ -206,6 +199,5 @@ def test_params(self):
206199
self.assertEqual(f.Eval(*x), pyf_tf2_params(x, [par1, par2, par3, par4]))
207200

208201

209-
if __name__ == '__main__':
202+
if __name__ == "__main__":
210203
unittest.main()
211-

0 commit comments

Comments
 (0)