The fastest transpose-match method

Given the matrices A and P, I need to calculate the "transposed conjugation" (not sure what the term is)

X = P A Transpose(P)

I thought the fastest way would be

for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
            for(int k=0;k<n;k++)
                    for(int l=0;l<n;l++) X[i][j]+=P[i][l]*A[l][k]*P[j][k];
            }
      }
}

However, this is O (n ^ 4), and I could also do it as two regular matrix multiplications, so twice O (n ^ 3). I have missed something here or should stick to two multiplications.

X = A Transpose(P)
X = P X
+4
source share
1 answer

, : , ​​ Eigen. , , O (n ^ 3), , .

, , , , . .

, , . Matrix_chain_multiplication. . . A 10 × 30, B 30 × 5, C 5 × 60. ,

(AB)C = (10×30×5) + (10×5×60) = 1500 + 3000 = 4500 operations
A(BC) = (30×5×60) + (10×30×60) = 9000 + 18000 = 27000 operations. 

( ), .

CPU, , SIMD, , , . , , -, Eigen.

+3

Source: https://habr.com/ru/post/1620508/


All Articles