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
|
//------------------------------------------------------------------------------
// GB_hyper_shallow: create a sparse shallow version of a hypersparse matrix
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// On input C must exist but the content of the C header is uninitialized
// except for C->static_header and C->header_size. No memory is allocated to
// construct C as the hyper_shallow version of A. C is purely shallow. If A
// is iso then so is C.
#include "GB.h"
#include "GB_convert.h"
GrB_Matrix GB_hyper_shallow // return C
(
GrB_Matrix C, // output sparse matrix
const GrB_Matrix A // input hypersparse matrix, not modified.
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
ASSERT_MATRIX_OK (A, "hyper_shallow input", GB0) ;
ASSERT (C != NULL && (C->static_header || GBNSTATIC)) ;
ASSERT (GB_IS_HYPERSPARSE (A)) ;
//--------------------------------------------------------------------------
// construct the hyper_shallow version
//--------------------------------------------------------------------------
// save the C header status
bool C_static_header = C->static_header ;
bool C_header_size = C->header_size ;
// copy the header
memcpy (C, A, sizeof (struct GB_Matrix_opaque)) ;
// restore the C header status
C->static_header = C_static_header ;
C->header_size = C_header_size ;
// remove the hyperlist and the hyper_hash
C->h = NULL ;
C->h_shallow = false ;
C->Y = NULL ;
C->Y_shallow = false ;
// flag all content of C as shallow
C->p_shallow = true ;
C->i_shallow = true ;
C->x_shallow = true ;
// C reduces in dimension to the # of vectors in A
C->vdim = C->nvec ;
C->plen = C->nvec ;
C->nvec_nonempty = C->nvec ;
//--------------------------------------------------------------------------
// return result
//--------------------------------------------------------------------------
ASSERT_MATRIX_OK (C, "hyper_shallow output", GB0) ;
ASSERT (GB_IS_SPARSE (C)) ;
return (C) ;
}
|