1 //------------------------------------------------------------------------------
2 // GrB_Col_extract: w<M> = accum (w, A(I,j)) or A(j,I)'
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 // Extract a single row or column from a matrix. Note that in the
11 // GraphBLAS spec, row and column vectors are indistinguishable. In this
12 // implementation, both are the same as an n-by-1 GrB_Matrix, except with
13 // restrictions on the matrix operations that can be performed on them.
14
15 #include "GB_extract.h"
16
GrB_Col_extract(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_Matrix A,const GrB_Index * I,GrB_Index ni,GrB_Index j,const GrB_Descriptor desc)17 GrB_Info GrB_Col_extract // w<M> = accum (w, A(I,j)) or (A(j,I))'
18 (
19 GrB_Vector w, // input/output vector for results
20 const GrB_Vector M, // optional mask for w, unused if NULL
21 const GrB_BinaryOp accum, // optional accum for z=accum(w,t)
22 const GrB_Matrix A, // first input: matrix A
23 const GrB_Index *I, // row indices
24 GrB_Index ni, // number of row indices
25 GrB_Index j, // column index
26 const GrB_Descriptor desc // descriptor for w, M, and A
27 )
28 {
29
30 //--------------------------------------------------------------------------
31 // check inputs
32 //--------------------------------------------------------------------------
33
34 GB_WHERE (w, "GrB_Col_extract (w, M, accum, A, I, ni, j, desc)") ;
35 GB_BURBLE_START ("GrB_extract") ;
36 GB_RETURN_IF_NULL_OR_FAULTY (w) ;
37 GB_RETURN_IF_FAULTY (M) ;
38 GB_RETURN_IF_NULL_OR_FAULTY (A) ;
39 ASSERT (GB_VECTOR_OK (w)) ;
40 ASSERT (GB_IMPLIES (M != NULL, GB_VECTOR_OK (M))) ;
41
42 // get the descriptor
43 GB_GET_DESCRIPTOR (info, desc, C_replace, Mask_comp, Mask_struct,
44 A_transpose, xx1, xx2, xx7) ;
45
46 GrB_Index ancols = (A_transpose ? GB_NROWS (A) : GB_NCOLS (A)) ;
47 if (j >= ancols)
48 {
49 GB_ERROR (GrB_INVALID_INDEX,
50 "Column index j=" GBu " out of bounds; must be < " GBu ,
51 j, ancols) ;
52 }
53
54 //--------------------------------------------------------------------------
55 // extract the jth column (or jth row if A is transposed) using GB_extract
56 //--------------------------------------------------------------------------
57
58 // construct the column index list J = [ j ] of length nj = 1
59 GrB_Index J [1] ;
60 J [0] = j ;
61
62 //--------------------------------------------------------------------------
63 // do the work in GB_extract
64 //--------------------------------------------------------------------------
65
66 info = GB_extract (
67 (GrB_Matrix) w, C_replace, // w as a matrix, and descriptor
68 (GrB_Matrix) M, Mask_comp, Mask_struct, // mask and its descriptor
69 accum, // optional accum for z=accum(w,t)
70 A, A_transpose, // A and its descriptor
71 I, ni, // row indices I and length ni
72 J, 1, // one column index, nj = 1
73 Context) ;
74
75 GB_BURBLE_END ;
76 return (info) ;
77 }
78
79