File: test_Random.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (86 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download
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
//------------------------------------------------------------------------------
// LAGraph/src/test/test_Random.c: test cases for random vector generator
//------------------------------------------------------------------------------

// LAGraph, (c) 2019-2022 by The LAGraph Contributors, All Rights Reserved.
// SPDX-License-Identifier: BSD-2-Clause
//
// For additional details (including references to third party source code and
// other files) see the LICENSE file or contact permission@sei.cmu.edu. See
// Contributors.txt for a full list of contributors. Created, in part, with
// funding and support from the U.S. Government (see Acknowledgments.txt file).
// DM22-0790

// Contributed by Timothy A. Davis, Texas A&M University

//------------------------------------------------------------------------------

#include <stdio.h>
#include <acutest.h>

#include <LAGraphX.h>
#include <LAGraph_test.h>

char msg [LAGRAPH_MSG_LEN] ;
GrB_Vector Seed = NULL ;

//------------------------------------------------------------------------------
// test_Random
//------------------------------------------------------------------------------

void test_Random (void)
{
    LAGraph_Init (msg) ;
    OK (LAGraph_Random_Init (msg)) ;

    uint64_t seed = 42 ;
    LAGraph_PrintLevel pr = LAGraph_COMPLETE_VERBOSE ;

    for (int trial = 0 ; trial <= 4 ; trial++)
    {
        seed++ ;
        printf ("\n=============================== seed: %g\n", (double) seed) ;

        // generate a seed vector (all entries present)
        printf ("\nDense random vector:\n") ;
        GrB_Index n = 8 ;
        OK (GrB_Vector_new (&Seed, GrB_UINT64, n)) ;
        OK (GrB_Vector_assign_UINT64 (Seed, NULL, NULL, 0, GrB_ALL, n, NULL)) ;
        OK (LAGraph_Random_Seed (Seed, seed, msg)) ;
        OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
        printf ("\nnext dense random vector:\n") ;
        OK (LAGraph_Random_Next (Seed, msg)) ;
        OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;

        // free all workspace
        OK (GrB_Vector_free (&Seed)) ;

        // generate a sparse seed vector
        printf ("\nSparse random vector (same seed):\n") ;
        OK (GrB_Vector_new (&Seed, GrB_UINT64, n)) ;
        for (int i = 0 ; i < n ; i += 2)
        {
            OK (GrB_Vector_setElement_UINT64 (Seed, 0, i)) ;
        }
        OK (LAGraph_Random_Seed (Seed, seed, msg)) ;
        OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;
        printf ("\nnext sparse random vector:\n") ;
        OK (LAGraph_Random_Next (Seed, msg)) ;
        OK (LAGraph_Vector_Print (Seed, pr, stdout, NULL)) ;

        // free all workspace
        OK (GrB_Vector_free (&Seed)) ;
    }

    OK (LAGraph_Random_Finalize (msg)) ;
    LAGraph_Finalize (msg) ;
}

//------------------------------------------------------------------------------
// Test list
//------------------------------------------------------------------------------

TEST_LIST = {
    {"Random", test_Random},
    {NULL, NULL}
};