1 //------------------------------------------------------------------------------
2 // GrB_Vector_extract: w<M> = accum (w, u(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 #include "GB_extract.h"
11 
GrB_Vector_extract(GrB_Vector w,const GrB_Vector M,const GrB_BinaryOp accum,const GrB_Vector u,const GrB_Index * I,GrB_Index ni,const GrB_Descriptor desc)12 GrB_Info GrB_Vector_extract         // w<M> = accum (w, u(I))
13 (
14     GrB_Vector w,                   // input/output vector for results
15     const GrB_Vector M,             // optional mask for w, unused if NULL
16     const GrB_BinaryOp accum,       // optional accum for z=accum(w,t)
17     const GrB_Vector u,             // first input:  vector u
18     const GrB_Index *I,             // row indices
19     GrB_Index ni,                   // number of row indices
20     const GrB_Descriptor desc       // descriptor for w and M
21 )
22 {
23 
24     //--------------------------------------------------------------------------
25     // check inputs
26     //--------------------------------------------------------------------------
27 
28     GB_WHERE (w, "GrB_Vector_extract (w, M, accum, u, I, ni, desc)") ;
29     GB_BURBLE_START ("GrB_extract") ;
30     GB_RETURN_IF_NULL_OR_FAULTY (w) ;
31     GB_RETURN_IF_FAULTY (M) ;
32     GB_RETURN_IF_NULL_OR_FAULTY (u) ;
33     ASSERT (GB_VECTOR_OK (w)) ;
34     ASSERT (M == NULL || GB_VECTOR_OK (M)) ;
35     ASSERT (GB_VECTOR_OK (u)) ;
36 
37     // get the descriptor
38     GB_GET_DESCRIPTOR (info, desc, C_replace, Mask_comp, Mask_struct,
39         xx1, xx2, xx3, xx7) ;
40 
41     //--------------------------------------------------------------------------
42     // extract entries
43     //--------------------------------------------------------------------------
44 
45     // If a column list J is constructed containing the single column index 0,
46     // then T = A(I,0) followed by C<M>=accum(C,T) does the right thing
47     // where all matrices (C, M, and T) are columns of size ni-by-1.  Thus,
48     // GB_extract does the right thing for this case.  Note that the input u is
49     // not transposed.  All GrB_Matrix objects will be in CSC format, and no
50     // matrices are transposed via the C_is_vector option in GB_extract.
51 
52     //--------------------------------------------------------------------------
53     // do the work in GB_extract
54     //--------------------------------------------------------------------------
55 
56     info = GB_extract (
57         (GrB_Matrix) w,     C_replace,  // w as a matrix, and its descriptor
58         (GrB_Matrix) M, Mask_comp, Mask_struct,  // mask and its descriptor
59         accum,                          // optional accum for z=accum(w,t)
60         (GrB_Matrix) u,     false,      // u as matrix; never transposed
61         I, ni,                          // row indices I and length ni
62         GrB_ALL, 1,                     // all columns
63         Context) ;
64 
65     GB_BURBLE_END ;
66     return (info) ;
67 }
68 
69