Line data Source code
1 : //------------------------------------------------------------------------------
2 : // LAGraph/src/test/test_Random_Matrix.c: test cases for random matrix generator
3 : //------------------------------------------------------------------------------
4 :
5 : // LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
6 : // SPDX-License-Identifier: BSD-2-Clause
7 : //
8 : // For additional details (including references to third party source code and
9 : // other files) see the LICENSE file or contact permission@sei.cmu.edu. See
10 : // Contributors.txt for a full list of contributors. Created, in part, with
11 : // funding and support from the U.S. Government (see Acknowledgments.txt file).
12 : // DM22-0790
13 :
14 : // Contributed by Timothy A. Davis, Texas A&M University
15 :
16 : //------------------------------------------------------------------------------
17 :
18 : #include <stdio.h>
19 : #include <acutest.h>
20 : #include <LAGraphX.h>
21 : #include <LAGraph_test.h>
22 :
23 : char msg [LAGRAPH_MSG_LEN] ;
24 : GrB_Vector Seed = NULL ;
25 : GrB_Matrix A = NULL ;
26 : GrB_Type MyInt = NULL ;
27 : typedef int myint ;
28 :
29 : //------------------------------------------------------------------------------
30 : // test_Random_Matrix
31 : //------------------------------------------------------------------------------
32 :
33 1 : void test_Random_Matrix (void)
34 : {
35 1 : LAGraph_Init (msg) ;
36 1 : OK (LAGraph_Random_Init (msg)) ;
37 :
38 1 : uint64_t seed = 42 ;
39 1 : LAGraph_PrintLevel pr = LAGraph_COMPLETE_VERBOSE ;
40 :
41 6 : for (int trial = 0 ; trial <= 4 ; trial++)
42 : {
43 5 : seed++ ;
44 5 : printf ("\n=============================== seed: %g\n", (double) seed) ;
45 :
46 5 : double d = (trial == 4) ? INFINITY : ((double) trial / 4) ;
47 5 : printf ("density: %g, expected values: %g\n", d, d*20) ;
48 :
49 5 : printf ("\n----------------bool:\n") ;
50 5 : OK (LAGraph_Random_Matrix (&A, GrB_BOOL, 4, 5, d, seed, msg)) ;
51 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
52 5 : OK (GrB_free (&A)) ;
53 :
54 5 : printf ("\n----------------int8:\n") ;
55 5 : OK (LAGraph_Random_Matrix (&A, GrB_INT8, 4, 5, d, seed, msg)) ;
56 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
57 5 : OK (GrB_free (&A)) ;
58 :
59 5 : printf ("\n----------------int16:\n") ;
60 5 : OK (LAGraph_Random_Matrix (&A, GrB_INT16, 4, 5, d, seed, msg)) ;
61 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
62 5 : OK (GrB_free (&A)) ;
63 :
64 5 : printf ("\n----------------int32:\n") ;
65 5 : OK (LAGraph_Random_Matrix (&A, GrB_INT32, 4, 5, d, seed, msg)) ;
66 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
67 5 : OK (GrB_free (&A)) ;
68 :
69 5 : printf ("\n----------------int64:\n") ;
70 5 : OK (LAGraph_Random_Matrix (&A, GrB_INT64, 4, 5, d, seed, msg)) ;
71 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
72 5 : OK (GrB_free (&A)) ;
73 :
74 5 : printf ("\n----------------uint8:\n") ;
75 5 : OK (LAGraph_Random_Matrix (&A, GrB_UINT8, 4, 5, d, seed, msg)) ;
76 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
77 5 : OK (GrB_free (&A)) ;
78 :
79 5 : printf ("\n----------------uint16:\n") ;
80 5 : OK (LAGraph_Random_Matrix (&A, GrB_UINT16, 4, 5, d, seed, msg)) ;
81 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
82 5 : OK (GrB_free (&A)) ;
83 :
84 5 : printf ("\n----------------uint32:\n") ;
85 5 : OK (LAGraph_Random_Matrix (&A, GrB_UINT32, 4, 5, d, seed, msg)) ;
86 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
87 5 : OK (GrB_free (&A)) ;
88 :
89 5 : printf ("\n----------------uint64:\n") ;
90 5 : OK (LAGraph_Random_Matrix (&A, GrB_UINT64, 4, 5, d, seed, msg)) ;
91 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
92 5 : OK (GrB_free (&A)) ;
93 :
94 5 : printf ("\n----------------fp32:\n") ;
95 5 : OK (LAGraph_Random_Matrix (&A, GrB_FP32, 4, 5, d, seed, msg)) ;
96 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
97 5 : OK (GrB_free (&A)) ;
98 :
99 5 : printf ("\n----------------fp64:\n") ;
100 5 : OK (LAGraph_Random_Matrix (&A, GrB_FP64, 4, 5, d, seed, msg)) ;
101 5 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
102 5 : OK (GrB_free (&A)) ;
103 :
104 : }
105 :
106 1 : printf ("\n----------------empty bool:\n") ;
107 1 : OK (LAGraph_Random_Matrix (&A, GrB_BOOL, 0, 5, 0.5, seed, msg)) ;
108 1 : OK (LAGraph_Matrix_Print (A, pr, stdout, NULL)) ;
109 1 : OK (GrB_free (&A)) ;
110 :
111 1 : printf ("\n----------------invalid type:\n") ;
112 1 : OK (GrB_Type_new (&MyInt, sizeof (myint))) ;
113 1 : int result = LAGraph_Random_Matrix (&A, MyInt, 0, 5, 0.5, seed, msg) ;
114 1 : printf ("result %d msg [%s]\n", result, msg) ;
115 1 : TEST_CHECK (result == GrB_NOT_IMPLEMENTED) ;
116 1 : OK (GrB_free (&MyInt)) ;
117 :
118 1 : OK (LAGraph_Random_Finalize (msg)) ;
119 1 : LAGraph_Finalize (msg) ;
120 1 : }
121 :
122 : //------------------------------------------------------------------------------
123 : // Test list
124 : //------------------------------------------------------------------------------
125 :
126 : TEST_LIST = {
127 : {"Random_Matrix", test_Random_Matrix},
128 : {NULL, NULL}
129 : };
|