28#ifndef _H_GRB_KCORE_DECOMPOSITION
29#define _H_GRB_KCORE_DECOMPOSITION
36 namespace algorithms {
138 bool criticalSection =
false,
139 typename IOType,
typename NZType
161 const size_t n =
nrows(A);
164 if( n !=
ncols( A )){
168 if(
size( core ) != n ||
169 size( distances ) != n ||
171 size( update ) != n ||
188 IOType current_k = 0;
192 ret = ret ? ret :
set( temp,
static_cast< IOType
>( 1 ) );
193 ret = ret ? ret :
set( distances,
static_cast< IOType
>( 0 ) );
194 ret = ret ? ret :
set( core,
static_cast< IOType
>( 0 ) );
195 ret = ret ? ret :
set( status,
true );
196 ret = ret ? ret :
clear( update );
199 ret = ret ? ret : grb::mxv< descr | descriptors::dense >(
200 distances, A, temp, ring );
204 std::cerr <<
" Initialization of k-core decomposition failed with error "
210 while( count < n &&
SUCCESS == ret ) {
214 ret = ret ? ret :
set( update, status, status );
220 if( criticalSection ) {
221 ret = ret ? ret :
clear( temp );
222 ret = ret ? ret :
eWiseLambda( [ &, current_k ](
const size_t i ) {
223 if( status[ i ] && distances[ i ] <= current_k ) {
224 core[ i ] = current_k;
236 status, distances, core, temp
247 ret = ret ? ret :
eWiseApply( temp, status, distances, current_k,
249 ret = ret ? ret :
foldl( core, temp, current_k,
251 ret = ret ? ret :
foldl( status, temp,
false,
253 ret = ret ? ret :
foldl( flag, temp, lorMonoid );
254 ret = ret ? ret :
set( update, temp, 1 );
256 std::swap( update, temp );
262 ret =
clear( update );
266 count +=
nnz( temp );
269 ret = ret ? ret : grb::mxv< descr >( update, A, temp, ring );
282 std::cerr <<
" Excecution of k-core decomposition failed with error "
An ALP/GraphBLAS matrix.
Definition: matrix.hpp:71
A generalised monoid.
Definition: monoid.hpp:54
A generalised semiring.
Definition: semiring.hpp:186
A GraphBLAS vector.
Definition: vector.hpp:64
Standard identitity for the logical or operator.
Definition: identities.hpp:151
Standard identity for numerical multiplication.
Definition: identities.hpp:79
Standard identity for numerical addition.
Definition: identities.hpp:57
This operator takes the sum of the two input parameters and writes it to the output variable.
Definition: ops.hpp:177
This operation returns whether the left operand compares less-than or equal to the right operand.
Definition: ops.hpp:738
The logical or.
Definition: ops.hpp:464
This operator multiplies the two input parameters and writes the result to the output variable.
Definition: ops.hpp:210
This operator discards all left-hand side input and simply copies the right-hand side input to the ou...
Definition: ops.hpp:117
Numerical substraction of two numbers.
Definition: ops.hpp:303
The main header to include in order to use the ALP/GraphBLAS API.
RC eWiseLambda(const Func f, const Vector< DataType, backend, Coords > &x, Args...)
Executes an arbitrary element-wise user-defined function f on any number of vectors of equal length.
Definition: blas1.hpp:3746
RC eWiseApply(Vector< OutputType, backend, Coords > &z, const InputType1 alpha, const InputType2 beta, const OP &op=OP(), const Phase &phase=EXECUTE, const typename std::enable_if< !grb::is_object< OutputType >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&grb::is_operator< OP >::value, void >::type *const =nullptr)
Computes , out of place, operator version.
Definition: blas1.hpp:208
RC foldl(IOType &x, const Vector< InputType, backend, Coords > &y, const Vector< MaskType, backend, Coords > &mask, const Monoid &monoid=Monoid(), const typename std::enable_if< !grb::is_object< IOType >::value &&!grb::is_object< InputType >::value &&!grb::is_object< MaskType >::value &&grb::is_monoid< Monoid >::value, void >::type *const =nullptr)
Reduces, or folds, a vector into a scalar.
Definition: blas1.hpp:3840
RC set(Vector< DataType, backend, Coords > &x, const T val, const Phase &phase=EXECUTE, const typename std::enable_if< !grb::is_object< DataType >::value &&!grb::is_object< T >::value, void >::type *const =nullptr) noexcept
Sets all elements of a vector to the given value.
Definition: io.hpp:857
size_t nnz(const Vector< DataType, backend, Coords > &x) noexcept
Request the number of nonzeroes in a given vector.
Definition: io.hpp:479
size_t size(const Vector< DataType, backend, Coords > &x) noexcept
Request the size of a given vector.
Definition: io.hpp:235
size_t ncols(const Matrix< InputType, backend, RIT, CIT, NIT > &A) noexcept
Requests the column size of a given matrix.
Definition: io.hpp:339
size_t capacity(const Vector< InputType, backend, Coords > &x) noexcept
Queries the capacity of the given ALP/GraphBLAS container.
Definition: io.hpp:388
RC setElement(Vector< DataType, backend, Coords > &x, const T val, const size_t i, const Phase &phase=EXECUTE, const typename std::enable_if< !grb::is_object< DataType >::value &&!grb::is_object< T >::value, void >::type *const =nullptr)
Sets the element of a given vector at a given position to a given value.
Definition: io.hpp:1128
size_t nrows(const Matrix< InputType, backend, RIT, CIT, NIT > &A) noexcept
Requests the row size of a given matrix.
Definition: io.hpp:286
RC clear(Vector< DataType, backend, Coords > &x) noexcept
Clears a given vector of all nonzeroes.
Definition: io.hpp:574
RC kcore_decomposition(const Matrix< NZType > &A, Vector< IOType > &core, Vector< IOType > &distances, Vector< IOType > &temp, Vector< IOType > &update, Vector< bool > &status, IOType &k)
The -core decomposition algorithm.
Definition: kcore_decomposition.hpp:141
static constexpr Descriptor no_operation
Indicates no additional pre- or post-processing on any of the GraphBLAS function arguments.
Definition: descriptors.hpp:63
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:452
RC
Return codes of ALP primitives.
Definition: rc.hpp:47
@ ILLEGAL
A call to a primitive has determined that one of its arguments was illegal as per the specification o...
Definition: rc.hpp:143
@ MISMATCH
One or more of the ALP/GraphBLAS objects passed to the primitive that returned this error have mismat...
Definition: rc.hpp:90
@ SUCCESS
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
unsigned int Descriptor
Descriptors indicate pre- or post-processing for some or all of the arguments to an ALP/GraphBLAS cal...
Definition: descriptors.hpp:54
std::string toString(const RC code)