-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFtensor.cpp
63 lines (52 loc) · 1.37 KB
/
Ftensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <Rcpp.h>
#include <iostream>
//#include <ofstream>
#include <fstream>
using namespace Rcpp;
using namespace std;
// [[Rcpp::export]]
void myMmult(NumericMatrix A, NumericMatrix B, double tol) {
int dim1 = A.nrow();
int dim2 = A.ncol();
int dim3 = B.nrow();
// int dim1 = 4;
// int dim2 = 4;
// int dim3 = 4;
// double array[50][50][50];
// NumericVector vec(dim1*dim2*dim3);
// List values;
// List paths;
double value;
NumericVector path(3);
ofstream myfile;
myfile.open("example.txt");
//int count = 0;
for(int i = 0; i < dim1; i++) {
for(int j = 0; j < dim2; j++) {
if(A(i,j) != 0) {
for(int k = 0; k < dim3; k++) {
//array[i][j][k] = A(i,j) * B(j,k);
value = A(i,j) * B(j,k);
if(value > tol) {
//vec(count) = A(i,j) * B(j,k);
path(0) = i+1; path(1) = j+1; path(2) = k+1;
myfile << path;
myfile << "\t";
myfile << value;
myfile << "\n";
// //result(count) = value;
// values.push_back(value);
// paths.push_back(path);
//count++;
} // endif
} // k
} // endif
} // j
} // i
myfile.close();
// List result;
// result["values"] = values;
// result["paths"] = paths;
// result["array"] = array;
// return NULL;
}