matrix and vector multiplication

Hi, i am trying to do multiplication of matrix and vector using block_prod( ) boost library in my code but i'am not able use it properly. can anyone link me to an example for block_prod( ) multiplication of matrix and vector.
Currently i am stuck with this line in my code

w = block_prod<matrix<double>,1024>(A ,v);

here w and v are boost vectors and A is a boost matrix. But i get an error as no operator "=" matches these operands.

I am already using prod( ) function from boost but it is taking more time so i need to use block_prod( ) function. Any help regarding this topic would be greatly appreciated.
Thank you.
Maybe you forgot to #include a needed header?
as best as I can tell from the web at a glance block_prod is a matrix multiplier, that may accept vectors, but it appears to return a matrix, not a vector. I dunno if you can cast it back or if its overloaded or what; but check the function, its return type, overloads, and the error message ... see if its trying to make a matrix from a vector etc.

for a matrix-vector you may find that your own is faster than theirs, depending...
Last edited on
Thank you for you response.
@coder777 (7493) I have added all header files. It works fine with prod( ) of same library. According to boost documentation, block_prod( ) is the optimized function for dense matrix multiplication so trying to implement it.
Thank you for your response,
@jonnin (5820)
I tried my own implementation but it takes a lot of time. Prod( ) is taking a little less time. But according to boost documentation block_prod( ) would be more optimized one.
what you have said is correct, block_prod( ) is returning matrix so I am not able to store it in vector. But according to boost documentation , the output should be in vector.
I wanted to know whether block_prod( ) can be used for matrix and vector multiplication, if it can what am I doing wrong?
@malibor
Thank you for your response .
But that is for matrix and matrix multiplication, which works fine .
I am trying for matrix and vector multiplication.
so the multiplication works in boost code, but problem is that return type is matrix instead of vector?

well, either write a helper function that converts matrix to vector array. it really depends on how you want or need data to be stored in an array.
surely boost version doesn't return vector because matrix isn't plain array, it's either multiple arrays or multidimensional array or it stores matrix elements somehow else..

But that is for matrix and matrix multiplication

so what, it still serves as example, rewrite the sample for loop code to multiply vector and matrix instead of 2 matrices.

if boost does not provide what you want then what are you going to do?

using array as a storage for matrix is error prone too, because you need to keep track of how data in vector is stored, is it 2x2, 3x3, or 4x5? how would you know these things?

also, what does such result represent anyway? it's the same as mutiplying 2 vectors, that is you lose matrix information. that's why boost library return matrix instead of vector which makes no mathematical sense.
Last edited on
my advice, take it or leave it, is to consider getting rid of any use of a vector object at all. just have Nx1 or 1XN matrix objects. Its more flexible. If you HAVE to use the vectors, then you need to provide a way to cast a matrix to a vector and a vector to a matrix. It would be mind-blowing if this did not already exist!

The optimized matrix multiply is pretty involved and is for 2-d matrix multiply. I can't imagine what needs to be optimized for a vector version; you could multi thread it but if the size is too small that would spend more time making threads than it would doing the work. We can bounce some ideas, what *exactly* are you trying to do here? Are these things huge? Tiny? Something else? Just because you wrote it and it was slower does not mean much, if you are not pretty strong at optimizing your code.
Last edited on
Thank you all for you help, will try manual way.
Topic archived. No new replies allowed.