File: gbtest42.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 (52 lines) | stat: -rw-r--r-- 1,309 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
function gbtest42
%GBTEST42 test for nan

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

rng ('default') ;
types = { 'single', 'double', 'single complex', 'double complex' } ;

for k1 = 1:length(types)
    atype = types {k1} ;
    fprintf ('\n%s ', atype) ;

    for trial = 1:40
        fprintf ('.') ;

        A = gbtest_cast (full (sprand (4,4,0.5)), atype) ;
        A (A > 0.5) = nan ;

        A_nan = zeros (4, 4) ;
        A_nan (isnan (A)) = nan ;
        A_notnan = zeros (4, 4) ;
        A_notnan (~isnan (A)) = A (~isnan (A)) ;

        A = gbtest_cast (A, atype) ;

        for k2 = 1:length(types)
            xtype = types {k2} ;
            xnan = gbtest_cast (nan, xtype) ;

            G = GrB.select (A, '==', xnan) ;
            X1 = full (double (G)) ;
            X2 = double (A_nan) ;
            assert (isequaln (X1, X2)) ;

            G = GrB.select (A, '~=', xnan) ;
            X1 = full (double (G)) ;
            X2 = double (A_notnan) ;
            assert (isequaln (X1, X2)) ;

            G = GrB.prune (A, xnan) ;
            X1 = full (double (G)) ;
            X2 = double (A_notnan) ;
            assert (isequaln (X1, X2)) ;

        end
    end

end

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