From 58f0c447719d276ee074fa7be0e28b3fe53a0892 Mon Sep 17 00:00:00 2001 From: MLopez-Ibanez <2620021+MLopez-Ibanez@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:48:12 +0000 Subject: [PATCH] Silence CRAN warnings and prepare 2.5. --- DESCRIPTION | 2 +- NEWS.md | 4 +- man/eafplot.Rd | 4 +- src/Reaf.c | 2 +- src/eaf/eaf.h | 4 +- src/eaf/eaf3d.c | 115 ++++++++++++++++++++------------------ src/eaf/gcc.mk | 2 +- src/eaf/svn_version | 2 +- src/mo-tools/gcc.mk | 2 +- src/mo-tools/hv_contrib.h | 8 --- src/mo-tools/svn_version | 2 +- 11 files changed, 72 insertions(+), 75 deletions(-) delete mode 100644 src/mo-tools/hv_contrib.h diff --git a/DESCRIPTION b/DESCRIPTION index 2f7a511..16996a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: eaf Type: Package Title: Plots of the Empirical Attainment Function -Version: 2.4.1.9000 +Version: 2.5 Authors@R: c(person("Manuel", "López-Ibáñez", role = c("aut", "cre"), email = "manuel.lopez-ibanez@manchester.ac.uk", comment = c(ORCID = "0000-0001-9974-1295")), diff --git a/NEWS.md b/NEWS.md index d6f6a6d..bc8c1b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,7 @@ -# development version +# eaf 2.5 * The argument `to.range` of `normalise()` has been renamed to `to_range`. -# eaf 2.5 - * Silence some warnings with GCC 12. # eaf 2.4 diff --git a/man/eafplot.Rd b/man/eafplot.Rd index e30b1cc..0fe30b6 100644 --- a/man/eafplot.Rd +++ b/man/eafplot.Rd @@ -139,7 +139,7 @@ tabucol <- subset(gcp2x2, alg != "TSinN1") tabucol$alg <- tabucol$alg[drop=TRUE] eafplot(time + best ~ run, data = tabucol, subset = tabucol$inst=="DSJC500.5") -\dontrun{# These take time +\donttest{# These take time eafplot(time + best ~ run | inst, groups=alg, data=gcp2x2) eafplot(time + best ~ run | inst, groups=alg, data=gcp2x2, percentiles=c(0,50,100), cex.axis = 0.8, lty = c(2,1,2), lwd = c(2,2,2), @@ -158,7 +158,7 @@ str(attsurfs) } ## Using extra.points -\dontrun{ +\donttest{ data(HybridGA) data(SPEA2relativeVanzyl) eafplot(SPEA2relativeVanzyl, percentiles = c(25, 50, 75), diff --git a/src/Reaf.c b/src/Reaf.c index 4ce5908..3a950e5 100644 --- a/src/Reaf.c +++ b/src/Reaf.c @@ -48,7 +48,7 @@ compute_eaf_helper (SEXP DATA, int nobj, SEXP CUMSIZES, int nruns, DEBUG2( Rprintf ("eaf computed\n"); for (k = 0; k < nlevels; k++) { - Rprintf ("eaf[%d] = %d\n", k, eaf[k]->size); + Rprintf ("eaf[%d] = %zu\n", k, eaf[k]->size); }); return eaf; diff --git a/src/eaf/eaf.h b/src/eaf/eaf.h index b7df358..cb30b2c 100644 --- a/src/eaf/eaf.h +++ b/src/eaf/eaf.h @@ -43,8 +43,8 @@ #define EAF_MALLOC(WHAT, NMEMB, TYPE) \ do { WHAT = malloc (NMEMB * sizeof(TYPE)); \ if (!WHAT) { \ - Rf_error(__FILE__ ": %s = malloc (%u * %u) failed", \ - #WHAT, (unsigned int) NMEMB, (unsigned int) sizeof(TYPE)); } \ + Rf_error(__FILE__ ": %s = malloc (%u * %zu) failed", \ + #WHAT, (unsigned int) NMEMB, sizeof(TYPE)); } \ } while (0) #else #define EAF_MALLOC(WHAT, NMEMB, TYPE) \ diff --git a/src/eaf/eaf3d.c b/src/eaf/eaf3d.c index 25f4e0e..cbe010d 100644 --- a/src/eaf/eaf3d.c +++ b/src/eaf/eaf3d.c @@ -86,8 +86,6 @@ static int compare_node(const void *p1, const void *p2) static dlnode_t * setup_cdllist(objective_t *data, int d, const int *cumsize, int nsets) { - dlnode_t **scratch; - int n = cumsize[nsets - 1]; dlnode_t *head = malloc ((n + 1) * sizeof(dlnode_t)); head->x = data; @@ -105,7 +103,7 @@ setup_cdllist(objective_t *data, int d, const int *cumsize, int nsets) } head->x = NULL; // head contains no data - scratch = malloc(n * sizeof(dlnode_t*)); + dlnode_t **scratch = malloc(n * sizeof(dlnode_t*)); for (i = 0; i < n; i++) scratch[i] = head + i + 1; @@ -161,26 +159,32 @@ static int avl_search_closest_y(const avl_tree_t *avltree, const void *item, avl avlnode = &node; node = avltree->top; + if(!node) { + *avlnode = NULL; + return 0; + } - if(!node) - return *avlnode = NULL, 0; - - for(;;) { + do { c = compare_tree_desc_y(item, node->item); - if(c < 0) { + if (c < 0) { if(node->left) node = node->left; - else - return *avlnode = node, -1; - } else if(c > 0) { + else { + *avlnode = node; + return -1; + } + } else if (c > 0) { if(node->right) node = node->right; - else - return *avlnode = node, 1; + else { + *avlnode = node; + return 1; + } } else { - return *avlnode = node, 0; + *avlnode = node; + return 0; } - } + } while(true); } @@ -546,17 +550,20 @@ eaf3df(dlnode_t *list, avl_tree_t **set, avl_tree_t **level, { // point from some level immediately at new's left, corresponds to r in pseudocode avl_node_t *leftNodeL; - - /*levelNode[t] is the point being verified (possibly to be promoted) from level t, - corresponds to s_t in pseudocode */ - avl_node_t *levelNode[nset]; - - avl_node_t auxNodes[nset]; /* these points are needed to represent the intersections of new - with the point, of each level, immediately at new's left */ - objective_t auxValues[nset][2]; - - avl_node_t *promoters[nset]; + struct aux_nodes { + /* levelNode[t] is the point being verified (possibly to be promoted) from level t, + corresponds to s_t in pseudocode */ + avl_node_t *levelNode; + /* these points are needed to represent the intersections of new + with the point, of each level, immediately at new's left */ + avl_node_t intersectNode; + objective_t intersectValues[2]; + avl_node_t * promoter; + }; + + struct aux_nodes * aux = malloc(sizeof(struct aux_nodes) * nset); + dlnode_t *new = list->next; //new - represents the new point //add new to its set @@ -568,7 +575,7 @@ eaf3df(dlnode_t *list, avl_tree_t **set, avl_tree_t **level, avl_add_promoter(tnode, new->set, NULL); avl_insert_after(level[0], level[0]->head, tnode); - bool mask[nset]; // needed to know how many different sets were considered so far + bool * mask = malloc(sizeof(bool) * nset); // needed to know how many different sets were considered so far memset(mask, false, nset * sizeof(mask[0])); mask[new->set] = true; @@ -605,18 +612,18 @@ eaf3df(dlnode_t *list, avl_tree_t **set, avl_tree_t **level, /* the intersection point of new with the point in level k immediately at new's left should be added to level k+1, so this intersection point is saved in levelNode in order to be added later */ - auxValues[k][0] = new->x[0]; - auxValues[k][1] = node_point(leftNodeL)[1]; + aux[k].intersectValues[0] = new->x[0]; + aux[k].intersectValues[1] = node_point(leftNodeL)[1]; - auxNodes[k].item = auxValues[k]; - auxNodes[k].next = leftNodeL->next; + aux[k].intersectNode.item = aux[k].intersectValues; + aux[k].intersectNode.next = leftNodeL->next; - levelNode[k] = &auxNodes[k]; - promoters[k] = leftNodeL; + aux[k].levelNode = &(aux[k].intersectNode); + aux[k].promoter = leftNodeL; } else { - levelNode[k] = find_point_below(level[k], newPrev->item); - promoters[k] = levelNode[k]; + aux[k].levelNode = find_point_below(level[k], newPrev->item); + aux[k].promoter = aux[k].levelNode; } } @@ -631,38 +638,37 @@ eaf3df(dlnode_t *list, avl_tree_t **set, avl_tree_t **level, for (k = start_at; k >= stop_at; k--) { //while levelNode is dominated by new but not by any point from new's set, levelNode is promoted - while (node_point(levelNode[k])[1] >= lbound - && (node_point(levelNode[k])[1] > lbound || lbound > new->x[1])) { + while (node_point(aux[k].levelNode)[1] >= lbound + && (node_point(aux[k].levelNode)[1] > lbound || lbound > new->x[1])) { - if (node_point(setNode)[0] <= node_point(levelNode[k])[0]) { - levelNode[k] = find_point_below(level[k], setNode->item); - promoters[k] = levelNode[k]; + if (node_point(setNode)[0] <= node_point(aux[k].levelNode)[0]) { + aux[k].levelNode = find_point_below(level[k], setNode->item); + aux[k].promoter = aux[k].levelNode; } else { - objective_t *value = new_point(node_point(levelNode[k])[0], node_point(levelNode[k])[1], new->x[2]); - tnode = add2level(level[k+1], value, output[k+1], new->set, promoters[k]); - if(tnode != NULL && new->x[2] == node_point(promoters[k])[2] && node_point(levelNode[k])[0] == node_point(promoters[k])[0]){ - promoters[k]->equal = tnode; + objective_t *value = new_point(node_point(aux[k].levelNode)[0], node_point(aux[k].levelNode)[1], new->x[2]); + tnode = add2level(level[k+1], value, output[k+1], new->set, aux[k].promoter); + if(tnode != NULL && new->x[2] == node_point(aux[k].promoter)[2] && node_point(aux[k].levelNode)[0] == node_point(aux[k].promoter)[0]){ + aux[k].promoter->equal = tnode; } - levelNode[k] = levelNode[k]->next; - promoters[k] = levelNode[k]; + aux[k].levelNode = aux[k].levelNode->next; + aux[k].promoter = aux[k].levelNode; } } } - }while(node_point(setNode)[1] > new->x[1]); + } while(node_point(setNode)[1] > new->x[1]); //Third part for(k = start_at; k >= stop_at; k--){ //if the intersection point of new with the point from level k immediately below new //isn't dominated, it is added to level k+1 - if(node_point(levelNode[k])[0] < node_point(setNode)[0]){ + if(node_point(aux[k].levelNode)[0] < node_point(setNode)[0]){ - objective_t *value; - value = new_point(node_point(levelNode[k])[0], new->x[1], new->x[2]); - tnode = add2level(level[k+1], value, output[k+1], new->set, promoters[k]); - if(tnode != NULL && new->x[2] == node_point(levelNode[k])[2] && new->x[1] == node_point(levelNode[k])[1]){ - promoters[k]->equal = tnode; + objective_t *value =new_point(node_point(aux[k].levelNode)[0], new->x[1], new->x[2]); + tnode = add2level(level[k+1], value, output[k+1], new->set, aux[k].promoter); + if (tnode != NULL && new->x[2] == node_point(aux[k].levelNode)[2] && new->x[1] == node_point(aux[k].levelNode)[1]){ + aux[k].promoter->equal = tnode; } } } @@ -684,6 +690,8 @@ eaf3df(dlnode_t *list, avl_tree_t **set, avl_tree_t **level, mask[new->set] = true; } } + free(mask); + free(aux); } @@ -694,7 +702,6 @@ freetree(avl_tree_t *avltree) aux=avltree->head; if(aux){ - while(aux){ aux2 = aux; aux = aux2->next; @@ -825,7 +832,7 @@ eaf3d (objective_t *data, const int *cumsize, int nruns, /* FIXME: This should be done earlier instead of creating the trees. */ eaf_t **eaf = malloc(nlevels * sizeof(eaf_t*)); - int attained[nruns]; + int * attained = malloc(nruns * sizeof(int)); for (int l = 0; l < nlevels; l++) { eaf[l] = eaf_create (nobj, nruns, ntotal); int k = attlevel[l] - 1; diff --git a/src/eaf/gcc.mk b/src/eaf/gcc.mk index 3528cb5..5f3e26b 100644 --- a/src/eaf/gcc.mk +++ b/src/eaf/gcc.mk @@ -1,5 +1,5 @@ # -*- Makefile-gmake -*- -WARN_CFLAGS = -pedantic -Wall -Wextra +WARN_CFLAGS = -pedantic -Wall -Wextra -Wvla SANITIZERS= -fsanitize=undefined -fsanitize=address ifeq ($(DEBUG), 0) OPT_CFLAGS ?= -O3 -flto -DNDEBUG diff --git a/src/eaf/svn_version b/src/eaf/svn_version index 27b4d6e..eff3954 100644 --- a/src/eaf/svn_version +++ b/src/eaf/svn_version @@ -1 +1 @@ -287 \ No newline at end of file +290 \ No newline at end of file diff --git a/src/mo-tools/gcc.mk b/src/mo-tools/gcc.mk index 3528cb5..5f3e26b 100644 --- a/src/mo-tools/gcc.mk +++ b/src/mo-tools/gcc.mk @@ -1,5 +1,5 @@ # -*- Makefile-gmake -*- -WARN_CFLAGS = -pedantic -Wall -Wextra +WARN_CFLAGS = -pedantic -Wall -Wextra -Wvla SANITIZERS= -fsanitize=undefined -fsanitize=address ifeq ($(DEBUG), 0) OPT_CFLAGS ?= -O3 -flto -DNDEBUG diff --git a/src/mo-tools/hv_contrib.h b/src/mo-tools/hv_contrib.h deleted file mode 100644 index 30a0ffb..0000000 --- a/src/mo-tools/hv_contrib.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HV_CONTRIB_H -#define HV_CONTRIB_H - -double * -hv_contrib (const double *points, int dim, int size, const double * ref, - const bool * uev); - -#endif diff --git a/src/mo-tools/svn_version b/src/mo-tools/svn_version index 7b27b25..4a8d924 100644 --- a/src/mo-tools/svn_version +++ b/src/mo-tools/svn_version @@ -1 +1 @@ -173 \ No newline at end of file +174 \ No newline at end of file