Skip to content

Commit

Permalink
FIX: Do not create a dense matrix along the way
Browse files Browse the repository at this point in the history
Backport niprepsgh-299
  • Loading branch information
oesteban authored and effigies committed Dec 7, 2022
1 parent 97cdd09 commit 8816083
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sdcflows/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,15 @@ def grid_bspline_weights(target_nii, ctrl_nii):

within_support = distance < 2.0
d_vals, d_idxs = np.unique(distance[within_support], return_inverse=True)
bs_w = _cubic_bspline(d_vals)
weights = np.zeros_like(distance, dtype="float32")
weights[within_support] = bs_w[d_idxs]
# Calculate univariate B-Spline weight for samples within kernel spread
weights_vals = _cubic_bspline(d_vals)[d_idxs].astype("float32")

# Build csr matrix
rows, cols = np.where(within_support)
weights = csr_matrix(
(weights_vals, (rows, cols)),
shape=distance.shape,
)
wd.append(csr_matrix(weights))

return kron(kron(wd[0], wd[1]), wd[2])
Expand Down

0 comments on commit 8816083

Please sign in to comment.