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
|
//------------------------------------------------------------------------------
// gbextractvalues: extract all entries from a GraphBLAS matrix
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// Usage:
// X = gbextractvalues (A)
#include "gb_interface.h"
#define USAGE "usage: X = GrB.extractvalues (A)"
void mexFunction
(
int nargout,
mxArray *pargout [ ],
int nargin,
const mxArray *pargin [ ]
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
gb_usage (nargin == 1 && nargout <= 1, USAGE) ;
//--------------------------------------------------------------------------
// get the matrix
//--------------------------------------------------------------------------
GrB_Matrix A = gb_get_shallow (pargin [0]) ;
GrB_Index nvals ;
OK (GrB_Matrix_nvals (&nvals, A)) ;
GrB_Type xtype ;
OK (GxB_Matrix_type (&xtype, A)) ;
GrB_Index s = MAX (nvals, 1) ;
//--------------------------------------------------------------------------
// extract the tuples
//--------------------------------------------------------------------------
if (xtype == GrB_BOOL)
{
bool *X = mxMalloc (s * sizeof (bool)) ;
OK (GrB_Matrix_extractTuples_BOOL (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_BOOL) ;
}
else if (xtype == GrB_INT8)
{
int8_t *X = mxMalloc (s * sizeof (int8_t)) ;
OK (GrB_Matrix_extractTuples_INT8 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_INT8) ;
}
else if (xtype == GrB_INT16)
{
int16_t *X = mxMalloc (s * sizeof (int16_t)) ;
OK (GrB_Matrix_extractTuples_INT16 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_INT16) ;
}
else if (xtype == GrB_INT32)
{
int32_t *X = mxMalloc (s * sizeof (int32_t)) ;
OK (GrB_Matrix_extractTuples_INT32 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_INT32) ;
}
else if (xtype == GrB_INT64)
{
int64_t *X = mxMalloc (s * sizeof (int64_t)) ;
OK (GrB_Matrix_extractTuples_INT64 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_INT64) ;
}
else if (xtype == GrB_UINT8)
{
uint8_t *X = mxMalloc (s * sizeof (uint8_t)) ;
OK (GrB_Matrix_extractTuples_UINT8 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_UINT8) ;
}
else if (xtype == GrB_UINT16)
{
uint16_t *X = mxMalloc (s * sizeof (uint16_t)) ;
OK (GrB_Matrix_extractTuples_UINT16 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_UINT16) ;
}
else if (xtype == GrB_UINT32)
{
uint32_t *X = mxMalloc (s * sizeof (uint32_t)) ;
OK (GrB_Matrix_extractTuples_UINT32 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_UINT32) ;
}
else if (xtype == GrB_UINT64)
{
uint64_t *X = mxMalloc (s * sizeof (uint64_t)) ;
OK (GrB_Matrix_extractTuples_UINT64 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_UINT64) ;
}
else if (xtype == GrB_FP32)
{
float *X = mxMalloc (s * sizeof (float)) ;
OK (GrB_Matrix_extractTuples_FP32 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_FP32) ;
}
else if (xtype == GrB_FP64)
{
double *X = mxMalloc (s * sizeof (double)) ;
OK (GrB_Matrix_extractTuples_FP64 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GrB_FP64) ;
}
else if (xtype == GxB_FC32)
{
GxB_FC32_t *X = mxMalloc (s * sizeof (GxB_FC32_t)) ;
OK (GxB_Matrix_extractTuples_FC32 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GxB_FC32) ;
}
else if (xtype == GxB_FC64)
{
GxB_FC64_t *X = mxMalloc (s * sizeof (GxB_FC64_t)) ;
OK (GxB_Matrix_extractTuples_FC64 (NULL, NULL, X, &nvals, A)) ;
pargout [0] = gb_export_to_mxfull ((void **) &X, nvals, 1, GxB_FC64) ;
}
else
{
ERROR ("unsupported type") ;
}
//--------------------------------------------------------------------------
// free workspace
//--------------------------------------------------------------------------
OK (GrB_Matrix_free (&A)) ;
GB_WRAPUP ;
}
|