Multiplication order of vector matrix can affect performance?

This is not the main question, but the main question. This is a calculation procedure related to performance, based on the associative property of matrix multiplication:A(BC)=(AB)C

If I have 2 matrices, Aand Bboth a vector vand I want to combine them in a certain order, for example ABv, I can do (AB)vor A(Bv).

It seems programmatic to me that I get better performance from much smaller calculations if I use the second method and always multiply the matrix with the vector.

For example, if we are dealing with 4x4 matrices:

AB leads to 16 individual calculations, a new matrix, each result is obtained from a point product

Matrix*vector leads to 4 calculations, each of a point product

In this way:

(AB)v - calculations 16 + 4 product points = 20

A(Bv) - two matrix-vector products or 4 + 4-point product calculations = 8

Am i thinking right? This suggests that executing many vector matrix expressions like this will significantly improve performance if I start with a vector every time?

Thus, it makes sense to structure the matrix library, which is based on the vector * matrix from left to right of the calculated order (even if you decide to designate right to left with column formatting), since vector multiplication with matrix products is very common in graphics.

+4
source share
2 answers

tmyklebu . , , , . , A B , v. A B ( ) v, AB , v.

, , , , AB, .

+4

, . - , .

+2

All Articles