1 //------------------------------------------------------------------------------
2 // GxB_Scalar_new: create a new GxB_Scalar
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 new GxB_Scalar has no entry.  Internally, it is identical to a
11 // GrB_Vector of length 1.  If this method fails, *s is set to NULL.
12 
13 #include "GB.h"
14 
GxB_Scalar_new(GxB_Scalar * s,GrB_Type type)15 GrB_Info GxB_Scalar_new     // create a new GxB_Scalar with no entries
16 (
17     GxB_Scalar *s,          // handle of GxB_Scalar to create
18     GrB_Type type           // type of GxB_Scalar to create
19 )
20 {
21 
22     //--------------------------------------------------------------------------
23     // check inputs
24     //--------------------------------------------------------------------------
25 
26     GB_WHERE1 ("GxB_Scalar_new (&s, type)") ;
27     GB_RETURN_IF_NULL (s) ;
28     (*s) = NULL ;
29     GB_RETURN_IF_NULL_OR_FAULTY (type) ;
30 
31     //--------------------------------------------------------------------------
32     // create the GxB_Scalar
33     //--------------------------------------------------------------------------
34 
35     GrB_Info info ;
36 
37     info = GB_new ((GrB_Matrix *) s, false, // new user header
38         type, 1, 1, GB_Ap_calloc, true,
39         GxB_SPARSE, GB_Global_hyper_switch_get ( ), 1, Context) ;
40     ASSERT (GB_IMPLIES (info == GrB_SUCCESS, GB_SCALAR_OK (*s))) ;
41     return (info) ;
42 }
43 
44