1 //------------------------------------------------------------------------------
2 // GB_lookup_template: find k so that j == Ah [k]
3 //------------------------------------------------------------------------------
4
5 // For a sparse, bitmap, or full matrix j == k.
6 // For a hypersparse matrix, find k so that j == Ah [k], if it
7 // appears in the list.
8
9 // k is not needed by the caller, just the variables
10 // pstart, pend, pleft, and found.
11
12 // Once k is found, find pstart and pend, the start and end of the vector.
13 // pstart and pend are defined for all sparsity structures: hypersparse,
14 // sparse, bitmap, or full.
15
16 // This fine is #included' by GB.h, so the #include'ing file does either:
17 // #include "GB.h"
18 // or
19 // #define GB_KERNEL
20 // #include "GB.h"
21
22 #ifdef GB_KERNEL
23 __device__
GB_lookup_device(const bool A_is_hyper,const int64_t * restrict Ah,const int64_t * restrict Ap,const int64_t avlen,int64_t * restrict pleft,int64_t pright,const int64_t j,int64_t * restrict pstart,int64_t * restrict pend)24 static inline bool GB_lookup_device
25 #else
26 static inline bool GB_lookup // find j = Ah [k] in a hyperlist
27 #endif
28 (
29 const bool A_is_hyper, // true if A is hypersparse
30 const int64_t *restrict Ah, // A->h [0..A->nvec-1]: list of vectors
31 const int64_t *restrict Ap, // A->p [0..A->nvec ]: pointers to vectors
32 const int64_t avlen, // A->vlen
33 int64_t *restrict pleft, // look only in A->h [pleft..pright]
34 int64_t pright, // normally A->nvec-1, but can be trimmed
35 // const int64_t nvec, // A->nvec: number of vectors
36 const int64_t j, // vector to find, as j = Ah [k]
37 int64_t *restrict pstart, // start of vector: Ap [k]
38 int64_t *restrict pend // end of vector: Ap [k+1]
39 )
40 {
41 if (A_is_hyper)
42 {
43 // to search the whole Ah list, use on input:
44 // pleft = 0 ; pright = nvec-1 ;
45 bool found ;
46 GB_BINARY_SEARCH (j, Ah, (*pleft), pright, found) ;
47 if (found)
48 {
49 // j appears in the hyperlist at Ah [pleft]
50 // k = (*pleft)
51 (*pstart) = Ap [(*pleft)] ;
52 (*pend) = Ap [(*pleft)+1] ;
53 }
54 else
55 {
56 // j does not appear in the hyperlist Ah
57 // k = -1
58 (*pstart) = -1 ;
59 (*pend) = -1 ;
60 }
61 return (found) ;
62 }
63 else
64 {
65 // A is sparse, bitmap, or full; j always appears
66 // k = j
67 (*pstart) = GBP (Ap, j, avlen) ;
68 (*pend) = GBP (Ap, j+1, avlen) ;
69 return (true) ;
70 }
71 }
72
73