Page 1 of 1

micropython-mtx: Extra-fast Matrix Multiplication and Linear System Solver on MicroPython

Posted: Tue Jul 23, 2019 1:09 pm
by nickoala
Hello,

I want to announce micropython-mtx, a small MicroPython library designed to do two things only:

- multiply a matrix
- solve a system of linear equations

https://gitlab.com/nickoala/micropython-mtx

I was doing some planar homography on OpenMV Cam, wanting to find some libraries for simple matrix calculations. I was able to find two (previously announced on this forum):

viewtopic.php?t=1169
viewtopic.php?t=5160

But I found them too "heavy" for my purpose. They offer a numpy-like API which is good for manipulating, analyzing, and experimenting with data. In an embedded environment (in which MicroPython is expected to be used), usually we just want to apply some algorithms. In my case, I only need matrix multiplication and linear system solving. A lot of numpy-like functionalities, if I use those 2 libraries, become dead weight, using up memory and dragging down speed.

So, I decided to roll my own. The result is micropython-mtx. It is pure Python, simple to use, and fast. Hopefully it will be useful to someone.

Re: micropython-mtx: Extra-fast Matrix Multiplication and Linear System Solver on MicroPython

Posted: Tue Jul 23, 2019 9:02 pm
by OutoftheBOTS_
My 15yr old is currently studding Matrix in his Math methods class at school. We were going to write something simple like this in python on his PC then play with with transformations of a 2d box then transformations of a 3d cube to help him get his head around matrix.

The other 2 operations that would be super handy would be finding the deviation and the inverse.

Also there is a number of way of further increasing your speed by using viper mode and also loading range() as a local variable. Not sure if having it all in a class may also help with speed too. And have you looked at Micro-python Viper mode for speeding up micropython??

Re: micropython-mtx: Extra-fast Matrix Multiplication and Linear System Solver on MicroPython

Posted: Wed Jul 24, 2019 4:00 pm
by nickoala
If you are playing around on a PC, why not use numpy? It has everything you need.

I have tried to use the native code emitter on OpenMV, but have not been able to make it work.

I am also aware of the viper code emitter, but find it not worth the effort after my attempt at native has failed.

If anyone can make it work, I would be happy.

Re: micropython-mtx: Extra-fast Matrix Multiplication and Linear System Solver on MicroPython

Posted: Wed Jul 24, 2019 8:28 pm
by OutoftheBOTS_
nickoala wrote:
Wed Jul 24, 2019 4:00 pm
If you are playing around on a PC, why not use numpy? It has everything you need.

I have tried to use the native code emitter on OpenMV, but have not been able to make it work.

I am also aware of the viper code emitter, but find it not worth the effort after my attempt at native has failed.

If anyone can make it work, I would be happy.
I know that numpy already has all this but if I sit down with my son and we write our own code it will help him to understand what is happening.