#include #include #include "sources/neighbors.h" #include "sources/utils/algebra.h" #include // Function to obtain neighborhoods. // NOTE: alpha = weight parameter to compute distances; -1 means "adaptive" // WARNING : M is given in columns SEXP getNeighbors( SEXP M_, SEXP k_, SEXP alpha_, SEXP gmode_, SEXP simpleDists_ ) { // get scalar arguments int k = INTEGER_VALUE(k_); double alpha = NUMERIC_VALUE(alpha_); int gmode = INTEGER_VALUE(gmode_); int simpleDists = LOGICAL_VALUE(simpleDists_); // extract infos from M and get associate pointer SEXP dim = getAttrib(M_, R_DimSymbol); int nrow = INTEGER(dim)[0]; int ncol = INTEGER(dim)[1]; // M is always given by columns: easier to process in rows double* pM = transpose(REAL(M_), nrow, ncol); // Main call to core algorithm which fills neighborhoods lists List** neighborhoods = getNeighbors_core(pM, alpha, k, gmode, simpleDists, nrow, ncol); // transfer neighborhoods lists into R vectors SEXP NIix, NIds; PROTECT(NIix = allocVector(VECSXP, nrow)); //indices PROTECT(NIds = allocVector(VECSXP, nrow)); //distances for (int i=0; i