Skip to content

Commit

Permalink
Modernized the Sum() operator, removing code left over from before th…
Browse files Browse the repository at this point in the history
…e move to .Call() and using the iinputs API.
  • Loading branch information
krivit committed Dec 22, 2024
1 parent edc27f1 commit 76500b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ergm
Version: 4.8.0-7022
Version: 4.8.0-7504
Date: 2024-12-22
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
Expand Down
4 changes: 1 addition & 3 deletions R/InitErgmTerm.operator.R
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ InitErgmTerm.Sum <- function(nw, arglist,...){
nparam <- nparams[1]

inputs <- unlist(wl%>%map(t))
inputs <- c(nf, length(inputs), inputs)


if(is.function(a$label)){
cns <- lapply(ms, param_names, canonical=TRUE)
Expand Down Expand Up @@ -770,7 +768,7 @@ InitErgmTerm.Sum <- function(nw, arglist,...){
}
}else offset <- FALSE

c(list(name="Sum", coef.names = coef.names, inputs=inputs, submodels=ms, emptynwstats=gs,
c(list(name="Sum", coef.names = coef.names, inputs=inputs, iinputs=nf, submodels=ms, emptynwstats=gs,
dependence=dependence, offset=offset,
ext.encode = if(ms %>% map("terms") %>% unlist(FALSE) %>% map("ext.encode") %>% compact %>% length)
function(el, nw0)
Expand Down
34 changes: 8 additions & 26 deletions src/changestats_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,7 @@ F_CHANGESTAT_FN(f__submodel_and_summary_term){
// Sum: Take a weighted sum of the models' statistics.

I_CHANGESTAT_FN(i_Sum){
/*
inputs expected:
1: number of models (nms)
1: total length of all weight matrices (tml)
tml: a list of mapping matrices in row-major order
*/

double *inputs = INPUT_PARAM;
unsigned int nms = *(inputs++);
unsigned int tml = *(inputs++);
inputs+=tml; // Jump to start of model specifications.

unsigned int nms = *IINPUT_PARAM;
ALLOC_STORAGE(nms, Model*, ms);

SEXP submodels = getListElement(mtp->R, "submodels");
Expand All @@ -200,11 +189,9 @@ I_CHANGESTAT_FN(i_Sum){
}

C_CHANGESTAT_FN(c_Sum){
double *inputs = INPUT_PARAM;
GET_STORAGE(Model*, ms);
unsigned int nms = *(inputs++);
inputs++; // Skip total length of weight matrices.
double *wts = inputs;
unsigned int nms = *IINPUT_PARAM;
double *wts = INPUT_PARAM;

for(unsigned int i=0; i<nms; i++){
Model *m = ms[i];
Expand All @@ -216,11 +203,9 @@ C_CHANGESTAT_FN(c_Sum){
}

Z_CHANGESTAT_FN(z_Sum){
double *inputs = INPUT_PARAM;
GET_STORAGE(Model*, ms);
unsigned int nms = *(inputs++);
inputs++; // Skip total length of weight matrices.
double *wts = inputs;
unsigned int nms = *IINPUT_PARAM;
double *wts = INPUT_PARAM;

for(unsigned int i=0; i<nms; i++){
Model *m = ms[i];
Expand All @@ -232,11 +217,9 @@ Z_CHANGESTAT_FN(z_Sum){
}

X_CHANGESTAT_FN(x_Sum){
double *inputs = INPUT_PARAM;
GET_STORAGE(Model*, ms);
unsigned int nms = *(inputs++);
inputs++; // Skip total length of weight matrices.
double *wts = inputs;
unsigned int nms = *IINPUT_PARAM;
double *wts = INPUT_PARAM;

for(unsigned int i=0; i<nms; i++){
Model *m = ms[i];
Expand All @@ -248,9 +231,8 @@ X_CHANGESTAT_FN(x_Sum){
}

F_CHANGESTAT_FN(f_Sum){
double *inputs = INPUT_PARAM;
GET_STORAGE(Model*, ms);
unsigned int nms = *(inputs++);
unsigned int nms = *IINPUT_PARAM;

for(unsigned int i=0; i<nms; i++){
ModelDestroy(nwp, ms[i]);
Expand Down
File renamed without changes.

0 comments on commit 76500b0

Please sign in to comment.