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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
//------------------------------------------------------------------------------
// GB_Iterator_rc_seek: seek a row/col iterator to A(:,j) or to jth vector of A
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// Seek a row iterator to A(j,:), a col iterator to A(:,j). If jth_vector is
// true, seek to the jth vector instead. For sparse, bitmap, or full matrices,
// this is the same as A(j,:) for a row iterator or A(:,j) for a col iterator.
// The jth_vector parameter only affects how hypersparse matrices are
// traversed.
#include "GB.h"
GrB_Info GB_Iterator_rc_seek
(
GxB_Iterator iterator,
uint64_t j_input,
bool jth_vector
)
{
//--------------------------------------------------------------------------
// check if the iterator is exhausted
//--------------------------------------------------------------------------
int64_t j = (int64_t) j_input ;
if (j >= ((jth_vector) ? iterator->anvec : iterator->avdim))
{
iterator->pstart = 0 ;
iterator->pend = 0 ;
iterator->p = 0 ;
iterator->k = iterator->anvec ;
return (GxB_EXHAUSTED) ;
}
//--------------------------------------------------------------------------
// attach the iterator to A(:,j)
//--------------------------------------------------------------------------
switch (iterator->A_sparsity)
{
default:
case GxB_SPARSE :
{
// attach to A(:,j), which is also the jth vector of A
iterator->pstart = GB_IGET (iterator->Ap, j) ;
iterator->pend = GB_IGET (iterator->Ap, j+1) ;
iterator->p = iterator->pstart ;
iterator->k = j ;
}
break ;
case GxB_HYPERSPARSE :
{
int64_t k ;
if (jth_vector)
{
// attach to the jth vector of A; this is much faster than
// searching Ah for the value j, to attach to A(:,j)
k = j ;
iterator->pstart = GB_IGET (iterator->Ap, k) ;
iterator->pend = GB_IGET (iterator->Ap, k+1) ;
iterator->p = iterator->pstart ;
iterator->k = k ;
}
else
{
// find k so that j = Ah [k], or if not found, return k as the
// smallest value so that j < Ah [k].
k = 0 ;
if (j > 0)
{
int64_t pright = iterator->anvec-1 ;
if (iterator->Ah32 != NULL)
{
GB_split_binary_search_32 (j, iterator->Ah32,
&k, &pright) ;
}
else
{
GB_split_binary_search_64 (j, iterator->Ah64,
&k, &pright) ;
}
}
}
// If j is found, A(:,j) is the kth vector in the Ah hyperlist.
// If j is not found, the iterator is placed at the first vector
// after j in the hyperlist, if this vector exists.
if (k >= iterator->anvec)
{
// the kth vector does not exist
iterator->pstart = 0 ;
iterator->pend = 0 ;
iterator->p = 0 ;
iterator->k = iterator->anvec ;
return (GxB_EXHAUSTED) ;
}
else
{
// the kth vector exists
iterator->pstart = GB_IGET (iterator->Ap, k) ;
iterator->pend = GB_IGET (iterator->Ap, k+1) ;
iterator->p = iterator->pstart ;
iterator->k = k ;
}
}
break ;
case GxB_BITMAP :
{
// attach to A(:,j), which is also the jth vector of A
iterator->pstart = j * iterator->avlen ;
iterator->pend = (j+1) * iterator->avlen ;
iterator->p = iterator->pstart ;
iterator->k = j ;
return (GB_Iterator_rc_bitmap_next (iterator)) ;
}
break ;
case GxB_FULL :
{
// attach to A(:,j), which is also the jth vector of A
iterator->pstart = j * iterator->avlen ;
iterator->pend = (j+1) * iterator->avlen ;
iterator->p = iterator->pstart ;
iterator->k = j ;
}
break ;
}
return ((iterator->p >= iterator->pend) ? GrB_NO_VALUE : GrB_SUCCESS) ;
}
|