Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cuslines/cuda_python/cu_propagate_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@


class SeedBatchPropagator:
def __init__(self, gpu_tracker):
def __init__(self, gpu_tracker, minlen=0, maxlen=np.inf):
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type hints for minlen and maxlen parameters. The gpu_tracker parameter should also have a type hint. Consider adding type hints for consistency with the rest of the codebase, e.g., gpu_tracker should reference the GPUTracker class, and minlen/maxlen should be typed appropriately (int for minlen, Union[int, float] for maxlen since it can be np.inf).

Copilot uses AI. Check for mistakes.
self.gpu_tracker = gpu_tracker
self.ngpus = gpu_tracker.ngpus
self.minlen = minlen
self.maxlen = maxlen

self.nSlines_old = np.zeros(self.ngpus, dtype=np.int32)
self.nSlines = np.zeros(self.ngpus, dtype=np.int32)
Expand Down Expand Up @@ -240,6 +242,8 @@ def get_buffer_size(self):
for ii in range(self.ngpus):
lens = self.sline_lens[ii]
for jj in range(self.nSlines[ii]):
if lens[jj] < self.minlen or lens[jj] > self.maxlen:
continue
buffer_size += lens[jj] * 3 * REAL_SIZE
return math.ceil(buffer_size / MEGABYTE)

Expand All @@ -252,9 +256,14 @@ def _yield_slines():
for jj in range(self.nSlines[ii]):
npts = this_len[jj]

if npts < self.minlen or npts > self.maxlen:
continue

yield np.asarray(this_sls[jj], dtype=REAL_DTYPE)[:npts]

return _yield_slines()

def as_array_sequence(self):
return ArraySequence(self.as_generator(), self.get_buffer_size())
return ArraySequence(
self.as_generator(),
self.get_buffer_size())
18 changes: 15 additions & 3 deletions cuslines/cuda_python/cu_tractography.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(
sphere_edges: np.ndarray,
max_angle: float = radians(60),
step_size: float = 0.5,
min_pts=0,
max_pts=np.inf,
Comment on lines +47 to +48
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type hints for min_pts and max_pts parameters. All other parameters in this function signature have explicit type hints (e.g., max_angle: float, ngpus: int). These parameters should follow the same pattern for consistency.

Suggested change
min_pts=0,
max_pts=np.inf,
min_pts: int = 0,
max_pts: float = np.inf,

Copilot uses AI. Check for mistakes.
relative_peak_thresh: float = 0.25,
min_separation_angle: float = radians(45),
ngpus: int = 1,
Expand Down Expand Up @@ -74,8 +76,14 @@ def __init__(
Maximum angle (in radians) between steps
default: radians(60)
step_size : float, optional
Step size for tracking
Step size for tracking, in voxels
default: 0.5
min_pts : int, optional
Minimum number of points in a streamline to be kept
default: 0
max_pts : int, optional
Maximum number of points in a streamline to be kept
default: np.inf
Comment on lines +81 to +86
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states max_pts is of type int, but the default value is np.inf (a float). This type mismatch in the documentation could confuse users. Consider updating the documentation to reflect that max_pts can be either int or float, or use Union[int, float] in the type hint to be more accurate.

Suggested change
min_pts : int, optional
Minimum number of points in a streamline to be kept
default: 0
max_pts : int, optional
Maximum number of points in a streamline to be kept
default: np.inf
min_pts : int or float, optional
Minimum number of points in a streamline to be kept
default: 0
max_pts : int or float, optional
Maximum number of points in a streamline to be kept. Use
np.inf for no upper limit (default).

Copilot uses AI. Check for mistakes.
relative_peak_thresh : float, optional
Relative peak threshold for direction selection
default: 0.25
Expand Down Expand Up @@ -136,7 +144,11 @@ def __init__(
self.streams = []
self.managed_data = []

self.seed_propagator = SeedBatchPropagator(gpu_tracker=self)
self.seed_propagator = SeedBatchPropagator(
gpu_tracker=self,
minlen=min_pts,
maxlen=max_pts
Comment on lines +147 to +150
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent parameter naming between GPUTracker and SeedBatchPropagator. GPUTracker uses min_pts/max_pts while SeedBatchPropagator uses minlen/maxlen. For better clarity and consistency, consider aligning the naming (e.g., both using min_pts/max_pts or both using minlen/maxlen). The current naming might confuse future maintainers about whether these represent the same concept.

Suggested change
self.seed_propagator = SeedBatchPropagator(
gpu_tracker=self,
minlen=min_pts,
maxlen=max_pts
minlen = min_pts
maxlen = max_pts
self.seed_propagator = SeedBatchPropagator(
gpu_tracker=self,
minlen=minlen,
maxlen=maxlen

Copilot uses AI. Check for mistakes.
)
self._allocated = False

def __enter__(self):
Expand Down Expand Up @@ -260,7 +272,7 @@ def generate_trx(self, seeds, ref_img):

# Will resize by a factor of 2 if these are exceeded
sl_len_guess = 100
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from sl_per_seed_guess = 4 to sl_per_seed_guess = 2 appears unrelated to adding min/max length filtering. This change affects memory allocation for TRX file generation and could impact performance if the actual number of streamlines per seed exceeds this guess (causing more frequent resizes). If this change is intentional and related to the filtering reducing expected streamlines per seed, it should be documented in the PR description or as a comment in the code.

Suggested change
sl_len_guess = 100
sl_len_guess = 100
# Heuristic: initial guess of how many streamlines we get per seed.
# With the current min/max length filtering in the GPU propagator we
# typically obtain fewer valid streamlines per seed than before, so
# we lower the guess from 4 to 2 to avoid over-allocating memory.
# If the filtering or seeding strategy changes (e.g. more accepted
# streamlines per seed), this value should be re-evaluated to balance
# memory usage against the cost of TRX internal resizes.

Copilot uses AI. Check for mistakes.
sl_per_seed_guess = 4
sl_per_seed_guess = 2
n_sls_guess = sl_per_seed_guess * seeds.shape[0]

# trx files use memory mapping
Expand Down
Loading