Skip to content

Commit

Permalink
slight changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Olumayowa-Olowomeye committed Nov 4, 2024
1 parent 48ef0f6 commit 7d277d1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
8 changes: 4 additions & 4 deletions experimental/algorithm/LAGraph_Louvain2.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,15 @@ int LAGraph_Louvain2(
bool changed = true;
int max_iter = 20;
int iter =0;

GRB_TRY(GrB_mxv(z,NULL,NULL,stdmxm,S,k,NULL));
while(changed && iter < max_iter){
changed = false;
double k_i;
GRB_TRY(GrB_mxv(z,NULL,NULL,stdmxm,S,k,NULL));

for(int i=0;i<n;i++){//extract tuples
// v = A(i,:)
GRB_TRY (GrB_Col_extract (v, NULL, NULL, A, GrB_ALL, b, i,GrB_DESC_T0));
// GxB_print(v,5);

// -- extract k_i
GRB_TRY(GrB_Vector_extractElement_FP64(&k_i,k,i));

Expand All @@ -163,6 +162,7 @@ int LAGraph_Louvain2(
Sx[i] = false;
GRB_TRY (GxB_Matrix_pack_CSR (S, &Sp, &Sj, (void**)&Sx,
Sp_size, Sj_size, Sx_size, NULL, S_jumbled, NULL));

////////////////////////////////////////////////////////////

double alpha = -k_i/m;
Expand All @@ -184,9 +184,9 @@ int LAGraph_Louvain2(
// GxB_print(z,5);
GRB_TRY(GrB_Vector_apply_BinaryOp2nd_FP64(z,NULL,NULL,timesf64,dSk,alpha,NULL));
// GxB_print(z,5);

// vtS
GRB_TRY(GrB_vxm(vtS,NULL,NULL,stdmxm,v,S,GrB_DESC_T0));

// GxB_print(vtS,5);

//Compute q1
Expand Down
2 changes: 1 addition & 1 deletion experimental/algorithm/LaGr_Modularity2.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int LAGr_Modularity2(
double m;
GRB_TRY(GrB_Matrix_reduce_FP64(&m,plusf64,plusmon,A,NULL));
m/=2;
printf("m:%f\n",m);
// printf("m:%f\n",m);
// GxB_print(S,5);
// GxB_print(A,5);
GRB_TRY(GrB_Matrix_reduce_Monoid ((GrB_Vector)k_,NULL,NULL,plusmon,A, GrB_DESC_T0));
Expand Down
64 changes: 64 additions & 0 deletions experimental/algorithm/temp_ibop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include "LG_internal.h"
#include <LAGraphX.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

typedef struct
{
int64_t k;
double v;
} tuple_fp64;
#define FP64_K "typedef struct { int64_t k ; double v ; } tuple_fp64 ;"
void make_fp64(tuple_fp64 *z,
const double *x, GrB_Index ix, GrB_Index jx,
const void *y, GrB_Index iy, GrB_Index jy,
const void *theta)
{
z->k = (int64_t)jx;
z->v = (*x);
}
void max_fp64(tuple_fp64 *z, const tuple_fp64 *x, const tuple_fp64 *y)
{
if (x->v > y->v || (x->v == y->v && x->k < y->k))
{
z->k = x->k;
z->v = x->v;
}
else
{
z->k = y->k;
z->v = y->v;
}
}

#define MAX_FP64 (a string containing the max_fp64 function above)
// create the types and operators:
GrB_Scalar Theta;
// unused, but cannot be NULL
GrB_Scalar_new(&Theta, GrB_BOOL);
GrB_Scalar_setElement_BOOL(Theta, 0);
GzB_IndexBinaryOp Iop;
GrB_BinaryOp Bop;
GrB_Type Tuple;
GxB_Type_new(&Tuple, sizeof(tuple_fp64), "tuple_fp64", FP64_K);
GzB_IndexBinaryOp_new (&Iop, make_fp64, Tuple, GrB_FP64, GrB_BOOL, GrB_BOOL,
"make_fp64", MAKE_FP64)) ;
OK(GzB_BinaryOp_new_IndexOp(&Bop, Iop, Theta));
tuple_fp64 id;
memset(&id, 0, sizeof(tuple_fp64));
id.k = INT64_MAX;
id.v = (double)(-INFINITY);
OK(GxB_BinaryOp_new(&MonOp, max_fp64, Tuple, Tuple, Tuple, "max_fp64", MAX_FP64));
GrB_Monoid MonOp;
GrB_Semiring Semiring;
GrB_Monoid_new_UDT(&Monoid, MonOp, &id);
GrB_Semiring_new(&Semiring, Monoid, Bop);
// compute the argmax of each row of a GrB_FP64 matrix A:
// y = zeros (ncols,1) ;
GrB_Vector y;
GrB_Matrix_new (&y, GrB_BOOL, ncols, 1)) ;
GrB_Matrix_assign_BOOL (y, NULL, NULL, 0, GrB_ALL, ncols, GrB_ALL, 1, NULL)) ;
// c = A*y using the argmax semiring
GrB_Vector_new (&c, Tuple, nrows, 1)) ;
GrB_mxv(c, NULL, NULL, Semiring, A, y, NULL);

0 comments on commit 7d277d1

Please sign in to comment.