Inner product between 2 matrices
edwardnguyen1705 opened this issue · comments
Dear @romeric ,
Thanks for sharing your work.
Let see the following pieces of code:
Tensor<float,2,3> m1 = {{1,1},{2,2}};
Tensor<float,2,3> m2 = {{3,3},{4,4}};
Tensor<float,2,2> m3 = inner(m1, m2);
I would like it produces: m3 = {{1*3+1*3, 1*4+1*4}, {2*3+2*3, 2*4+2*4}}
, but instead it produces: m3 = {{1*1+2*2+3*3 + 4*4+5*5+6*6, 1*1+2*2+3*3 + 4*4+5*5+6*6}, {1*1+2*2+3*3 + 4*4+5*5+6*6, 1*1+2*2+3*3 + 4*4+5*5+6*6}}
How would I change the code to get the desired the output?
Thanks for your time.
First of all, your tensor dimensions are incorrect, m1
and m2
should be 2x2
not 2x3
.
Second, you are not describing an inner product between two matrices. You still want the output matrix to be 2x2
which is not a reduction operation (inner) operation. This is a very specific operation and the closest you can get it without doing it manually using Fastor is:
Tensor<float,2,2> m1 = {{1,1},{2,2}};
Tensor<float,2,2> m2 = {{3,3},{4,4}};
Tensor<float,2,2> m3;
m3(0,0) = inner(m1(fix<0>,all), m2(fix<0>,all));
m3(0,1) = inner(m1(fix<0>,all), m2(fix<1>,all));
m3(1,0) = inner(m1(fix<1>,all), m2(fix<0>,all));
m3(1,1) = inner(m1(fix<1>,all), m2(fix<1>,all));