Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
#include <RcppArmadillo.h> |
|
2 |
|
|
3 |
using namespace Rcpp; |
|
4 |
using namespace arma; |
|
5 |
|
|
6 |
// [[Rcpp::depends(RcppArmadillo)]]
|
|
7 |
// [[Rcpp::export]]
|
|
8 |
|
|
9 | 1 |
arma::imat matdom(NumericMatrix A, bool map, bool benefit) { |
10 | 1 |
arma::mat B=as<arma::mat>(A); |
11 | 1 |
int n=B.n_rows; |
12 |
// int m=B.n_cols;
|
|
13 |
bool status; |
|
14 | 1 |
arma::mat Asort(n,n,fill::zeros); |
15 | 1 |
arma::imat dom(n,n,fill::zeros); |
16 | 1 |
arma::rowvec tmpi(n); |
17 | 1 |
arma::rowvec tmpj(n); |
18 | 1 |
arma::rowvec check(n); |
19 | 1 |
if(map){ |
20 | 1 |
Asort=arma::sort(B,"descend",1); |
21 |
}
|
|
22 | 1 |
int c=1; |
23 | 1 |
if(!benefit){ |
24 | 1 |
c=-1; |
25 |
}
|
|
26 | 1 |
for(int i = 0; i < n; ++i) { |
27 | 1 |
for(int j = 0; j < n; ++j) { |
28 | 1 |
if(i!=j){ |
29 | 1 |
if(!map){ |
30 | 1 |
tmpi=c*B.row(i); |
31 | 1 |
tmpj=c*B.row(j); |
32 | 1 |
tmpi[i]=c; |
33 | 1 |
tmpi[j]=c; |
34 | 1 |
tmpj[i]=c; |
35 | 1 |
tmpj[j]=c; |
36 | 1 |
check=tmpi-tmpj; |
37 | 1 |
status = arma::all(check<=0); |
38 | 1 |
if(status){ |
39 | 1 |
dom(i,j)=1; |
40 |
}
|
|
41 |
} else{ |
|
42 | 1 |
tmpi=c*Asort.row(i); |
43 | 1 |
tmpj=c*Asort.row(j); |
44 | 1 |
check=tmpi-tmpj; |
45 | 1 |
status = arma::all(check<=0); |
46 | 1 |
if(status){ |
47 | 1 |
dom(i,j)=1; |
48 |
}
|
|
49 |
}
|
|
50 |
|
|
51 |
}
|
|
52 |
}
|
|
53 |
}
|
|
54 | 1 |
return dom; |
55 |
}
|
Read our documentation on viewing source code .