Caching Elements Inside a Matrix Trail

I have this grade to do as

D = trace (ABC)

A and C are constant matrices that do not change. B keeps changing. I want to find a way to store some values ​​from A and C, so I don’t need to calculate the ABC product all the time. B will change, and I just use some kind of B elements product with some cached version of AC or something like that.

I know trace (ABC) = trace (BCA), so I can pre-calculate the product CA, but the CA is very large, so it will not fit in memory. Therefore, I cannot do this. ABC turns out to be low-sized, so it’s good

C is of size 40000x10 and dense
B  of size 80000x40000 but B is sparse so it is fine
A is of size 10 by 80000 and dense

Any suggestions how I can do this efficiently?

+4
source share
1 answer

If you are thinking about the tr (ABC) element,

enter image description here

l = 10, n = 40,000, m = 80,000.

The number of multiplications above using sparseness Bis np * 10, where np is the number of nonzero elements B.

The number of pre-calculation CPU multiplications is 10 * 40,000 * 80,000. After that, using sparsity B, the number of multiplications tr (B (CA)) is np. Thus, if you do not do this calculation more than 1 / (density B) times, just tr (ABC) calculation is faster.

However, I do not think that a preliminary calculation of CA is necessary.

+2
source

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


All Articles