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
|
//------------------------------------------------------------------------------
// GxB_Matrix_diag: build a diagonal matrix from a vector
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
#include "GB_diag.h"
GrB_Info GxB_Matrix_diag // build a diagonal matrix from a vector
(
GrB_Matrix C, // output matrix
const GrB_Vector v, // input vector
int64_t k,
const GrB_Descriptor desc // unused, except threading control
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GB_WHERE (C, "GxB_Matrix_diag (C, v, k, desc)") ;
GB_BURBLE_START ("GxB_Matrix_diag") ;
GB_RETURN_IF_NULL_OR_FAULTY (C) ;
GB_RETURN_IF_NULL_OR_FAULTY (v) ;
GrB_Type ctype = C->type ;
GrB_Type vtype = v->type ;
int64_t nrows = GB_NROWS (C) ;
int64_t ncols = GB_NCOLS (C) ;
int64_t n = v->vlen + GB_IABS (k) ; // C must be n-by-n
if (nrows != ncols || nrows != n)
{
GB_ERROR (GrB_DIMENSION_MISMATCH,
"Input matrix is " GBd "-by-" GBd " but must be "
GBd "-by-" GBd "\n", nrows, ncols, n, n) ;
}
if (!GB_Type_compatible (ctype, vtype))
{
GB_ERROR (GrB_DOMAIN_MISMATCH, "Input vector of type [%s] "
"cannot be typecast to output of type [%s]\n",
vtype->name, ctype->name) ;
}
// get the descriptor
GB_GET_DESCRIPTOR (info, desc, xx1, xx2, xx3, xx4, xx5, xx6, xx7) ;
//--------------------------------------------------------------------------
// C = diag (v,k)
//--------------------------------------------------------------------------
info = GB_Matrix_diag (C, (GrB_Matrix) v, k, Context) ;
GB_BURBLE_END ;
return (info) ;
}
|