File: GB_Iterator_attach.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (83 lines) | stat: -rw-r--r-- 2,699 bytes parent folder | download | duplicates (3)
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
73
74
75
76
77
78
79
80
81
82
83
//------------------------------------------------------------------------------
// GB_Iterator_attach: attach an iterator to matrix
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

#include "GB.h"
#define GB_FREE_ALL ;

GrB_Info GB_Iterator_attach
(
    // input/output:
    GxB_Iterator iterator,      // iterator to attach to the matrix A
    // input
    GrB_Matrix A,               // matrix to attach
    GxB_Format_Value format,    // by row, by col, or by entry (GxB_NO_FORMAT)
    GrB_Descriptor desc
)
{

    //--------------------------------------------------------------------------
    // check inputs
    //--------------------------------------------------------------------------

    GB_RETURN_IF_NULL (iterator) ;
    GB_RETURN_IF_NULL_OR_FAULTY (A) ;

    if ((format == GxB_BY_ROW &&  A->is_csc) ||
        (format == GxB_BY_COL && !A->is_csc))
    { 
        return (GrB_NOT_IMPLEMENTED) ;
    }

    //--------------------------------------------------------------------------
    // finish any pending work on the matrix
    //--------------------------------------------------------------------------

    if (GB_ANY_PENDING_WORK (A))
    {
        GrB_Info info ;
        GB_CONTEXT ("GxB_Iterator_attach") ;
        if (desc != NULL)
        { 
            // get the # of threads to use
            Context->nthreads_max = desc->nthreads_max ;
            Context->chunk = desc->chunk ;
        }
        GB_OK (GB_wait (A, "A", Context)) ;
    }

    //--------------------------------------------------------------------------
    // clear the current position
    //--------------------------------------------------------------------------

    iterator->pstart = 0 ;
    iterator->pend = 0 ;
    iterator->p = 0 ;
    iterator->k = 0 ;

    //--------------------------------------------------------------------------
    // get the matrix and save its contents in the iterator
    //--------------------------------------------------------------------------

    iterator->pmax = (GB_nnz (A) == 0) ? 0 : GB_nnz_held (A) ;
    iterator->avlen = A->vlen ;
    iterator->avdim = A->vdim ;
    iterator->anvec = A->nvec ;
    iterator->Ap = A->p ;
    iterator->Ah = A->h ;
    iterator->Ab = A->b ;
    iterator->Ai = A->i ;
    iterator->Ax = A->x ;
    iterator->type_size = A->type->size ;
    iterator->A_sparsity = GB_sparsity (A) ;
    iterator->iso = A->iso ;
    iterator->by_col = A->is_csc ;

    return (GrB_SUCCESS) ;
}