schochastics / signnet
1
#include <RcppArmadillo.h>
2
// [[Rcpp::depends(RcppArmadillo)]]
3
using namespace Rcpp;
4

5

6
// [[Rcpp::export]]
7 0
IntegerVector triadCensusSign(NumericMatrix A, int n)
8
{
9

10 0
  int code = 0;
11 0
  IntegerVector triads(729);
12

13 0
  for (int u = 0; u < n; ++u)
14
  {
15 0
    for (int v = 0; v < n; ++v)
16
    {
17 0
      for (int w = 0; w < n; ++w)
18
      {
19 0
        if ((u < v) & (v < w))
20
        {
21 0
          code = A(u, v) + 3 * A(u, w) + 9 * A(v, u) + 27 * A(v, w) + 81 * A(w, u) + 243 * A(w, v);
22 0
          triads[code] = triads[code] + 1;
23
        }
24
      }
25
    }
26
  }
27 0
  return triads;
28
}
29

30
// [[Rcpp::export]]
31 1
DoubleVector triadCensusSign1(const arma::sp_mat &A, List adj, int n)
32
{
33 1
  long long code = 0;
34 1
  DoubleVector triads(729);
35 1
  for (int u = 0; u < n; u++)
36
  {
37 1
    IntegerVector Nu = as<IntegerVector>(adj[u]);
38 1
    int nu = Nu.length();
39 1
    for (int j = 0; j < nu; j++)
40
    {
41 1
      int v = Nu[j];
42 1
      if (u < v)
43
      {
44 1
        IntegerVector Nv = as<IntegerVector>(adj[v]);
45 1
        IntegerVector S = union_(Nu, Nv);
46 1
        IntegerVector uv = {u, v};
47 1
        S = setdiff(S, uv);
48 1
        code = (A(u, v) + 1) + 3 + 9 * (A(v, u) + 1) + 27 + 81 + 243;
49 1
        triads[code] = triads[code] + n - S.length() - 2;
50 1
        for (int k = 0; k < S.length(); k++)
51
        {
52 1
          int w = S[k];
53 1
          if ((v < w) | ((u < w) & (w < v) & (A(u, w) == 0) & (A(w, u) == 0)))
54
          {
55 1
            code = (A(u, v) + 1) + 3 * (A(u, w) + 1) + 9 * (A(v, u) + 1) + 27 * (A(v, w) + 1) + 81 * (A(w, u) + 1) + 243 * (A(w, v) + 1);
56 1
            triads[code] = triads[code] + 1;
57
          }
58
        }
59
      }
60
    }
61
  }
62 1
  return triads;
63
}
64

Read our documentation on viewing source code .

Loading