Ah, matrix maths! There’s been a few previous discussions on the topic. The summary is that pure Elixir code isn’t ideal for matrix maths. See this thread for more info: Matrix in Elixir
If possible, I’d recommend using the Matrex library (https://github.com/versilov/matrex) as probably the most complete matrix math library in elixir. There’s some alternatives that might be good for you in the other forum posting I linked to above.
Specifically in your code replace all of the matrix multiplications, transposes with the equivalent Matrex
functions. Also consider storing your matrix data in a binary format. Matrex supports the matlab binary format which should be exportable from Python, Matlab or others. The binary format should help speed up loading the data. One main limit of
Matrex` is that it only uses single precision floating points.
If you really want to use pure Elixir, look into parallelizing the matrix operations into sub-matrices using multiple GenServer’s or Tasks. Or look at the Matrax
library that uses OTP atomics to do matrix math: Matrax library - use :atomics as a matrix .