Skip to content

Commit

Permalink
RF+ACK: simplify isequaln. This also marks the end of the second meet…
Browse files Browse the repository at this point in the history
…ing of LABMAN, the Latin American Brain Mapping Network, in Buenos Aires, Argentina. Thanks to all who made this possible, it was a pleasure.
  • Loading branch information
nno committed Mar 26, 2017
1 parent ab55cb1 commit d5a1527
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions mvpa/cosmo_isequaln.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
% to be equal; false otherwise
%
% Examples:
% cosmo_isequaln(2,2)
% > true
% cosmo_isequaln(2,3)
% > false
% % using the builtin isequal, NaNs are considered not equal to each other
% isequal(NaN,NaN)
% > false
% % using cosmo_isequaln, NaNs are considered to be equal to each other
% cosmo_isequaln(NaN,NaN)
% > true
% cosmo_isequaln(2,2)
% > true
% cosmo_isequaln(2,3)
% > false
% % using the builtin isequal, NaNs are considered not equal
% isequal(NaN,NaN)
% > false
% % using cosmo_isequaln, NaNs are considered to be equal to each other
% cosmo_isequaln(NaN,NaN)
% > true

% Notes:
% - in earlier versions of Matlab, isequaln did not exist;
Expand All @@ -40,7 +40,7 @@
persistent cached_comparison_func

if isempty(cached_comparison_func)
cached_comparison_func=find_comparison_func_helper;
cached_comparison_func=find_comparison_func_helper();
end

func=cached_comparison_func;
Expand All @@ -49,16 +49,15 @@
function func=find_comparison_func_helper()
candidates={@isequaln,@isequalwithequalnans};

has_func=@(x)~isempty(which(func2str(x),'builtin'));
idx=find(cellfun(has_func,candidates),1,'first');
candidates_str=cellfun(@func2str, candidates,...
'UniformOutput',false);

has_func=@(x)~isempty(which(x,'builtin'));
idx=find(cellfun(has_func,candidates_str),1,'first');
if ~isempty(idx)
func=candidates{idx};
return
end


candidates_str=cellfun(@func2str, candidates,...
'UniformOutput',false);

error('No comparison function found from candidates: %s',...
cosmo_strjoin(candidates_str,', '));

0 comments on commit d5a1527

Please sign in to comment.