annotate extra/NaN/inst/nantest.m @ 12656:ddbd9137910a octave-forge

fix nantest to avoid crashing Octave 4.0.0 on Windows
author schloegl
date Thu, 02 Jul 2015 11:14:16 +0000
parents 9a277c75a100
children aca981120490
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
1 % NANTEST checks several mathematical operations and a few
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
2 % statistical functions for their correctness related to NaN's.
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
3 % e.g. it checks norminv, normcdf, normpdf, sort, matrix division and multiplication.
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
4 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
5 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
6 % see also: NANINSTTEST
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
7 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
8 % REFERENCE(S):
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
9 % [1] W. Kahan (1996) Lecture notes on the Status of "IEEE Standard 754 for
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
10 % Binary Floating-point Arithmetic.
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
11 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
12
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
13
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
14 % This program is free software; you can redistribute it and/or modify
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
15 % it under the terms of the GNU General Public License as published by
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
16 % the Free Software Foundation; either version 2 of the License, or
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
17 % (at your option) any later version.
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
18 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
19 % This program is distributed in the hope that it will be useful,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
20 % but WITHOUT ANY WARRANTY; without even the implied warranty of
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
22 % GNU General Public License for more details.
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
23 %
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
24 % You should have received a copy of the GNU General Public License
4404
2de537641f94 More copyright updates
adb014
parents: 4352
diff changeset
25 % along with this program; If not, see <http://www.gnu.org/licenses/>.
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
26
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
27 % $Id$
8037
6a419bec96bb update contact e-mail and www address
schloegl
parents: 7889
diff changeset
28 % Copyright (C) 2000-2004,2009 by Alois Schloegl <alois.schloegl@gmail.com>
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
29 % This script is part of the NaN-toolbox
7889
c101c486d80a fix web address
schloegl
parents: 6787
diff changeset
30 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
31
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
32 %FLAG_WARNING = warning;
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
33 %warning('off');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
34
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
35 try
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
36 x = randn([3,4,5]);
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
37 x(~isnan(x)) = 0;
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
38 catch
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
39 fprintf(1,'WARNING: NANTEST fails for 3-DIM matrices. \n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
40 end;
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
41 try
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
42 [s,n] = sumskipnan([nan,1,4,5]);
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
43 catch
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
44 fprintf(1,'WARNING: SUMSKIPNAN is not avaible. \n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
45 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
46
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
47 % check NORMPDF, NORMCDF, NORMINV
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
48 x = [-inf,-2,-1,-.5,0,.5,1,2,3,inf,nan]';
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
49 if exist('normpdf','file')==2,
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
50 q(1) = sum(isnan(normpdf(x,2,0)))>sum(isnan(x));
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
51 if q(1),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
52 fprintf(1,'NORMPDF cannot handle v=0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
53 fprintf(1,'-> NORMPDF should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
54 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
55 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
56
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
57 if exist('normcdf','file')==2,
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
58 q(2) = sum(isnan(normcdf(x,2,0)))>sum(isnan(x));
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
59 if q(2),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
60 fprintf(1,'NORMCDF cannot handle v=0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
61 fprintf(1,'-> NORMCDF should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
62 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
63 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
64
12548
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
65 if ~(any(exist('erfinv') == [2,5]))
12389
4fa782b50c19 fix test for FreeMat 4.0
schloegl
parents: 8037
diff changeset
66 fprintf(1,'ERFINV is not available\n');
4fa782b50c19 fix test for FreeMat 4.0
schloegl
parents: 8037
diff changeset
67
4fa782b50c19 fix test for FreeMat 4.0
schloegl
parents: 8037
diff changeset
68 elseif exist('norminv','file')==2,
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
69 p = [-inf,-.2,0,.2,.5,1,2,inf,nan];
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
70 q(3) = sum(~isnan(norminv(p,2,0)))<4;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
71 if q(3),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
72 fprintf(1,'NORMINV cannot handle correctly v=0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
73 fprintf(1,'-> NORMINV should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
74 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
75 q(4) = ~isnan(norminv(0,NaN,0));
6535
3d73810fc628 fix of typo
schloegl
parents: 6534
diff changeset
76 q(5) = any(norminv(0.5,[1 2 3],0)~=(1:3));
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
77 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
78
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
79 if exist('tpdf','file')==2,
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
80 q(6) = ~isnan(tpdf(nan,4));
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
81 if q(6),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
82 fprintf(1,'TPDF(NaN,4) does not return NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
83 fprintf(1,'-> TPDF should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
84 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
85 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
86
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
87 if exist('tcdf','file')==2,
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
88 try
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
89 q(7) = ~isnan(tcdf(nan,4));
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
90 catch
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
91 q(7) = 1;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
92 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
93 if q(7),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
94 fprintf(1,'TCDF(NaN,4) does not return NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
95 fprintf(1,'-> TCDF should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
96 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
97 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
98
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
99 if exist('tinv','file')==2,
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
100 try
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
101 q(8) = ~isnan(tinv(nan,4));
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
102 catch
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
103 q(8) = 1;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
104 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
105 if q(8),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
106 fprintf(1,'TINV(NaN,4) does not return NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
107 fprintf(1,'-> TINV should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
108 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
109 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
110
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
111 q(9) = isreal(double(2+3i));
5741
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
112 if q(9)
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
113 printf('DOUBLE rejects imaginary part\n-> this can affect SUMSKIPNAN\n');
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
114 end;
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
115
6519
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
116 try
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
117 x = reshape(1:6,3,2);
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
118 [cc,nn] = covm(x+i*x,'e');
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
119 q(10) = 0;
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
120 catch
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
121 q(10) = 1;
d787e19c9410 fix several minor issues
schloegl
parents: 5741
diff changeset
122 end;
5741
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
123
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
124 if 0,
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
125 %%%%% MOD
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
126 if exist('mod')>1,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
127 if (mod(5,0))~=0,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
128 fprintf(1,'WARNING: MOD(x,0) does not return 0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
129 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
130 if isnan(mod(5,0)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
131 fprintf(1,'WARNING: MOD(x,0) returns NaN.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
132 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
133 if isnan(mod(5,inf)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
134 fprintf(1,'WARNING: MOD(x,INF) returns NaN.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
135 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
136 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
137 %%%%% REM
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
138 if exist('rem')>1,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
139 if (rem(5,0))~=0,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
140 fprintf(1,'WARNING: REM(x,0) does not return 0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
141 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
142 if isnan(rem(5,0)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
143 fprintf(1,'WARNING: REM(x,0) returns NaN.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
144 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
145 if isnan(mod(5,inf)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
146 fprintf(1,'WARNING: REM(x,INF) returns NaN.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
147 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
148 end;
5741
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
149 end;
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
150
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
151 %%%%% NANSUM(NAN) - this test addresses a problem in Matlab 5.3, 6.1 & 6.5
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
152 if exist('nansum','file'),
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
153 if isnan(nansum(nan)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
154 fprintf(1,'Warning: NANSUM(NaN) returns NaN instead of 0\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
155 fprintf(1,'-> NANSUM should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
156 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
157 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
158 %%%%% NANSUM(NAN) - this test addresses a problem in Matlab 5.3, 6.1 & 6.5
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
159 if exist('nanstd','file'),
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
160 if ~isnan(nanstd(0)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
161 fprintf(1,'Warning: NANSTD(x) with isscalar(x) returns 0 instead of NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
162 fprintf(1,'-> NANSTD should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
163 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
164 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
165 %%%%% GEOMEAN - this test addresses a problem in Octave
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
166 if exist('geomean','file'),
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
167 if isnan(geomean((0:3)')),
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
168 fprintf(1,'Warning: GEOMEAN([0,1,2,3]) NaN instead of 0\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
169 fprintf(1,'-> GEOMEAN should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
170 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
171 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
172 %%%%% HARMMEAN - this test addresses a problem in Octave
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
173 if exist('harmmean','file'),
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
174 if isnan(harmmean(0:3)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
175 fprintf(1,'Warning: HARMMEAN([0,1,2,3]) NaN instead of 0\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
176 fprintf(1,'-> HARMMEAN should be replaced\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
177 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
178 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
179 %%%%% BITAND - this test addresses a problem in Octave
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
180 if exist('bitand')>1,
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
181 if isnan(bitand(2^33-1,13)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
182 fprintf(1,'BITAND can return NaN. \n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
183 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
184 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
185 %%%%% BITSHIFT - this test addresses a problem in Octave
6534
bb399a7e3a11 major cleanup
schloegl
parents: 6519
diff changeset
186 if exist('bitshift','file'),
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
187 if isnan(bitshift(5,30,32)),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
188 fprintf(1,'BITSHIFT can return NaN.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
189 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
190 end;
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
191 %%%%% ALL - this test addresses a problem in some old Octave and FreeMat v3.5
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
192 if any(NaN)==1,
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
193 fprintf(1,'WARNING: ANY(NaN) returns 1 instead of 0\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
194 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
195 if any([])==1,
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
196 fprintf(1,'WARNING: ANY([]) returns 1 instead of 0\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
197 end;
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
198 %%%%% ALL - this test addresses a problem in some old Octave and FreeMat v3.5
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
199 if all(NaN)==0,
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
200 fprintf(1,'WARNING: ALL(NaN) returns 0 instead of 1\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
201 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
202 if all([])==0,
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
203 fprintf(1,'WARNING: ALL([]) returns 0 instead of 1\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
204 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
205
12389
4fa782b50c19 fix test for FreeMat 4.0
schloegl
parents: 8037
diff changeset
206 %%%%% SORT - this was once a problem in Octave Version < 2.1.36, and still is in FreeMat 4.0 %%%%
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
207 if ~all(isnan(sort([3,4,NaN,3,4,NaN]))==[0,0,0,0,1,1]),
12389
4fa782b50c19 fix test for FreeMat 4.0
schloegl
parents: 8037
diff changeset
208 warning('Warning: SORT does not properly handle NaN.');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
209 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
210
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
211 %%%%% commutativity of 0*NaN %%% This test adresses a problem in Octave
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
212 x=[-2:2;4:8]';
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
213 y=x;y(2,1)=nan;y(4,2)=nan;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
214 B=[1,0,2;0,3,1];
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
215 if ~all(all(isnan(y*B)==isnan(B'*y')')),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
216 fprintf(2,'WARNING: 0*NaN within matrix multiplication is not commutative\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
217 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
218
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
219 % from Kahan (1996)
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
220 tmp = (0-3*i)/inf;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
221 if isnan(tmp)
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
222 fprintf(2,'WARNING: (0-3*i)/inf results in NaN instead of 0.\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
223 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
224
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
225 %(roots([5,0,0])-[0;0])
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
226 %(roots([2,-10,12])-[3;2])
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
227 %(roots([2e-37,-2,2])-[1e37;1])
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
228 %%%%% check nan/nan %% this test addresses a problem in Matlab 5.3, 6.1 & 6.5
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
229 p = 4;
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
230 tmp1 = repmat(nan, 4);
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
231 tmp2 = repmat(nan, 4);
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
232 if ~ispc
12548
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
233 try
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
234 tmp1 = repmat(nan,p)/repmat(nan,p);
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
235 catch % exception error in Octave 3.8.2 of debian wheezy
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
236 fprintf(2,'repmat(nan,4)/repmat(nan,4) fails with an exception\n');
12548
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
237 end;
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
238 try
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
239 tmp2 = repmat(nan,p)\repmat(nan,p);
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
240 catch % exception error in Octave 3.8.2 of debian wheezy
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
241 fprintf(2,'repmat(nan,4)\repmat(nan,4) fails with an exception\n');
12548
9a277c75a100 fix compatibility issue with octave 3.8.2 in debian/jessie
schloegl
parents: 12515
diff changeset
242 end
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
243 end;
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
244 tmp3 = repmat(0,p)/repmat(0,p);
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
245 tmp4 = repmat(0,p)\repmat(0,p);
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
246 tmp5 = repmat(0,p)*repmat(inf,p);
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
247 tmp6 = repmat(inf,p)*repmat(0,p);
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
248 x = randn(100,1)*ones(1,p); y=x'*x;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
249 tmp7 = y/y;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
250 tmp8 = y\y;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
251
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
252 if ~all(isnan(tmp1(:))),
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
253 fprintf(1,'WARNING: matrix division NaN/NaN does not result in NaN\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
254 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
255 if ~all(isnan(tmp2(:))),
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
256 fprintf(1,'WARNING: matrix division NaN\\NaN does not result in NaN\n');
2414
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
257 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
258 if ~all(isnan(tmp3(:))),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
259 fprintf(2,'WARNING: matrix division 0/0 does not result in NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
260 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
261 if ~all(isnan(tmp4(:))),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
262 fprintf(2,'WARNING: matrix division 0\\0 does not result in NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
263 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
264 if ~all(isnan(tmp5(:))),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
265 fprintf(2,'WARNING: matrix multiplication 0*inf does not result in NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
266 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
267 if ~all(isnan(tmp6(:))),
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
268 fprintf(2,'WARNING: matrix multiplication inf*0 does not result in NaN\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
269 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
270 if any(any(tmp7==inf));
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
271 fprintf(2,'WARNING: right division of two singulare matrices return INF\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
272 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
273 if any(any(tmp8==inf));
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
274 fprintf(2,'WARNING: left division of two singulare matrices return INF\n');
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
275 end;
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
276
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
277 tmp = [tmp1;tmp2;tmp3;tmp4;tmp5;tmp6;tmp7;tmp8];
19251cd2753b Latest package manager mega patch, but not the last
adb014
parents:
diff changeset
278
5741
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
279
f0955d62224a faster exist() improves performance (especially in covm.m)
schloegl
parents: 5425
diff changeset
280
4352
bf0641a79d27 fix warning text
schloegl
parents: 3761
diff changeset
281 %warning(FLAG_WARNING);
3761
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
282
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
283
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
284 %%%%% QUANTILE TEST
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
285 d = [1 1 2 2 4 4 10 700]';
3761
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
286 q = [-1,0,.05,.1,.25,.49,.5,.51,.75,.8, .999999,1,2];
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
287 r = [ NaN, 1, 1, 1, 1.5, 2, 3, 4, 7, 10, 700, 700, NaN];
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
288 if any( quantile(d, q)' - r>0)
3761
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
289 fprintf(1,'Quantile(1): failed\n');
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
290 else
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
291 fprintf(1,'Quantile(1): OK\n');
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
292 end;
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
293 if exist('histo3','file')
12656
ddbd9137910a fix nantest to avoid crashing Octave 4.0.0 on Windows
schloegl
parents: 12548
diff changeset
294 H = histo3(d);
3761
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
295 else
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
296 H.X = [1;2;4;10;700];
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
297 H.H = [2;2;2;1;1];
5425
38ca720979c2 fix typo
schloegl
parents: 4404
diff changeset
298 H.datatype = 'HISTOGRAM';
3761
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
299 end;
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
300 if any( quantile(H, q)' - r>0)
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
301 fprintf(1,'Quantile(2): failed\n');
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
302 else
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
303 fprintf(1,'Quantile(2): OK\n');
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
304 end;
ddf14ae10671 add test for quantile
schloegl
parents: 3268
diff changeset
305