File: gbtest79.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 (89 lines) | stat: -rw-r--r-- 2,069 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
function gbtest79
%GBTEST79 test real 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 ('gbtest79: test power') ;

maxerr = 0 ;
maxerr_single = 0 ;

for xr = list
    fprintf ('.') ;

    X = xr ;
    GX = GrB (X) ;
    Xs = single (X) ;
    GXs = GrB (Xs) ;

    for yr = list
        Y = yr ;
        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 > 0)
            err = err / znorm ;
        end

        if (err > 1e-14)
            fprintf ('(%g) .^ (%g) = (%g,%g) (%g,%g)', ...
                xr, yr, real (Z), imag (Z), ...
                real (Z2), imag (Z2)) ;
            fprintf (' err: %g', err) ;
            fprintf (' DOUBLE DIFFERS') ;
            fprintf ('\n') ;
            % pause
        end
        if (~errnan)
            maxerr = max (maxerr, err) ;
        end
        % assert (err < 1e-14)

        Z = Xs .^ Ys ;
        Z2 = GXs .^ GYs ;
        [err, errnan] = gbtest_err (Z, Z2) ;
        znorm = abs (Z) ;
        if (znorm > 0)
            err = err / znorm ;
        end
        if (~errnan)
            maxerr_single = max (maxerr_single, err) ;
        end

        if (err > 1e-6)
            fprintf ('(%g) .^ (%g) = (%g,%g) (%g,%g)', ...
                xr, yr, real (Z), imag (Z), ...
                real (Z2), imag (Z2)) ;
            fprintf (' err: %g', err) ;
            fprintf (' SINGLE DIFFERS') ;
            fprintf ('\n') ;
            % pause
        end

        % assert (maxerr_single < 1e-6) ;
    end
end

A = int32 (magic (4)) ;
B = int32 (2 * rand (4)) ;
GA = GrB (A) ;
GB = GrB (B) ;
C1 = A.^B ;
C2 = GA.^GB ;
assert (isequal (C1, C2)) ;

fprintf ('\nmaxerr: %g %g\n', maxerr, maxerr_single) ;
assert (maxerr < 1e-14)
assert (maxerr_single < 1e-6)

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