The sizes of the matrices involved is what is keeping me from bothering any further than bringing it up every so often . Also, ideal way would be to use libraries like lapack, or even numpy.linalg rather than reinventing the wheel.
Indeed if you want to solve for multiple (say m) vectors, inverting the matrix would I suppose take just n more operations (the number of solvings for the inverse itself.dpoen wrote: ↑Wed Jun 22, 2022 10:07 pm - About the speed of the operation :
Yes, there is a 3 time ratio between both way, but I often need to solve one given system for many inputs : example : if I when to change the origin of multiples points (lets says a mesh), I need to take the inverse matrix of the transform of the target origin, then multiply by all the point in my mesh to get the work done. At this point I'm way better off computing the inverse matrix once and multiply by all my point (granted, it's faster only if I have more than 3 point in my mesh, which is often the case)
Moreover, given the figure 2 in "Numerical experiments", if I look at the curve for n=4, I get only negligible value, so I'm not sure if it's worth it... Yes, 3 times faster is 3 times faster, but I mean FreeCAD is not aimed at inverting matrix, and other stuff will take significantly much more time...
- About the loss of accuracy :
Given the figure 3 in "Numerical experiments", if I look at the curve for n=4, the error doesn't seems to be such a big deal, IMHO
Do note the errors are drawn on linear scale so we can't just eyeball the statistics. We would want a semilog plot or maybe even tracking ratios.
I wouldn't be a bad thing for those functions to exist. But I still wonder if we can't just use linear algebra libraries directly for all this.dpoen wrote: ↑Wed Jun 22, 2022 10:07 pm - About our use case :
I do think (but I could be vastly wrong) that more often than not FreeCAD matrix are often transformation (rotation/translation...), and might be well invertible (ie well-conditioned) (but don't quote me on that). (and for my use case, I should replace the inversion of rotation matrix by transpose, but I'm too lazy now xD)
Having say that, it will not harm to add a matrix.solve(vector) method that will compute matrix.inverse()*vector, using the fast way
Whatever the conclusion is, invert() and inverse() should continue to exist, but should behave correctly, as described earlier !
That my 2cents !
I'll take a look, but I don't know if/when I'll be able to work on this. Right now I'm obsessed with trying to get Coin to work better for sketcher.dpoen wrote: ↑Wed Jun 22, 2022 10:07 pm PS: @jnxd I did start a work of cleaning up the https://github.com/FreeCAD/FreeCAD/blob ... Matrix.cpp file, which contains the code to inverse a matrix https://github.com/FreeCAD/FreeCAD/blob ... x.cpp#L492. But I'm not so confident to work on that part of the code... If you feel up the task, we might join forces
I've exposed my thought here : https://forum.freecadweb.org/viewtopic. ... 55#p568155 and the branch : https://github.com/ShuffleWire/FreeCAD/ ... ean_matrix