This forum has been archived. All content is frozen. Please use KDE Discuss instead.

huge amount of multiplications

Tags: None
(comma "," separated)
Martijnvdc
Registered Member
Posts
2
Karma
0
OS

huge amount of multiplications

Sun Aug 29, 2010 7:00 pm
hello,
i'm trying to multiply a matrix with a huge amount of vectors.
the following code shows basically what i'm doing right now:

Code: Select all
bool CalculateVectors()
{
Matrix3f m;
Vector3f **A;Vector3f **B; Vector3f **C;
unsigned int Amount=1000000;
// make A,B and C 2D array's of vectors here ...
// set the values for the matrix and vectors here ...
   unsigned int i=0;unsigned int j=0;
   while(i<rows)
   {
      while(j<columns)
      {
      A[i][j]=m*B[i][j];
      C[i][j]=A[i][j].reverse().normalized();
      j++;
      }
   i++; j=0;
   }

return true;
}


this method works, and does what i want it to do, but i would love to see it go faster.
is there a way to multiply all vectors with the matrix at once, without looping through all the vectors individually? maybe i could get some performance boost there?
The amount of vectors could sometimes be 16 million, so i will probably still have to do it in multiple steps :)

sorry for my English
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: huge amount of multiplications

Tue Aug 31, 2010 7:21 am
Hi,

yes you can store your (rows * columns) vectors into a 3 x (rows * columns) matrix and simply do:

Matrix<float, 3, Dynamic> A, B, C;
// ...
A = m * B;
C = A.colwise().reverse().normalized();

Then your "A[i][j]" become "A.col(i+j*rows)". You could wrap this into a function returning a Matrix<float, 3, Dynamic>::ColXpr object.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]