File: gbtest80.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (126 lines) | stat: -rw-r--r-- 4,018 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function gbtest80
%GBTEST80 test complex division and power
% Tests all real, inf, and nan cases.

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

list = [-2:0.5:2 inf -inf nan] ;

fprintf ('gbtest80: test complex division and power') ;

maxerr = 0 ;
maxerr_single = 0 ;
stol = 1e-5 ;
dtol = 1e-14 ;

for xr = list
    fprintf ('\n%g ', xr) ;
    % fprintf ('\n------------------------------------------\n') ;
    for xi = list
        fprintf ('.')
        % fprintf ('\n') ;
        X = complex (xr, xi) ;
        GX = GrB (X) ;
        Xs = single (X) ;
        GXs = GrB (Xs) ;

        for yr = list
            for yi = list

                Y = complex (yr, yi) ;
                GY = GrB (Y) ;
                Ys = single (Y) ;
                GYs = GrB (Ys) ;

                Z = X / Y ;
                Z2 = GX / GY ;
                [err, errnan] = gbtest_err (Z, Z2) ;
                znorm = abs (Z) ;
                if (znorm > 1)
                    err = err / znorm ;
                end
                if (~errnan)
                    maxerr = max (maxerr, err) ;
                end
                if (err > dtol)
                    fprintf ('(%g,%g) / (%g,%g) = (%g,%g) (%g,%g)', ...
                        xr, xi, yr, yi, real (Z), imag (Z), ...
                        real (Z2), imag (Z2)) ;
                    fprintf (' err: %g', err) ;
                    fprintf (' DOUBLE DIFFERS') ;
                    fprintf ('\n') ;
                    % pause
                end

                Z = Xs / Ys ;
                Z2 = GXs / GYs ;
                [err, errnan] = gbtest_err (Z, Z2) ;
                znorm = abs (Z) ;
                if (znorm > 1)
                    err = err / znorm ;
                end
                if (~errnan)
                    maxerr_single = max (maxerr_single, err) ;
                end
                if (err > stol)
                    fprintf ('(%g,%g) / (%g,%g) = (%g,%g) (%g,%g)', ...
                        xr, xi, yr, yi, real (Z), imag (Z), ...
                        real (Z2), imag (Z2)) ;
                    fprintf (' err: %g', err) ;
                    fprintf (' SINGLE DIFFERS') ;
                    fprintf ('\n') ;
                    % pause
                end

                Z = X .^ Y ;
                Z2 = GX .^ GY ;
                [err, errnan] = gbtest_err (Z, Z2) ;
                znorm = abs (Z) ;
                if (znorm > 1)
                    err = err / znorm ;
                end
                if (~errnan)
                    maxerr = max (maxerr, err) ;
                end
                if (err > dtol)
                    fprintf ('(%g,%g) .^ (%g,%g) = (%g,%g) (%g,%g)', ...
                        xr, xi, yr, yi, real (Z), imag (Z), ...
                        real (Z2), imag (Z2)) ;
                    fprintf (' err: %g', err) ;
                    fprintf (' DOUBLE DIFFERS') ;
                    fprintf ('\n') ;
                    % pause
                end

                Z = Xs .^ Ys ;
                Z2 = GXs .^ GYs ;
                [err, errnan] = gbtest_err (Z, Z2) ;
                znorm = abs (Z) ;
                if (znorm > 1)
                    err = err / znorm ;
                end
                if (~errnan)
                    maxerr_single = max (maxerr_single, err) ;
                end
                if (err > stol)
                    fprintf ('(%g,%g) .^ (%g,%g) = (%g,%g) (%g,%g)', ...
                        xr, xi, yr, yi, real (Z), imag (Z), ...
                        real (Z2), imag (Z2)) ;
                    fprintf (' err: %g', err) ;
                    fprintf (' SINGLE DIFFERS') ;
                    fprintf ('\n') ;
                    % pause
                end

            end
        end
    end
end

fprintf ('\nmaxerr: %g %g\n', maxerr, maxerr_single) ;
assert (maxerr < dtol)
assert (maxerr_single < stol)

fprintf ('\ngbtest80: all tests passed\n') ;