Skip to content

Commit

Permalink
ENH - some generic speedups and depth-of-recursion limitation (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
schoffelen committed Oct 15, 2021
1 parent 4be7088 commit f29aadf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ft_sourceinterpolate.m
Expand Up @@ -128,8 +128,8 @@
anatomical = fixpos(anatomical);
functional = fixpos(functional);

% ensure the functional data to be in double precision
functional = ft_struct2double(functional);
% ensure the functional data to be in double precision, the maxdepth parameter ensure double precision up to the content of functional.avg.mom{:}, avoiding too much recursion
functional = ft_struct2double(functional, 3);

if (strcmp(cfg.interpmethod, 'nearest') || strcmp(cfg.interpmethod, 'mode')) && (ft_datatype(functional, 'volume+label') || ft_datatype(functional, 'source+label') || ft_datatype(functional, 'mesh+label'))
% the first input argument describes a parcellation or segmentation with tissue labels
Expand Down
10 changes: 8 additions & 2 deletions utilities/ft_struct2double.m
Expand Up @@ -63,15 +63,21 @@
% warning, this is a recursive call to traverse nested structures
for i=1:length(fna)
fn = fna{i};
ra = getfield(a(j), fn);
ra = a(j).(fn);
ra = convert(ra, depth+1, maxdepth);
a(j) = setfield(a(j), fn, ra);
a(j).(fn) = ra;
end
end

case 'cell'
% process all elements of the cell-array recursively
% warning, this is a recursive call to traverse nested structures

% the recursion is only needed if the maxdepth allows it
if depth+1>maxdepth
return
end

for i=1:length(a(:))
a{i} = convert(a{i}, depth+1, maxdepth);
end
Expand Down

0 comments on commit f29aadf

Please sign in to comment.