37 namespace algorithms {
40 constexpr size_t MaxPrinting = 20;
41 constexpr size_t MaxAnyPrinting = 100;
44 static void printVector(
45 const Vector< double > &v,
const std::string message
50 if(
size > MaxAnyPrinting ) {
53 std::cerr <<
"\t " << message <<
": ";
54 for( Vector< double >::const_iterator it = v.begin(); it != v.end(); ++it ) {
55 const std::pair< size_t, double > iter = *it;
56 const double val = iter.second;
57 if( val < INFINITY ) {
58 if(
size > MaxPrinting ) {
59 zeros += ( val == 0 ) ? 1 : 0;
60 ones += ( val == 1 ) ? 1 : 0;
62 std::cerr << val <<
" ";
66 if(
size > MaxPrinting ) {
67 std::cerr << zeros <<
" zeros; " << ones <<
" ones.";
122 template<
typename IOType >
126 const size_t n,
const size_t l,
127 const size_t maxIterations = 1000
139 const IOType zero = reals.template getZero< IOType >();
163 RC ret =
set( multiplier,
static_cast< IOType
>(1) );
166 ret = ret ? ret :
set( diagonals, zero );
167 ret = ret ? ret : mxv< descriptors::dense >(
168 diagonals, W, multiplier, reals
171 printVector( diagonals,
"diagonals matrix in vector form" );
184 ret = ret ? ret :
eWiseLambda( [ &diagonals ](
const size_t i ) {
185 diagonals[ i ] = 1.0 / diagonals[ i ];
193 for(
size_t i = 0; ret ==
SUCCESS && i < l; ++i ) {
198 ret = ret ? ret :
set( f, y );
202 bool different =
true;
206 while( ret ==
SUCCESS && different && iter < maxIterations ) {
209 if( n < MaxAnyPrinting ) {
210 std::cerr <<
"\t iteration " << iter <<
"\n";
214 std::cerr <<
"\t pre- set/mxv nnz( f ) = " <<
nnz( f ) <<
", "
215 <<
"fNext = " <<
nnz( fNext ) <<
"\n";
217 ret = ret ? ret :
set( fNext, zero );
218 ret = ret ? ret :
mxv( fNext, W, f, reals );
220 std::cerr <<
"\t post-set/mxv nnz( f ) = " <<
nnz( f ) <<
", "
221 <<
"nnz( fNext ) = " <<
nnz( fNext ) <<
"\n";
222 printVector( f,
"Previous iteration solution" );
223 printVector( fNext,
"New iteration solution" );
228 ret = ret ? ret :
eWiseLambda( [ &fNext, &diagonals ](
const size_t i ) {
229 fNext[ i ] = ( fNext[ i ] * diagonals[ i ] < 0.5 ? 0 : 1 );
233 printVector( fNext,
"New iteration solution after threshold cutoff" );
234 std::cerr <<
"\t pre-set nnz( fNext ) = " <<
nnz( fNext ) <<
", "
235 <<
"nnz( mask ) = " <<
nnz( mask ) <<
"\n";
238 ret = ret ? ret :
foldl(
245 std::cerr <<
"\t post-set nnz( fNext ) = " <<
nnz( fNext ) <<
"\n";
248 "New iteration solution after threshold cutoff and clamping"
253 ret = ret ? ret :
dot( different, f, fNext, orMonoid, notEqualOp );
257 std::cerr <<
"\t pre-set nnz(f) = " <<
nnz( f ) <<
"\n";
259 std::swap( f, fNext );
261 std::cerr <<
"\t post-set nnz(f) = " <<
nnz( f ) <<
"\n";
270 std::cerr <<
"Info: label propagation did not converge after "
271 << (iter-1) <<
" iterations\n";
276 std::cerr <<
"Info: label propagation converged in "
277 << (iter-1) <<
" iterations\n";
286 std::cerr <<
"Warning: label propagation exiting with " <<
toString(ret)
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
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
Operator that returns false whenever its inputs compare equal, and true otherwise.
Definition: ops.hpp:407
This operator discards all left-hand side input and simply copies the right-hand side input to the ou...
Definition: ops.hpp:117
static size_t pid() noexcept
Definition: spmd.hpp:61
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 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 dot(OutputType &z, const Vector< InputType1, backend, Coords > &x, const Vector< InputType2, backend, Coords > &y, const AddMonoid &addMonoid=AddMonoid(), const AnyOp &anyOp=AnyOp(), 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_monoid< AddMonoid >::value &&grb::is_operator< AnyOp >::value, void >::type *const =nullptr)
Calculates the dot product, , under a given additive monoid and multiplicative operator.
Definition: blas1.hpp:4056
RC mxv(Vector< IOType, backend, Coords > &u, const Vector< InputType3, backend, Coords > &u_mask, const Matrix< InputType2, backend, RIT, CIT, NIT > &A, const Vector< InputType1, backend, Coords > &v, const Vector< InputType4, backend, Coords > &v_mask, const Semiring &semiring=Semiring(), const Phase &phase=EXECUTE, const typename std::enable_if< grb::is_semiring< Semiring >::value &&!grb::is_object< IOType >::value &&!grb::is_object< InputType1 >::value &&!grb::is_object< InputType2 >::value &&!grb::is_object< InputType3 >::value &&!grb::is_object< InputType4 >::value, void >::type *const =nullptr)
Right-handed in-place doubly-masked sparse matrix times vector multiplication, .
Definition: blas2.hpp:243
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 label(Vector< IOType > &out, const Vector< IOType > &y, const Matrix< IOType > &W, const size_t n, const size_t l, const size_t maxIterations=1000)
The label propagation algorithm.
Definition: label.hpp:123
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
@ SUCCESS
Indicates the primitive has executed successfully.
Definition: rc.hpp:54
@ FAILED
Indicates when one of the grb::algorithms has failed to achieve its intended result,...
Definition: rc.hpp:154
std::string toString(const RC code)