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
|
//------------------------------------------------------------------------------
// GB_cast: definitions for GB_cast_* methods
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#ifndef GB_CAST_H
#define GB_CAST_H
//------------------------------------------------------------------------------
// GB_cast_scalar: typecast or copy a scalar
//------------------------------------------------------------------------------
static inline void GB_cast_scalar // z = x with typecasting from xcode to zcode
(
void *z, // output scalar z of type zcode
GB_Type_code zcode, // type of z
const void *x, // input scalar x of type xcode
GB_Type_code xcode, // type of x
size_t size // size of x and z if they have the same type
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
ASSERT (z != NULL) ;
ASSERT (x != NULL) ;
//--------------------------------------------------------------------------
// copy or typecast the scalar
//--------------------------------------------------------------------------
if (zcode == xcode)
{
// no typecasting; copy x into z, works for any types
memcpy (z, x, size) ;
}
else
{
// typecast x into z, works for built-in types only
GB_cast_function cast_X_to_Z = GB_cast_factory (zcode, xcode) ;
cast_X_to_Z (z, x, size) ;
}
}
//------------------------------------------------------------------------------
// GB_cast_one: return 1, typecasted to any type
//------------------------------------------------------------------------------
static inline void GB_cast_one // z = 1 with typecasting zcode
(
void *z, // output scalar z of type zcode
GB_Type_code zcode // type of z
)
{
GB_cast_function cast_one = GB_cast_factory (zcode, GB_UINT8_code) ;
uint8_t one = 1 ;
cast_one (z, (GB_void *) &one, sizeof (uint8_t)) ;
}
//------------------------------------------------------------------------------
GB_PUBLIC
void GB_cast_array // typecast an array
(
GB_void *Cx, // output array
const GB_Type_code code1, // type code for Cx
GB_void *Ax, // input array
const GB_Type_code code2, // type code for Ax
const int8_t *restrict Ab, // bitmap for Ax
const int64_t anz, // number of entries in Cx and Ax
const int nthreads // number of threads to use
) ;
void GB_cast_matrix // copy or typecast the values from A into C
(
GrB_Matrix C,
GrB_Matrix A,
GB_Context Context
) ;
#endif
|