Skip to content

Commit 53d5fb6

Browse files
committed
In the *_*CHANGESTAT_CPP() helper marcros, swapped the StorageType argument and the implementation argument to put the short one first; and moved c_cylces to C++ as a test.
1 parent c2cd199 commit 53d5fb6

File tree

4 files changed

+135
-139
lines changed

4 files changed

+135
-139
lines changed

inst/include/cpp/ergm_changestat.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ template<typename StorageType = void>
2323
impl; \
2424
}
2525

26-
#define _C_CHANGESTAT_CPP_3(name, impl, StorageType) \
26+
#define _C_CHANGESTAT_CPP_3(name, StorageType, impl) \
2727
extern "C" void c_ ## name (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, int edgestate) { \
2828
ergm::ErgmCppNetwork nw(nwp); \
2929
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -40,7 +40,7 @@ template<typename StorageType = void>
4040
impl; \
4141
}
4242

43-
#define _S_CHANGESTAT_CPP_3(name, impl, StorageType) \
43+
#define _S_CHANGESTAT_CPP_3(name, StorageType, impl) \
4444
extern "C" void s_ ## name (ModelTerm *mtp, Network *nwp) { \
4545
ergm::ErgmCppNetwork nw(nwp); \
4646
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -57,7 +57,7 @@ template<typename StorageType = void>
5757
impl; \
5858
}
5959

60-
#define _D_CHANGESTAT_CPP_3(name, impl, StorageType) \
60+
#define _D_CHANGESTAT_CPP_3(name, StorageType, impl) \
6161
extern "C" void d_ ## name (Edge ntoggles, Vertex *tails, Vertex *heads, ModelTerm *mtp, Network *nwp) { \
6262
ergm::ErgmCppNetwork nw(nwp); \
6363
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -74,7 +74,7 @@ template<typename StorageType = void>
7474
impl; \
7575
}
7676

77-
#define _I_CHANGESTAT_CPP_3(name, impl, StorageType) \
77+
#define _I_CHANGESTAT_CPP_3(name, StorageType, impl) \
7878
extern "C" void i_ ## name (ModelTerm *mtp, Network *nwp) { \
7979
ergm::ErgmCppNetwork nw(nwp); \
8080
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -91,7 +91,7 @@ template<typename StorageType = void>
9191
impl; \
9292
}
9393

94-
#define _U_CHANGESTAT_CPP_3(name, impl, StorageType) \
94+
#define _U_CHANGESTAT_CPP_3(name, StorageType, impl) \
9595
extern "C" void u_ ## name (Vertex tail, Vertex head, ModelTerm *mtp, Network *nwp, Rboolean edgestate) { \
9696
ergm::ErgmCppNetwork nw(nwp); \
9797
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -108,7 +108,7 @@ template<typename StorageType = void>
108108
impl; \
109109
}
110110

111-
#define _F_CHANGESTAT_CPP_3(name, impl, StorageType) \
111+
#define _F_CHANGESTAT_CPP_3(name, StorageType, impl) \
112112
extern "C" void f_ ## name (ModelTerm *mtp, Network *nwp) { \
113113
ergm::ErgmCppNetwork nw(nwp); \
114114
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -125,7 +125,7 @@ template<typename StorageType = void>
125125
impl; \
126126
}
127127

128-
#define _W_CHANGESTAT_CPP_3(name, impl, StorageType) \
128+
#define _W_CHANGESTAT_CPP_3(name, StorageType, impl) \
129129
extern "C" SEXP w_ ## name (ModelTerm *mtp, Network *nwp) { \
130130
ergm::ErgmCppNetwork nw(nwp); \
131131
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -142,7 +142,7 @@ template<typename StorageType = void>
142142
impl; \
143143
}
144144

145-
#define _X_CHANGESTAT_CPP_3(name, impl, StorageType) \
145+
#define _X_CHANGESTAT_CPP_3(name, StorageType, impl) \
146146
extern "C" void x_ ## name (unsigned int type, void *data, ModelTerm *mtp, Network *nwp) { \
147147
ergm::ErgmCppNetwork nw(nwp); \
148148
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \
@@ -159,7 +159,7 @@ template<typename StorageType = void>
159159
impl; \
160160
}
161161

162-
#define _Z_CHANGESTAT_CPP_3(name, impl, StorageType) \
162+
#define _Z_CHANGESTAT_CPP_3(name, StorageType, impl) \
163163
extern "C" void z_ ## name (ModelTerm *mtp, Network *nwp, Rboolean skip_s) { \
164164
ergm::ErgmCppNetwork nw(nwp); \
165165
ergm::ErgmCppModelTerm<StorageType> mt(mtp); \

inst/include/cpp/ergm_wtchangestat.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ template<typename StorageType = void>
2323
impl; \
2424
}
2525

26-
#define _WtC_CHANGESTAT_CPP_3(name, impl, StorageType) \
26+
#define _WtC_CHANGESTAT_CPP_3(name, StorageType, impl) \
2727
extern "C" void c_ ## name (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate) { \
2828
ergm::ErgmCppWtNetwork nw(nwp); \
2929
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -40,7 +40,7 @@ template<typename StorageType = void>
4040
impl; \
4141
}
4242

43-
#define _WtS_CHANGESTAT_CPP_3(name, impl, StorageType) \
43+
#define _WtS_CHANGESTAT_CPP_3(name, StorageType, impl) \
4444
extern "C" void s_ ## name (WtModelTerm *mtp, WtNetwork *nwp) { \
4545
ergm::ErgmCppWtNetwork nw(nwp); \
4646
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -57,7 +57,7 @@ template<typename StorageType = void>
5757
impl; \
5858
}
5959

60-
#define _WtD_CHANGESTAT_CPP_3(name, impl, StorageType) \
60+
#define _WtD_CHANGESTAT_CPP_3(name, StorageType, impl) \
6161
extern "C" void d_ ## name (Edge ntoggles, Vertex *tails, Vertex *heads, double *weights, WtModelTerm *mtp, WtNetwork *nwp) { \
6262
ergm::ErgmCppWtNetwork nw(nwp); \
6363
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -74,7 +74,7 @@ template<typename StorageType = void>
7474
impl; \
7575
}
7676

77-
#define _WtI_CHANGESTAT_CPP_3(name, impl, StorageType) \
77+
#define _WtI_CHANGESTAT_CPP_3(name, StorageType, impl) \
7878
extern "C" void i_ ## name (WtModelTerm *mtp, WtNetwork *nwp) { \
7979
ergm::ErgmCppWtNetwork nw(nwp); \
8080
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -91,7 +91,7 @@ template<typename StorageType = void>
9191
impl; \
9292
}
9393

94-
#define _WtU_CHANGESTAT_CPP_3(name, impl, StorageType) \
94+
#define _WtU_CHANGESTAT_CPP_3(name, StorageType, impl) \
9595
extern "C" void u_ ## name (Vertex tail, Vertex head, double weight, WtModelTerm *mtp, WtNetwork *nwp, double edgestate) { \
9696
ergm::ErgmCppWtNetwork nw(nwp); \
9797
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -108,7 +108,7 @@ template<typename StorageType = void>
108108
impl; \
109109
}
110110

111-
#define _WtF_CHANGESTAT_CPP_3(name, impl, StorageType) \
111+
#define _WtF_CHANGESTAT_CPP_3(name, StorageType, impl) \
112112
extern "C" void f_ ## name (WtModelTerm *mtp, WtNetwork *nwp) { \
113113
ergm::ErgmCppWtNetwork nw(nwp); \
114114
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -125,7 +125,7 @@ template<typename StorageType = void>
125125
impl; \
126126
}
127127

128-
#define _WtW_CHANGESTAT_CPP_3(name, impl, StorageType) \
128+
#define _WtW_CHANGESTAT_CPP_3(name, StorageType, impl) \
129129
extern "C" SEXP w_ ## name (WtModelTerm *mtp, WtNetwork *nwp) { \
130130
ergm::ErgmCppWtNetwork nw(nwp); \
131131
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -142,7 +142,7 @@ template<typename StorageType = void>
142142
impl; \
143143
}
144144

145-
#define _WtX_CHANGESTAT_CPP_3(name, impl, StorageType) \
145+
#define _WtX_CHANGESTAT_CPP_3(name, StorageType, impl) \
146146
extern "C" void x_ ## name (unsigned int type, void *data, WtModelTerm *mtp, WtNetwork *nwp) { \
147147
ergm::ErgmCppWtNetwork nw(nwp); \
148148
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \
@@ -158,7 +158,7 @@ template<typename StorageType = void>
158158
impl; \
159159
}
160160

161-
#define _WtZ_CHANGESTAT_CPP_3(name, impl, StorageType) \
161+
#define _WtZ_CHANGESTAT_CPP_3(name, StorageType, impl) \
162162
extern "C" void z_ ## name (WtModelTerm *mtp, WtNetwork *nwp, Rboolean skip_s) { \
163163
ergm::ErgmCppWtNetwork nw(nwp); \
164164
ergm::ErgmCppWtModelTerm<StorageType> mt(mtp); \

src/changestats.c

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,127 +1146,6 @@ C_CHANGESTAT_FN(c_ctriple) {
11461146
}
11471147
}
11481148

1149-
/*****************
1150-
changestat: d_cycle
1151-
*****************/
1152-
void edgewise_path_recurse(Network *nwp, Vertex dest, Vertex curnode,
1153-
int *visited, Vertex curlen, int *countv, Vertex maxlen, Rboolean semi);
1154-
void edgewise_cycle_census(Network *nwp, Vertex tail, Vertex head,
1155-
int *countv, Vertex maxlen, Rboolean semi);
1156-
1157-
I_CHANGESTAT_FN(i_cycle) {
1158-
ALLOC_STORAGE(IINPUT_PARAM[1]*2, int, dummy);
1159-
(void)(dummy); // Suppress unused warning.
1160-
}
1161-
1162-
C_CHANGESTAT_FN(c_cycle) {
1163-
GET_STORAGE(int, countv);
1164-
int emult;
1165-
1166-
/*Perform initial setup*/
1167-
Rboolean semi = (Rboolean) (IINPUT_PARAM[0]); /*Are we using semicycles?*/
1168-
Vertex maxlen = (Vertex) (IINPUT_PARAM[1]); /*Get max cycle length*/
1169-
1170-
/* *** don't forget tail -> head */
1171-
/*Clear out the count vector*/
1172-
memset(countv, 0, sizeof(*countv)*(maxlen-1));
1173-
/*In semi-cycle case, this toggle can't matter if there is a*/
1174-
/*head->tail edge in the graph; not counting saves much time.*/
1175-
if(!(semi&&(IS_OUTEDGE(head,tail)))){
1176-
/*Count the cycles associated with this edge*/
1177-
edgewise_cycle_census(nwp,tail,head,countv,maxlen,semi);
1178-
1179-
/*Make the change, as needed*/
1180-
if((!DIRECTED)&&(tail>head))
1181-
emult = IS_OUTEDGE(head, tail) ? -1 : 1;
1182-
else
1183-
emult = edgestate ? -1 : 1;
1184-
for(unsigned int j=0, k=0; j<maxlen-1;j++)
1185-
if(IINPUT_PARAM[2+j]>0)
1186-
CHANGE_STAT[k++]+=emult*countv[j];
1187-
}
1188-
}
1189-
1190-
/*****************
1191-
edgewise_path_recurse: Called by d_cycle
1192-
*****************/
1193-
void edgewise_path_recurse(Network *nwp, Vertex dest, Vertex curnode,
1194-
int *visited, Vertex curlen, int *countv, Vertex maxlen, Rboolean semi) {
1195-
Vertex v;
1196-
Edge e;
1197-
1198-
/*If we've found a path to the destination, increment the census vector*/
1199-
if(DIRECTED){ /*Use outedges, or both if counting semi-paths*/
1200-
if(!semi)
1201-
countv[curlen] += IS_OUTEDGE(curnode, dest);
1202-
else
1203-
countv[curlen] += (IS_OUTEDGE(curnode, dest) || IS_INEDGE(curnode, dest));
1204-
}else{ /*For undirected graphs, edges go from low to high*/
1205-
if(curnode<dest)
1206-
countv[curlen] += IS_OUTEDGE(curnode, dest);
1207-
else
1208-
countv[curlen] += IS_INEDGE(curnode, dest);
1209-
}
1210-
1211-
/*If possible, keep searching for novel paths*/
1212-
if(curlen<maxlen-2){
1213-
visited[curlen+1]=curnode; /*Add current node to visited list*/
1214-
1215-
/*Recurse on all unvisited neighbors of curnode*/
1216-
STEP_THROUGH_OUTEDGES(curnode,e,v){
1217-
Rboolean rflag = TRUE;
1218-
for(Vertex i=0;(i<=curlen)&&(rflag);i++) /*Check earlier nodes in path*/
1219-
rflag=(v!=visited[i]);
1220-
if(rflag)
1221-
edgewise_path_recurse(nwp,dest,v,visited,curlen+1,countv,maxlen, semi);
1222-
}
1223-
if(semi||(!DIRECTED)){ /*If semi or !directed, need in-neighbors too*/
1224-
STEP_THROUGH_INEDGES(curnode,e,v){
1225-
Rboolean rflag = ((!DIRECTED)||(!(IS_OUTEDGE(curnode,v))));
1226-
for(Vertex i=0;(i<=curlen)&&(rflag);i++) /*Check earlier nodes in path*/
1227-
rflag=(v!=visited[i]);
1228-
if(rflag)
1229-
edgewise_path_recurse(nwp,dest,v,visited,curlen+1,countv,maxlen, semi);
1230-
}
1231-
}
1232-
}
1233-
}
1234-
1235-
/*****************
1236-
edgewise_cycle_census: Called by d_cycle
1237-
*****************/
1238-
void edgewise_cycle_census(Network *nwp, Vertex tail, Vertex head,
1239-
int *countv, Vertex maxlen, Rboolean semi) {
1240-
/* *** don't forget tail -> head */
1241-
int *visited;
1242-
Vertex v;
1243-
Edge e;
1244-
1245-
/*First, check for a 2-cycle (but only if directed and !semi)*/
1246-
if(DIRECTED && (!semi) && IS_OUTEDGE(head,tail))
1247-
countv[0]++;
1248-
if(N_NODES == 2)
1249-
return; /*Failsafe for graphs of order 2*/
1250-
1251-
/*Perform the recursive path count*/
1252-
visited=countv + maxlen; /*Locate the list of visited nodes*/
1253-
memset(visited, 0, sizeof(*visited)*maxlen);
1254-
visited[0]=tail;
1255-
visited[1]=head;
1256-
1257-
/*Recurse on each neighbor of head*/
1258-
STEP_THROUGH_OUTEDGES(head,e,v){
1259-
if(v!=tail)
1260-
edgewise_path_recurse(nwp,tail,v,visited,1,countv,maxlen,semi);
1261-
}
1262-
if(semi||(!DIRECTED)){ /*If semi or !directed, need in-neighbors too*/
1263-
STEP_THROUGH_INEDGES(head,e,v){
1264-
if((v!=tail)&&((!DIRECTED)||(!(IS_OUTEDGE(head,v)))))
1265-
edgewise_path_recurse(nwp,tail,v,visited,1,countv,maxlen, semi);
1266-
}
1267-
}
1268-
}
1269-
12701149
/******************** changestats: D ***********/
12711150
/*****************
12721151
changestat: d_degcor

0 commit comments

Comments
 (0)