From 76500b01c2482126edf9dfcc19aee790448db0e8 Mon Sep 17 00:00:00 2001
From: "Pavel N. Krivitsky"
Date: Sun, 22 Dec 2024 22:25:54 +1100
Subject: [PATCH] Modernized the Sum() operator, removing code left over from
before the move to .Call() and using the iinputs API.
---
DESCRIPTION | 2 +-
R/InitErgmTerm.operator.R | 4 +--
src/changestats_operator.c | 34 +++++--------------
.../testthat/{test-Sum.R => test-term-Sum.R} | 0
4 files changed, 10 insertions(+), 30 deletions(-)
rename tests/testthat/{test-Sum.R => test-term-Sum.R} (100%)
diff --git a/DESCRIPTION b/DESCRIPTION
index 3767c9e7a..aea9d0ce3 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -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(
diff --git a/R/InitErgmTerm.operator.R b/R/InitErgmTerm.operator.R
index aab9d9498..126668234 100644
--- a/R/InitErgmTerm.operator.R
+++ b/R/InitErgmTerm.operator.R
@@ -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)
@@ -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)
diff --git a/src/changestats_operator.c b/src/changestats_operator.c
index 36503f4da..bb02a7a4e 100644
--- a/src/changestats_operator.c
+++ b/src/changestats_operator.c
@@ -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");
@@ -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