-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericDebugCheck.m
54 lines (49 loc) · 1.54 KB
/
GenericDebugCheck.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% [TimeInput,TimeCast,resCuda]=GenericDebugCheck(fkt,TypeString,varargin) : checks if the performance of a function is identical between two datatypes
% fkt : function to test
% TypeString : string of the datatype to cast to
% varargin : matlab inputs which are converted to other datatype
%
% Example:
% a= [1 2 3];b=[4 5 6];
% GenericDebugCheck('plus','dip_image',@double,dip_image(a),b);
%
function [TimeInput,TimeCast,resVal]=GenericDebugCheck(fkt,TypeString,myCast,varargin)
argMatlab=cell(1,nargin-3);
Nout = nargout-2;
if Nout<= 0
Nout=1;
end
inargs=varargin;
for n=1:numel(inargs)
if (isa(inargs{n},TypeString))
argMatlab{n}=myCast(inargs{n}); % convert to double or dip_image
else
argMatlab{n}=inargs{n};
end
end
resMatlab=cell(1,Nout);
tic
eval(['[resMatlab{:}]=' fkt '(argMatlab{:});']);
TimeCast=toc;
%% Compare Matlab to CudaMat result
resType=cell(1,Nout);
% setCudaSynchronize(1);
tic
eval(['[resType{:}]=' fkt '(inargs{:});']);
TimeInput=toc;
% setCudaSynchronize(0); pause(1);
for n=1:Nout
D=double(resMatlab{n}- myCast(resType{n}));
D=norm(D(:));
M1=max(abs(resMatlab{n}(:)));
M2=max(abs(resType{n}(:)));
M=max(M1,M2);
fprintf('checked function %s type %s .. relative error is %d percent\n',fkt,TypeString,D/M*100);
if (D/M > 0.01) % one percent error leads to scream
error('Function %s: detected disagreement of results!',fkt);
end
end
fprintf('checked function %s type %s .. relative error is %d percent\n',fkt,TypeString,D/M*100);
if Nout>0
resVal=resType{:};
end