Missing "Const" attribute in xml

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
jnxd
Posts: 515
Joined: Mon Mar 30, 2015 2:30 pm

Re: Missing "Const" attribute in xml

Post by jnxd »

dpoen wrote: Wed Jun 22, 2022 10:07 pm
I kinda agree, but the main point is that we are dealing here with very small matrix (and with size being known)...
The sizes of the matrices involved is what is keeping me from bothering any further than bringing it up every so often :oops:. Also, ideal way would be to use libraries like lapack, or even numpy.linalg rather than reinventing the wheel.
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
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.

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.
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 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 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
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
Posts: 47
Joined: Wed Feb 02, 2022 10:26 pm

Re: Missing "Const" attribute in xml

Post by dpoen »

About using algebra library : I don't think it worth it, because we would have to create another interface to work with an external library, and very not sure if it worth it, here ... (I often an advocate to limit external dependencies)

Yes, not worries, do whatever is the most important for you, Coin is actually a way more important piece of software :)
jnxd
Posts: 515
Joined: Mon Mar 30, 2015 2:30 pm

Re: Missing "Const" attribute in xml

Post by jnxd »

dpoen wrote: Thu Jun 23, 2022 8:29 am About using algebra library : I don't think it worth it, because we would have to create another interface to work with an external library, and very not sure if it worth it, here ... (I often an advocate to limit external dependencies)
Pretty sure we are using certain linear algebra libraries, if not directly then through OCC and other dependencies. I don't think it's that tall an ask
Post Reply