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
|
//------------------------------------------------------------------------------
// gbbuiltin: convert to a sparse or full built-in matrix
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// The input may be either a GraphBLAS matrix struct or a standard built-in
// sparse or full matrix. The output is a standard built-in sparse or full
// matrix: full if all entries are present, and sparse otherwise.
// Usage:
// A = gbbuiltin (X, type)
#include "gb_interface.h"
#define USAGE "usage: A = gbbuiltin (X, type)"
void mexFunction
(
int nargout,
mxArray *pargout [ ],
int nargin,
const mxArray *pargin [ ]
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
gb_usage (nargin == 2 && nargout <= 1, USAGE) ;
//--------------------------------------------------------------------------
// get the input matrix
//--------------------------------------------------------------------------
GrB_Matrix X = gb_get_shallow (pargin [0]) ;
GrB_Type xtype ;
OK (GxB_Matrix_type (&xtype, X)) ;
//--------------------------------------------------------------------------
// get the desired type, and typecast if needed
//--------------------------------------------------------------------------
GrB_Type type = gb_mxstring_to_type (pargin [1]) ;
GrB_Matrix T = NULL ;
if (type != xtype)
{
T = gb_typecast (X, type, GxB_BY_COL, GxB_SPARSE + GxB_FULL) ;
OK (GrB_Matrix_free (&X)) ;
X = T ;
}
//--------------------------------------------------------------------------
// export the input matrix to a built-in sparse or full matrix
//--------------------------------------------------------------------------
pargout [0] = gb_export (&X, KIND_BUILTIN) ;
GB_WRAPUP ;
}
|