Skip to content

Commit

Permalink
The MH proposal C API apparently did not make available the lengths o…
Browse files Browse the repository at this point in the history
…f the input vectors as the change statistics API did.
  • Loading branch information
krivit committed Dec 22, 2024
1 parent 76500b0 commit 6724034
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
9 changes: 7 additions & 2 deletions inst/include/ergm_MHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ typedef struct MHProposalstruct {
Vertex *togglehead;
double logratio;
int status;
double *inputs; /* may be used if needed, ignored if not. */
int *iinputs; /* may be used if needed, ignored if not. */
int ninputs;
double *inputs;
int niinputs;
int *iinputs;
void *storage;
void **aux_storage;
unsigned int n_aux;
Expand All @@ -79,8 +81,11 @@ MHProposal *MHProposalInitialize(SEXP pR, Network *nwp, void **aux_storage);
void MHProposalDestroy(MHProposal *MHp, Network *nwp);

/* Helper macros */
#define MH_N_DINPUTS MHp->ninputs
#define MH_DINPUTS MHp->inputs
#define MH_N_INPUTS MH_N_DINPUTS
#define MH_INPUTS MH_DINPUTS
#define MH_N_IINPUTS MHp->niinputs
#define MH_IINPUTS MHp->iinputs

#define Mtail (MHp->toggletail)
Expand Down
9 changes: 7 additions & 2 deletions inst/include/ergm_wtMHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ typedef struct WtMHProposalstruct {
double *toggleweight;
double logratio;
int status;
double *inputs; /* may be used if needed, ignored if not. */
int *iinputs; /* may be used if needed, ignored if not. */
int ninputs;
double *inputs;
int niinputs;
int *iinputs;
void *storage;
void **aux_storage;
unsigned int n_aux;
Expand All @@ -79,8 +81,11 @@ WtMHProposal *WtMHProposalInitialize(SEXP pR, WtNetwork *nwp, void **aux_storage
void WtMHProposalDestroy(WtMHProposal *MH, WtNetwork *nwp);

/* Helper macros */
#define MH_N_DINPUTS MHp->ninputs
#define MH_DINPUTS MHp->inputs
#define MH_N_INPUTS MH_N_DINPUTS
#define MH_INPUTS MH_DINPUTS
#define MH_N_IINPUTS MHp->niinputs
#define MH_IINPUTS MHp->iinputs

#define Mtail (MHp->toggletail)
Expand Down
6 changes: 4 additions & 2 deletions src/MHproposal.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ MHProposal *MHProposalInitialize(SEXP pR, Network *nwp, void **aux_storage){
MHp->x_func=(void (*)(unsigned int, void *, MHProposal*, Network*)) R_FindSymbol(fn,sn,NULL);

SEXP tmp = getListElement(pR, "inputs");
MHp->inputs=length(tmp) ? REAL(tmp) : NULL;
MHp->ninputs = length(tmp);
MHp->inputs = MHp->ninputs ? REAL(tmp) : NULL;
tmp = getListElement(pR, "iinputs");
MHp->iinputs=length(tmp) ? INTEGER(tmp) : NULL;
MHp->niinputs = length(tmp);
MHp->iinputs = MHp->niinputs ? INTEGER(tmp) : NULL;

/*Clean up by freeing sn and fn*/
R_Free(fn);
Expand Down
6 changes: 4 additions & 2 deletions src/wtMHproposal.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ WtMHProposal *WtMHProposalInitialize(SEXP pR, WtNetwork *nwp, void **aux_storage
MHp->x_func=(void (*)(unsigned int, void *, WtMHProposal*, WtNetwork*)) R_FindSymbol(fn,sn,NULL);

SEXP tmp = getListElement(pR, "inputs");
MHp->inputs=length(tmp) ? REAL(tmp) : NULL;
MHp->ninputs = length(tmp);
MHp->inputs = MHp->ninputs ? REAL(tmp) : NULL;
tmp = getListElement(pR, "iinputs");
MHp->iinputs=length(tmp) ? INTEGER(tmp) : NULL;
MHp->niinputs = length(tmp);
MHp->iinputs = MHp->niinputs ? INTEGER(tmp) : NULL;

/*Clean up by freeing sn and fn*/
R_Free(fn);
Expand Down

0 comments on commit 6724034

Please sign in to comment.