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

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
nickoala
Posts: 2
Joined: Tue Jul 23, 2019 12:13 pm

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

Post by nickoala » Tue Jul 23, 2019 1:09 pm

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.

OutoftheBOTS_
Posts: 626
Joined: Mon Nov 20, 2017 10:18 am

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

Post by OutoftheBOTS_ » Tue Jul 23, 2019 9:02 pm

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??

nickoala
Posts: 2
Joined: Tue Jul 23, 2019 12:13 pm

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

Post by nickoala » 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.

OutoftheBOTS_
Posts: 626
Joined: Mon Nov 20, 2017 10:18 am

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

Post by OutoftheBOTS_ » Wed Jul 24, 2019 8:28 pm

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.

Post Reply