1function gbtest7 2%GBTEST7 test GrB.build 3 4% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 5% SPDX-License-Identifier: GPL-3.0-or-later 6 7rng ('default') ; 8 9n = 5 ; 10A = sprand (n, n, 0.5) ; 11A (n,n) = 5 ; 12 13[i, j, x] = find (A) ; 14[m, n] = size (A) ; 15 16G = GrB.build (i, j, x, m, n) ; 17S = sparse (i, j, x, m, n) ; 18assert (gbtest_eq (S, G)) ; 19 20d.kind = 'GrB' ; 21G = GrB.build (i, j, x, m, n, d) ; 22assert (gbtest_eq (S, G)) ; 23 24d.kind = 'sparse' ; 25G = GrB.build (i, j, x, m, n, d) ; 26assert (gbtest_eq (S, G)) 27 28i0 = int64 (i) - 1 ; 29j0 = int64 (j) - 1 ; 30 31G = GrB.build (i0, j0, x, struct ('base', 'zero-based')) ; 32assert (gbtest_eq (S, G)) ; 33 34G = GrB.build (1:3, 1:3, [1 1 1]) ; 35assert (gbtest_eq (speye (3), G)) ; 36 37G = GrB.build (1, 1, [1 2 3]) ; 38assert (isequal (sparse (6), G)) ; 39 40G = GrB.build (1:3, 1:3, 1) ; 41assert (isequal (speye (3), G)) ; 42 43types = gbtest_types ; 44for k = 1: length(types) 45 type = types {k} ; 46 X = full (gbtest_cast (1, type)) ; 47 G = GrB.build (1:3, 1:3, X) ; 48 S = gbtest_cast (eye (3, 3), type) ; 49 assert (gbtest_eq (S, G)) ; 50 assert (isequal (GrB.type (G), type)) ; 51end 52 53fprintf ('gbtest7: all tests passed\n') ; 54 55