pygae / clifford

Geometric Algebra for Python
http://clifford.rtfd.io
BSD 3-Clause "New" or "Revised" License
774 stars 72 forks source link

Implement numba extension support #97

Open hugohadfield opened 5 years ago

hugohadfield commented 5 years ago

Using the numba extension interface https://numba.pydata.org/numba-doc/latest/extending/interval-example.html We should be able to create a multivector type that numba understands and can work with directly. This would vastly improve the readability and quality of the jitted library code.

We should implement at least the operators:

moble commented 5 years ago

Note that the old documentation specifically discussed the overloads you'd want. But I suggest making sure such a thing is still possible before going too far down this road.

Numba also has jitclass, which is almost exactly what you'd want — except that despite having lots of people (e.g., me) bugging them for a long time to add these capabilities, jitclass still doesn't support the overloads you'd really want. I went through some of those issues toward the bottom of this wiki page. The jitclass interface is really nice, and much easier to use than the awkward low-level stuff in the interval example. And they have recently added __getitem__ and __setitem__ support, with suggestions that this new code will provide a nice way forward for the other overloads. So if you don't get around to this too soon, keep an eye on jitclass's support, because that would be a much nicer approach if it worked.

hugohadfield commented 5 years ago

@moble I just had a go at the extension interface and I gave to agree, it is very difficult to work out what to do, here is my attempt: https://gist.github.com/hugohadfield/d8dd24869288fa5e227c598a1440dff8 In the end it is both slower than the original clifford implementation and gives incorrect values for compound functions, so overall a bit of a flop... an interesting learning experience though...

moble commented 5 years ago

I'm impressed that it worked as well as it did, actually. As I mentioned, I've had good experiences with jitclass, especially in terms of simplicity, but also in terms of speed. I suspect that some of that stuff you had to do manually has been streamlined out of the process, so I can imagine it will be faster with jitclass. So there's still hope for the future.

eric-wieser commented 4 years ago

xref #189.

Note that one of the big challenges here is handling the Layout type. Essentially we have two options: