1 //------------------------------------------------------------------------------ 2 // GB_code_type: convert a type code to a GrB_Type 3 //------------------------------------------------------------------------------ 4 5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. 6 // SPDX-License-Identifier: Apache-2.0 7 8 //------------------------------------------------------------------------------ 9 10 // The GrB_assign, GxB_subassign, and GrB_setElement operations all accept 11 // scalar inputs. The scalar code is converted to an appropriate GrB_Type 12 // here. For user-defined types, the scalar is required to have the same type 13 // as the matrix being operated on. This cannot be checked; results are 14 // undefined if the user passes in a void * pointer to a different user-defined 15 // type. 16 17 #include "GB.h" 18 19 GB_PUBLIC // accessed by the MATLAB tests in GraphBLAS/Test only GB_code_type(const GB_Type_code code,const GrB_Type type)20GrB_Type GB_code_type // return the GrB_Type corresponding to the code 21 ( 22 const GB_Type_code code, // type code to convert 23 const GrB_Type type // user type if code is user-defined 24 ) 25 { 26 27 ASSERT (code <= GB_UDT_code) ; 28 switch (code) 29 { 30 case GB_BOOL_code : return (GrB_BOOL) ; 31 case GB_INT8_code : return (GrB_INT8) ; 32 case GB_UINT8_code : return (GrB_UINT8) ; 33 case GB_INT16_code : return (GrB_INT16) ; 34 case GB_UINT16_code : return (GrB_UINT16) ; 35 case GB_INT32_code : return (GrB_INT32) ; 36 case GB_UINT32_code : return (GrB_UINT32) ; 37 case GB_INT64_code : return (GrB_INT64) ; 38 case GB_UINT64_code : return (GrB_UINT64) ; 39 case GB_FP32_code : return (GrB_FP32) ; 40 case GB_FP64_code : return (GrB_FP64) ; 41 case GB_FC32_code : return (GxB_FC32) ; 42 case GB_FC64_code : return (GxB_FC64) ; 43 case GB_UDT_code : 44 default : return (type) ; 45 } 46 } 47 48