Skip to content

Commit a67da28

Browse files
committed
RF: Prefer math.gcd to hand-rolled Euclid's algorithm
1 parent 9049156 commit a67da28

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

nipype/algorithms/modelgen.py

Lines changed: 2 additions & 21 deletions
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
@@ -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, dt))
820801

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

0 commit comments

Comments
 (0)