Skip to content

Commit 4dde564

Browse files
committed
RF: Avoid repeated linspace and hstack calls
1 parent 055285d commit 4dde564

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

nipype/algorithms/confounds.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1190,12 +1190,13 @@ def _make_cosine_regressors(ntimepoints, timestep, period_cut):
11901190

11911191

11921192
def _make_legendre_regressors(ntimepoints, degree):
1193-
X = np.ones((ntimepoints, 1)) # quick way to calc degree 0
1194-
for i in range(degree):
1195-
polynomial_func = Legendre.basis(i + 1)
1196-
value_array = np.linspace(-1, 1, ntimepoints)
1197-
X = np.hstack((X, polynomial_func(value_array)[:, np.newaxis]))
1198-
return X
1193+
support = np.linspace([-1], [1], ntimepoints)
1194+
return np.hstack(
1195+
[
1196+
np.ones((ntimepoints, 1)), # Degree 0 is a constant
1197+
*(Legendre.basis(i + 1)(support) for i in range(degree)),
1198+
]
1199+
)
11991200

12001201

12011202
def _high_pass_filter(

0 commit comments

Comments
 (0)