Skip to content

Add support for asterisk overloads #24

@taless474

Description

@taless474

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions