I have the following code:
static const int nx = 4;
static const int ny = 4;
static const int nz = 4;
Eigen::Tensor<double, 3> test((nz+1),nx,ny);
test.setZero(); //ttt1.setRandom();
for(int i = 0; i< nx; i++){
for(int j = 0; j< ny; j++){
for(int k = 0; k< nz+1; k++){
test(j + (nz+1)*i+k) = (i)*dx;
}
}
}
This code produces the following output:
0 1.5708 3.14159 4.71239 4.71239 0 0 0 0 0 0 0 0 0 0 0
0 1.5708 3.14159 4.71239 4.71239 0 0 0 0 0 0 0 0 0 0 0
0 1.5708 3.14159 4.71239 4.71239 0 0 0 0 0 0 0 0 0 0 0
0 1.5708 3.14159 4.71239 0 0 0 0 0 0 0 0 0 0 0 0
0 1.5708 3.14159 4.71239 0 0 0 0 0 0 0 0 0 0 0 0
which is sort of correct, but not fully initialize the tensor correctly this should be more like:
0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 ..
0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 ..
0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 ..
0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 ..
0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 0 1.5708 3.1416 4.7124 ..
Repeating in such a way that the tensor is a 5-by-4-by4. I am using tensor to reproduce 3D matrix from MATLAB, so I am new to tensor. Thanks.