From 4dde5649fbf56e1dba8716e28f5dc7a7d765750c Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 30 May 2024 10:46:02 -0400 Subject: [PATCH] RF: Avoid repeated linspace and hstack calls --- nipype/algorithms/confounds.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nipype/algorithms/confounds.py b/nipype/algorithms/confounds.py index 4d82bcf080..a93d36aca0 100644 --- a/nipype/algorithms/confounds.py +++ b/nipype/algorithms/confounds.py @@ -1190,12 +1190,13 @@ def _make_cosine_regressors(ntimepoints, timestep, period_cut): def _make_legendre_regressors(ntimepoints, degree): - X = np.ones((ntimepoints, 1)) # quick way to calc degree 0 - for i in range(degree): - polynomial_func = Legendre.basis(i + 1) - value_array = np.linspace(-1, 1, ntimepoints) - X = np.hstack((X, polynomial_func(value_array)[:, np.newaxis])) - return X + support = np.linspace([-1], [1], ntimepoints) + return np.hstack( + [ + np.ones((ntimepoints, 1)), # Degree 0 is a constant + *(Legendre.basis(i + 1)(support) for i in range(degree)), + ] + ) def _high_pass_filter(