File: test_single.m

package info (click to toggle)
mwrap 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: cpp: 3,271; ansic: 856; makefile: 252; lex: 233; sh: 2
file content (104 lines) | stat: -rw-r--r-- 3,057 bytes parent folder | download | duplicates (4)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function test_single
% pass-fail test of the single- and double-precision args and arrays.
% must do either make test_single_cpp or make test_single_c99 first.
% Barnett & Gimbutas. 7/20/20

tol = 2e-16;
tols = 1e-7;
%format long g  % for debug


%fprintf('scalar real routines...\n') % -------------------------------------
x = 1/3; ce = x+x; xf = single(x);
c = add(x,x);
assert(abs(c-ce)<tol)
assert(class(c)=='double')

try
c = add(xf,xf);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid scalar argument, mxDOUBLE_CLASS expected')
end

try
c = addf(x,x);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid scalar argument, mxSINGLE_CLASS expected')
end

c = addf(xf,xf);  % input as designed, should give single
assert(abs(double(c)-ce)<tols)
assert(abs(double(c)-ce)>tol)   % test it's not doing double-prec!
assert(class(c)=='single')


%fprintf('\narray real routines...\n')  % ------------------------------------
x = x*ones(3,1); xf = xf*ones(3,1); ce=x+x;
c = arradd(x,x);
assert(norm(c-ce)<tol)
assert(class(c)=='double'); % double->double, as mwrap 0.33.3 designed for!

try
c = arradd(xf,xf);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid array argument, mxDOUBLE_CLASS expected');
end

try
c = arraddf(x,x);  % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid array argument, mxSINGLE_CLASS expected');
end

c = arraddf(xf,xf);   % input as designed, should give single
assert(norm(double(c)-ce)<tols)
assert(norm(double(c)-ce)>tol)   % test it's not doing double-prec!
assert(class(c)=='single')


%fprintf('\nscalar complex routines...\n')  % -------------------------------
z = (1+2i)/3; zf = single(z); ce = z+z;
c = addz(z,z);
assert(abs(c-ce)<tol)
assert(class(c)=='double');    % double->double, as mwrap 0.33.3 designed for!

try
c = addz(zf,zf);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid scalar argument, mxDOUBLE_CLASS expected');
end

try
c = addc(z,z);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid scalar argument, mxSINGLE_CLASS expected');
end

c = addc(zf,zf);   % input as designed, should give single
assert(abs(double(c)-ce)<tols)
assert(abs(double(c)-ce)>tol)   % test it's not doing double-prec!
assert(class(c)=='single')


% fprintf('\narray complex routines...\n')  % --------------------------------
z = z*ones(3,1); zf = zf*ones(3,1); ce = z+z;
c = arraddz(z,z);     % input as designed, double
assert(norm(c-ce)<tol)
assert(class(c)=='double'); % double->double, as mwrap 0.33.3 designed for!

try
c = arraddz(zf,zf);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid array argument, mxDOUBLE_CLASS expected');
end

try
c = arraddc(z,z);   % should error
catch ME
  assert(ME.message=='test_singlemex: Invalid array argument, mxSINGLE_CLASS expected');
end

c = arraddc(zf,zf);    % input as designed, should give single
assert(norm(double(c)-ce)<tols)
assert(norm(double(c)-ce)>tol)   % test it's not doing double-prec!
assert(class(c)=='single')