|
27 | 27 | IFLOGGER = logging.getLogger('nipype.interface')
|
28 | 28 |
|
29 | 29 |
|
| 30 | +def fallback_svd(a, full_matrices=True, compute_uv=True): |
| 31 | + try: |
| 32 | + return np.linalg.svd(a, full_matrices=full_matrices, compute_uv=compute_uv) |
| 33 | + except np.linalg.LinAlgError: |
| 34 | + pass |
| 35 | + |
| 36 | + from scipy.linalg import svd |
| 37 | + return svd(a, full_matrices=full_matrices, compute_uv=compute_uv, lapack_driver='gesvd') |
| 38 | + |
| 39 | + |
30 | 40 | class ComputeDVARSInputSpec(BaseInterfaceInputSpec):
|
31 | 41 | in_file = File(
|
32 | 42 | exists=True, mandatory=True, desc='functional data, after HMC')
|
@@ -1192,14 +1202,11 @@ def compute_noise_components(imgseries, mask_images, num_components,
|
1192 | 1202 | # "The covariance matrix C = MMT was constructed and decomposed into its
|
1193 | 1203 | # principal components using a singular value decomposition."
|
1194 | 1204 | try:
|
1195 |
| - u, _, _ = np.linalg.svd(M, full_matrices=False) |
| 1205 | + u, _, _ = fallback_svd(M, full_matrices=False) |
1196 | 1206 | except np.linalg.LinAlgError:
|
1197 |
| - try: |
1198 |
| - u, _, _ = linalg.svd(M, full_matrices=False, lapack_driver='gesvd') |
1199 |
| - except linalg.LinAlgError: |
1200 |
| - if self.inputs.failure_mode == 'error': |
1201 |
| - raise |
1202 |
| - u = np.ones((M.shape[0], num_components), dtype=np.float32) * np.nan |
| 1207 | + if self.inputs.failure_mode == 'error': |
| 1208 | + raise |
| 1209 | + u = np.ones((M.shape[0], num_components), dtype=np.float32) * np.nan |
1203 | 1210 | if components is None:
|
1204 | 1211 | components = u[:, :num_components]
|
1205 | 1212 | else:
|
@@ -1277,7 +1284,7 @@ def _full_rank(X, cmax=1e15):
|
1277 | 1284 | X: array of shape(nrows, ncols) after regularization
|
1278 | 1285 | cmax=1.e-15, float tolerance for condition number
|
1279 | 1286 | """
|
1280 |
| - U, s, V = np.linalg.svd(X, 0) |
| 1287 | + U, s, V = fallback_svd(X, full_matrices=False) |
1281 | 1288 | smax, smin = s.max(), s.min()
|
1282 | 1289 | c = smax / smin
|
1283 | 1290 | if c < cmax:
|
|
0 commit comments