Skip to content

Commit b75a7ce

Browse files
authored
Merge pull request #3177 from effigies/rf/gcd
RF: Prefer math.gcd to hand-rolled Euclid's algorithm
2 parents 9049156 + 7a19ee0 commit b75a7ce

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

nipype/algorithms/modelgen.py

+4-23
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,6 @@
3030
iflogger = logging.getLogger("nipype.interface")
3131

3232

33-
def gcd(a, b):
34-
"""
35-
Return the greatest common divisor of two integers (uses Euclid's algorithm).
36-
37-
Examples
38-
--------
39-
>>> gcd(4, 5)
40-
1
41-
>>> gcd(4, 8)
42-
4
43-
>>> gcd(22, 55)
44-
11
45-
46-
"""
47-
while b > 0:
48-
a, b = b, a % b
49-
return a
50-
51-
5233
def spm_hrf(RT, P=None, fMRI_T=16):
5334
"""
5435
python implementation of spm_hrf
@@ -799,9 +780,9 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
799780
matplotlib.use(config.get("execution", "matplotlib_backend"))
800781
import matplotlib.pyplot as plt
801782

802-
TR = np.round(self.inputs.time_repetition * 1000) # in ms
783+
TR = int(np.round(self.inputs.time_repetition * 1000)) # in ms
803784
if self.inputs.time_acquisition:
804-
TA = np.round(self.inputs.time_acquisition * 1000) # in ms
785+
TA = int(np.round(self.inputs.time_acquisition * 1000)) # in ms
805786
else:
806787
TA = TR # in ms
807788
nvol = self.inputs.volumes_in_cluster
@@ -813,10 +794,10 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
813794
if len(durations) == 1:
814795
durations = durations * np.ones((len(i_onsets)))
815796
onsets = np.round(np.array(i_onsets) * 1000)
816-
dttemp = gcd(TA, gcd(SILENCE, TR))
797+
dttemp = math.gcd(TA, math.gcd(SILENCE, TR))
817798
if dt < dttemp:
818799
if dttemp % dt != 0:
819-
dt = float(gcd(dttemp, dt))
800+
dt = float(math.gcd(dttemp, int(dt)))
820801

821802
if dt < 1:
822803
raise Exception("Time multiple less than 1 ms")

0 commit comments

Comments
 (0)