Skip to content

Commit

Permalink
Merge branch 'statnet:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienLeGuillou authored Sep 26, 2024
2 parents dc9dff1 + c5180b3 commit ac38cda
Show file tree
Hide file tree
Showing 33 changed files with 340 additions and 347 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ergm
Version: 4.7-7377
Date: 2024-07-22
Version: 4.7-7384
Date: 2024-09-05
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
person(c("Mark", "S."), "Handcock", role=c("aut"), email="[email protected]"),
Expand Down
2 changes: 1 addition & 1 deletion R/ergm_keyword.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ergm_keyword <- local({
if (all(is.null(name), is.null(short), is.null(description), is.null(popular), is.null(package))) {
return(cache)
} else if (any(is.null(name), is.null(short), is.null(description), is.null(popular), is.null(package))) {
stop("All arguments are needed to register Ergm keyword")
stop("All arguments are needed to register ", sQuote("ergm"), " keyword")
} else if (!is.logical(popular)) {
stop("Logical value expected for argument 'popular'")
} else {
Expand Down
52 changes: 26 additions & 26 deletions inst/include/ergm_BDNodeLists.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static inline BDNodeLists *BDNodeListsInitialize(int **maxout,
int bd_nlevels,
int *combined_vattr_counts,
Network *nwp) {
BDNodeLists *lists = Calloc(1, BDNodeLists);
BDNodeLists *lists = R_Calloc(1, BDNodeLists);

// do some copying
lists->directed = DIRECTED;
Expand All @@ -67,25 +67,25 @@ static inline BDNodeLists *BDNodeListsInitialize(int **maxout,
lists->bd_nlevels = bd_nlevels;

// set up node lists
lists->bothpos = Calloc(bd_nlevels, int *);
lists->tailpos = DIRECTED ? Calloc(bd_nlevels, int *) : lists->bothpos;
lists->headpos = DIRECTED ? Calloc(bd_nlevels, int *) : lists->bothpos;
lists->bothpos = R_Calloc(bd_nlevels, int *);
lists->tailpos = DIRECTED ? R_Calloc(bd_nlevels, int *) : lists->bothpos;
lists->headpos = DIRECTED ? R_Calloc(bd_nlevels, int *) : lists->bothpos;

lists->boths = Calloc(bd_nlevels, NodeList **);
lists->tails = DIRECTED ? Calloc(bd_nlevels, NodeList **) : lists->boths;
lists->heads = DIRECTED ? Calloc(bd_nlevels, NodeList **) : lists->boths;
lists->boths = R_Calloc(bd_nlevels, NodeList **);
lists->tails = DIRECTED ? R_Calloc(bd_nlevels, NodeList **) : lists->boths;
lists->heads = DIRECTED ? R_Calloc(bd_nlevels, NodeList **) : lists->boths;

for(int i = 0; i < bd_nlevels; i++) {
lists->bothpos[i] = Calloc(N_NODES + 1, int);
lists->bothpos[i] = R_Calloc(N_NODES + 1, int);
if(DIRECTED) {
lists->tailpos[i] = Calloc(N_NODES + 1, int);
lists->headpos[i] = Calloc(N_NODES + 1, int);
lists->tailpos[i] = R_Calloc(N_NODES + 1, int);
lists->headpos[i] = R_Calloc(N_NODES + 1, int);
}

lists->boths[i] = Calloc(combined_nlevels, NodeList *);
lists->boths[i] = R_Calloc(combined_nlevels, NodeList *);
if(DIRECTED) {
lists->tails[i] = Calloc(combined_nlevels, NodeList *);
lists->heads[i] = Calloc(combined_nlevels, NodeList *);
lists->tails[i] = R_Calloc(combined_nlevels, NodeList *);
lists->heads[i] = R_Calloc(combined_nlevels, NodeList *);
}

for(int j = 0; j < combined_nlevels; j++) {
Expand Down Expand Up @@ -128,32 +128,32 @@ static inline void BDNodeListsDestroy(BDNodeLists *lists) {
}
}

Free(lists->boths[i]);
R_Free(lists->boths[i]);
if(lists->directed) {
Free(lists->tails[i]);
Free(lists->heads[i]);
R_Free(lists->tails[i]);
R_Free(lists->heads[i]);
}

Free(lists->bothpos[i]);
R_Free(lists->bothpos[i]);
if(lists->directed) {
Free(lists->tailpos[i]);
Free(lists->headpos[i]);
R_Free(lists->tailpos[i]);
R_Free(lists->headpos[i]);
}
}

Free(lists->boths);
R_Free(lists->boths);
if(lists->directed) {
Free(lists->tails);
Free(lists->heads);
R_Free(lists->tails);
R_Free(lists->heads);
}

Free(lists->bothpos);
R_Free(lists->bothpos);
if(lists->directed) {
Free(lists->tailpos);
Free(lists->headpos);
R_Free(lists->tailpos);
R_Free(lists->headpos);
}

Free(lists);
R_Free(lists);
}

// update NodeLists as appropriate for a toggle with tail, head maximality
Expand Down
16 changes: 8 additions & 8 deletions inst/include/ergm_BDStratBlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ static inline BDStratBlocks *BDStratBlocksInitialize(BDNodeLists *lists,
int *bd_tails,
int *bd_heads,
Network *nwp) {
BDStratBlocks *blocks = Calloc(1, BDStratBlocks);
BDStratBlocks *blocks = R_Calloc(1, BDStratBlocks);

// do some copying
blocks->lists = lists;

// set up blocks
blocks->blocks = Calloc(strat_nmixtypes, Block **);
blocks->nblocks = Calloc(strat_nmixtypes, int);
blocks->blocks = R_Calloc(strat_nmixtypes, Block **);
blocks->nblocks = R_Calloc(strat_nmixtypes, int);
blocks->strat_nmixtypes = strat_nmixtypes;
for(int i = 0; i < strat_nmixtypes; i++) {
int strat_diag = (strat_tails[i] == strat_heads[i]);
Expand All @@ -67,7 +67,7 @@ static inline BDStratBlocks *BDStratBlocksInitialize(BDNodeLists *lists,
int base_nblocks = (1 + !strat_diag)*nblocksoffdiag*bd_mixtypes[0] + nblocksdiag*bd_mixtypes[strat_diag];
blocks->nblocks[i] = DIRECTED ? 4*base_nblocks : base_nblocks;

blocks->blocks[i] = Calloc(blocks->nblocks[i], Block *);
blocks->blocks[i] = R_Calloc(blocks->nblocks[i], Block *);
int l = 0;
for(int j = 0; j < nblocksmixtypes; j++) {
int blocks_diag = (blocks_tails[j] == blocks_heads[j]);
Expand Down Expand Up @@ -108,11 +108,11 @@ static inline void BDStratBlocksDestroy(BDStratBlocks *blocks) {
for(int j = 0; j < blocks->nblocks[i]; j++) {
BlockDestroy(blocks->blocks[i][j]);
}
Free(blocks->blocks[i]);
R_Free(blocks->blocks[i]);
}
Free(blocks->blocks);
Free(blocks->nblocks);
Free(blocks);
R_Free(blocks->blocks);
R_Free(blocks->nblocks);
R_Free(blocks);
}

static inline Dyad BDStratBlocksDyadCount(BDStratBlocks *blocks, int stratmixingtype) {
Expand Down
2 changes: 1 addition & 1 deletion inst/include/ergm_MHstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* Storage utilities for MH proposal clients */
#define MH_STORAGE (/* (stored_type *) */ MHp->storage)
#define MH_N_AUX (MHp->n_aux)
#define MH_ALLOC_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (MH_STORAGE = Calloc(nmemb, stored_type));
#define MH_ALLOC_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (MH_STORAGE = R_Calloc(nmemb, stored_type));
#define MH_GET_STORAGE(stored_type, store_into) stored_type *store_into = (stored_type *) MH_STORAGE;

#define MH_AUX_STORAGE (/* (stored_type *) */ MHp->aux_storage)
Expand Down
2 changes: 1 addition & 1 deletion inst/include/ergm_Rutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static inline SEXP mkRStrVec(const char **x){
// Safely test if x is a NULL C pointer or a NULL R pointer.
#define isNULL(x) ((x)==NULL || (x)==R_NilValue)

// An alias for R_alloc that behaves more like Calloc(); uses the
// An alias for R_alloc that behaves more like R_Calloc(); uses the
// following helper function:
static inline void *R_calloc_helper(size_t n, size_t size){
char *tmp = R_alloc(n, size);
Expand Down
4 changes: 2 additions & 2 deletions inst/include/ergm_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef struct {
} Block;

static inline Block *BlockInitialize(NodeList *tails, NodeList *heads, int diagonal, int directed) {
Block *block = Calloc(1, Block);
Block *block = R_Calloc(1, Block);
block->tails = tails;
block->heads = heads;
block->diagonal = diagonal;
Expand All @@ -38,7 +38,7 @@ static inline Block *BlockInitialize(NodeList *tails, NodeList *heads, int diago
}

static inline void BlockDestroy(Block *block) {
Free(block);
R_Free(block);
}

static inline void BlockPut2Dyad(Vertex *tail, Vertex *head, Dyad dyadindex, Block *block) {
Expand Down
5 changes: 0 additions & 5 deletions inst/include/ergm_dyad_hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
#include <R.h>
#include "ergm_edgetree_types.h"

/* Specify allocators. */
#define kcalloc(N,Z) R_chk_calloc(N,Z)
#define kmalloc(Z) R_chk_calloc(Z,1)
#define krealloc(P,Z) R_chk_realloc(P,Z)
#define kfree(P) R_chk_free(P)
#include "ergm_khash.h"

/* Data structure to represent a dyad that can serve as a key to the hash. */
Expand Down
4 changes: 2 additions & 2 deletions inst/include/ergm_hash_edgelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct {

/* Embed an existing UnsrtEL into a HashEL. */
static inline HashEL *UnsrtELIntoHashEL(UnsrtEL *el) {
HashEL *hash = Calloc(1, HashEL);
HashEL *hash = R_Calloc(1, HashEL);

hash->list = el;

Expand All @@ -52,7 +52,7 @@ static inline HashEL *HashELInitialize(unsigned int nedges, Vertex *tails, Verte
static inline void HashELDestroy(HashEL *hash) {
kh_destroy(StrictDyadMapUInt, hash->hash);
UnsrtELDestroy(hash->list);
Free(hash);
R_Free(hash);
}

static inline void HashELClear(HashEL *hash) {
Expand Down
47 changes: 15 additions & 32 deletions inst/include/ergm_khash.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ int main() {
#include <string.h>
#include <limits.h>
#include <stdbool.h>
#include <R.h>

/* compiler specific configuration */

Expand Down Expand Up @@ -223,19 +224,6 @@ static kh_inline klib_unused bool __ac_set_isempty_if_isdel(khint32_t *flag, khi
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#endif

#ifndef kcalloc
#define kcalloc(N,Z) calloc(N,Z)
#endif
#ifndef kmalloc
#define kmalloc(Z) malloc(Z)
#endif
#ifndef krealloc
#define krealloc(P,Z) realloc(P,Z)
#endif
#ifndef kfree
#define kfree(P) free(P)
#endif

static const double __ac_HASH_UPPER = 0.77;

#define __KHASH_TYPE(name, khkey_t, khval_t, __extra_data) \
Expand All @@ -260,33 +248,33 @@ static const double __ac_HASH_UPPER = 0.77;

#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
SCOPE kh_##name##_t *kh_init_##name(void) { \
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
return R_Calloc(1, kh_##name##_t); \
} \
SCOPE kh_##name##_t *kh_copy_##name(kh_##name##_t *h) \
{ \
kh_##name##_t *src = h; \
h = (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
h = R_Calloc(1, kh_##name##_t); \
*h = *src; /* Shallow copy struct. */ \
if(h->flags){ \
h->flags = (khint32_t*)kmalloc(__ac_fsize(src->n_buckets) * sizeof(khint32_t)); \
h->flags = R_Calloc(__ac_fsize(src->n_buckets), khint32_t); \
memcpy(h->flags, src->flags, __ac_fsize(src->n_buckets) * sizeof(khint32_t)); \
} \
if(h->keys){ \
h->keys = (khkey_t*)kmalloc(src->n_buckets * sizeof(khkey_t)); \
h->keys = R_Calloc(src->n_buckets, khkey_t); \
memcpy(h->keys, src->keys, src->n_buckets * sizeof(khkey_t)); \
} \
if(h->vals){ \
h->vals = (khval_t*)kmalloc(src->n_buckets * sizeof(khval_t)); \
h->vals = R_Calloc(src->n_buckets, khval_t); \
memcpy(h->vals, src->vals, src->n_buckets * sizeof(khval_t)); \
} \
return h; \
} \
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
{ \
if (h) { \
kfree((void *)h->keys); kfree(h->flags); \
kfree((void *)h->vals); \
kfree(h); \
R_Free(h->keys); R_Free(h->flags); \
R_Free(h->vals); \
R_Free(h); \
} \
} \
SCOPE void kh_clear_##name(kh_##name##_t *h) \
Expand Down Expand Up @@ -324,17 +312,12 @@ static const double __ac_HASH_UPPER = 0.77;
if (new_n_buckets < 4) new_n_buckets = 4; \
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
else { /* hash table size to be changed (shrink or expand); rehash */ \
new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (!new_flags) return -1; \
new_flags = R_Calloc(__ac_fsize(new_n_buckets), khint32_t); \
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
if (h->n_buckets < new_n_buckets) { /* expand */ \
khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
if (!new_keys) { kfree(new_flags); return -1; } \
h->keys = new_keys; \
h->keys = R_Realloc(h->keys, new_n_buckets, khkey_t); \
if (kh_is_map) { \
khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
if (!new_vals) { kfree(new_flags); return -1; } \
h->vals = new_vals; \
h->vals = R_Realloc(h->vals, new_n_buckets, khval_t); \
} \
} /* otherwise shrink */ \
} \
Expand Down Expand Up @@ -367,10 +350,10 @@ static const double __ac_HASH_UPPER = 0.77;
} \
} \
if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
h->keys = R_Realloc(h->keys, new_n_buckets, khkey_t); \
if (kh_is_map) h->vals = R_Realloc(h->vals, new_n_buckets, khval_t); \
} \
kfree(h->flags); /* free the working space */ \
R_Free(h->flags); /* free the working space */ \
h->flags = new_flags; \
h->n_buckets = new_n_buckets; \
h->mask = h->n_buckets - 1; \
Expand Down
8 changes: 4 additions & 4 deletions inst/include/ergm_nodelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ typedef struct {
} NodeList;

static inline NodeList *NodeListInitialize(int nnodes, int *nodepos) {
NodeList *nodelist = Calloc(1, NodeList);
nodelist->nodes = Calloc(nnodes + 1, Vertex);
NodeList *nodelist = R_Calloc(1, NodeList);
nodelist->nodes = R_Calloc(nnodes + 1, Vertex);
nodelist->nodepos = nodepos;
return nodelist;
}

static inline void NodeListDestroy(NodeList *nodelist) {
Free(nodelist->nodes);
Free(nodelist);
R_Free(nodelist->nodes);
R_Free(nodelist);
}

static inline void NodeListInsert(NodeList *nodelist, Vertex node) {
Expand Down
6 changes: 3 additions & 3 deletions inst/include/ergm_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// 2. Allocates a vector of `nmemb` elements of type `stored_type`.
// 3. Saves its pointer to private storage.
// 4. Also assigns its pointer to store_into.
#define ALLOC_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (STORAGE = Calloc(nmemb, stored_type));
#define ALLOC_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (STORAGE = R_Calloc(nmemb, stored_type));

// 1. Declares a stored_type *store_into.
// 2. Assigns pointer to private storage to store_into.
Expand All @@ -40,7 +40,7 @@
// 2. Allocates a vector of `nmemb` elements of type `stored_type`.
// 3. Saves its pointer to its assigned public storage slot.
// 4. Also assigns its pointer to store_into.
#define ALLOC_AUX_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (AUX_STORAGE = Calloc(nmemb, stored_type));
#define ALLOC_AUX_STORAGE(nmemb, stored_type, store_into) stored_type *store_into = (stored_type *) (AUX_STORAGE = R_Calloc(nmemb, stored_type));
// 1. Declares a stored_type *store_into.
// 2. Assigns pointer to its assigned auxiliary storage slot (or, for a statistic, its first requested auxiliary) to store_into.
#define GET_AUX_STORAGE(stored_type, store_into) stored_type *store_into = AUX_STORAGE;
Expand Down Expand Up @@ -75,7 +75,7 @@
store_into--; /* Shift the pointer array by -1. */ \
AUX_STORAGE = store_into; /* This is needed to make sure the pointer array itself is updated. */

/* Free a sociomatrix in auxiliary storage. */
/* R_Free a sociomatrix in auxiliary storage. */
/* If we hadn't shifted the pointers by -1, this would not have been
necessary. We need to shift the array back into place so that it's
automatically deallocated. */
Expand Down
Loading

0 comments on commit ac38cda

Please sign in to comment.