blaze_tensor icon indicating copy to clipboard operation
blaze_tensor copied to clipboard

Add support for asterisk overloads

Open taless474 opened this issue 5 years ago • 0 comments

Using Blaze, the result of a matrix * vector is the same as their dot product:

blaze::DynamicVector<int> a{1, 1, 0};
blaze::DynamicMatrix<int> b{{1, 2, 3}, {-1, -2, -3}};
auto ans = b * a;

would results in

(           3 )
(          -3 )

Having a matrix * matrix is also results in their dot product:

blaze::DynamicMatrix<int> a{{1, 0}, {1, -1}, {2, -2}};
blaze::DynamicMatrix<int> b{{1, 2, 3}, {-1, -2, -3}};
auto ans = b * a;
(            9           -8 )
(           -9            8 )

That would be really useful to have the same overloads for a tensor. I think we need to add the equivalents of dot3d1d, dot3d2d and dot2d3d.

For example, for calculating tensor * vector (like in dot3d1d), the for loop in the following:

blaze::DynamicVector<int> a{1, 1, 0};
blaze::DynamicTensor<int> b{{{1, 2, 3}, {-1, -2, -3}},
                                              {{4, 5, 6}, {-4, -5, -6}}};
blaze::DynamicMatrix<int> ans(b.pages(), b.rows());

for (std::size_t i = 0; i != b.pages(); ++i)
     blaze::row(blaze::submatrix(ans, i, 0, 1, b.rows()), 0) =
         blaze::trans(blaze::pageslice(b, i) * a);

would results in the desired ans = b*a.

taless474 avatar May 02 '19 20:05 taless474