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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
//------------------------------------------------------------------------------
// GB_mex_about6: still more basic tests
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// Test lots of random stuff. The function otherwise serves no purpose.
#include "GB_mex.h"
#include "GB_mex_errors.h"
#include "GB_serialize.h"
#define USAGE "GB_mex_about6"
#define FREE_ALL ;
#define GET_DEEP_COPY ;
#define FREE_DEEP_COPY ;
typedef int32_t myint ;
void mexFunction
(
int nargout,
mxArray *pargout [ ],
int nargin,
const mxArray *pargin [ ]
)
{
GrB_Info info ;
GrB_Matrix C = NULL, A = NULL, B = NULL, P = NULL ;
GrB_Scalar alpha = NULL, beta = NULL, S = NULL ;
GrB_Vector u = NULL ;
GrB_Type MyType = NULL ;
const char *err ;
//--------------------------------------------------------------------------
// startup GraphBLAS
//--------------------------------------------------------------------------
bool malloc_debug = GB_mx_get_global (true) ;
int expected = GrB_SUCCESS ;
//--------------------------------------------------------------------------
// eWiseUnion
//--------------------------------------------------------------------------
OK (GrB_Type_new (&MyType, sizeof (myint))) ;
OK (GrB_Matrix_new (&A, GrB_FP64, 10, 10)) ;
OK (GrB_Matrix_new (&B, GrB_FP64, 10, 10)) ;
OK (GrB_Matrix_new (&C, GrB_FP64, 10, 10)) ;
expected = GrB_NULL_POINTER ;
ERR (GxB_Matrix_eWiseUnion (C, NULL, NULL, GrB_PLUS_FP64, A, alpha,
B, beta, NULL)) ;
OK (GrB_Scalar_new (&alpha, GrB_FP64)) ;
OK (GrB_Scalar_new (&beta, GrB_FP64)) ;
expected = GrB_EMPTY_OBJECT ;
ERR (GxB_Matrix_eWiseUnion (C, NULL, NULL, GrB_PLUS_FP64, A, alpha,
B, beta, NULL)) ;
OK (GrB_Matrix_error_(&err, C)) ;
printf ("expected error:\n%s\n", err) ;
OK (GrB_Scalar_setElement_FP64_ (alpha, (double) 42)) ;
ERR (GxB_Matrix_eWiseUnion (C, NULL, NULL, GrB_PLUS_FP64, A, alpha,
B, beta, NULL)) ;
OK (GrB_Matrix_error_(&err, C)) ;
printf ("expected error:\n%s\n", err) ;
GrB_Scalar_free_(&alpha) ;
OK (GrB_Scalar_new (&alpha, MyType)) ;
myint nothing [1] ;
memset (nothing, 0, sizeof (myint)) ;
OK (GrB_Scalar_setElement_UDT (alpha, (void *) nothing)) ;
OK (GxB_Scalar_fprint (alpha, "alpha", 3, NULL)) ;
OK (GxB_Scalar_fprint (beta, "beta", 3, NULL)) ;
OK (GrB_Scalar_setElement_FP64 (beta, (double) 99)) ;
expected = GrB_DOMAIN_MISMATCH ;
ERR (GxB_Matrix_eWiseUnion (C, NULL, NULL, GrB_PLUS_FP64, A, alpha,
B, beta, NULL)) ;
OK (GrB_Matrix_error_(&err, C)) ;
printf ("expected error:\n%s\n", err) ;
ERR (GxB_Matrix_eWiseUnion (C, NULL, NULL, GrB_PLUS_FP64, A, beta,
B, alpha, NULL)) ;
OK (GrB_Matrix_error_(&err, C)) ;
printf ("expected error:\n%s\n", err) ;
GrB_Matrix_free_(&A) ;
GrB_Matrix_free_(&B) ;
GrB_Matrix_free_(&C) ;
GrB_Scalar_free_(&alpha) ;
GrB_Scalar_free_(&beta) ;
GrB_Type_free_(&MyType) ;
//--------------------------------------------------------------------------
// sort
//--------------------------------------------------------------------------
expected = GrB_NULL_POINTER ;
OK (GrB_Matrix_new (&A, GrB_FP64, 10, 10)) ;
OK (GrB_Matrix_setElement_FP64 (A, (double) 1.2, 0, 0)) ;
ERR (GxB_Matrix_sort (NULL, NULL, GrB_LT_FP64, A, NULL)) ;
OK (GrB_Matrix_new (&C, GrB_FP64, 10, 10)) ;
OK (GrB_Matrix_new (&P, GrB_INT64, 10, 10)) ;
expected = GrB_DOMAIN_MISMATCH ;
ERR (GxB_Matrix_sort (C, P, GrB_PLUS_FP64, A, NULL)) ;
GrB_Matrix_free_(&C) ;
OK (GrB_Matrix_new (&C, GrB_FP64, 9, 10)) ;
expected = GrB_DIMENSION_MISMATCH ;
ERR (GxB_Matrix_sort (C, P, GrB_LT_FP64, A, NULL)) ;
GrB_Matrix_free_(&P) ;
GrB_Matrix_free_(&C) ;
//--------------------------------------------------------------------------
// reduce to GrB_Scalar
//--------------------------------------------------------------------------
GrB_Scalar_new (&S, GrB_FP64) ;
OK (GrB_Vector_new (&u, GrB_FP64, 10)) ;
expected = GrB_DOMAIN_MISMATCH ;
ERR (GrB_Matrix_reduce_BinaryOp_Scalar_(S, NULL, GrB_LT_FP64, A, NULL)) ;
OK (GrB_Scalar_error_(&err, S)) ;
printf ("expected error:\n%s\n", err) ;
ERR (GrB_Vector_reduce_BinaryOp_Scalar_(S, NULL, GrB_LT_FP64, u, NULL)) ;
OK (GrB_Scalar_error_(&err, S)) ;
printf ("expected error:\n%s\n", err) ;
expected = GrB_NOT_IMPLEMENTED ;
ERR (GrB_Matrix_reduce_BinaryOp_Scalar_(S, NULL, GrB_DIV_FP64, A, NULL)) ;
OK (GrB_Scalar_error_(&err, S)) ;
printf ("expected error:\n%s\n", err) ;
ERR (GrB_Vector_reduce_BinaryOp_Scalar_(S, NULL, GrB_DIV_FP64, u, NULL)) ;
OK (GrB_Scalar_error_(&err, S)) ;
printf ("expected error:\n%s\n", err) ;
GrB_Scalar_free_(&S) ;
GrB_Vector_free_(&u) ;
GrB_Matrix_free_(&A) ;
//--------------------------------------------------------------------------
// wrapup
//--------------------------------------------------------------------------
GB_mx_put_global (true) ;
printf ("\nGB_mex_about6: all tests passed\n\n") ;
}
|