Yellow-Dog-Man / Resonite-Issues

Issue repository for Resonite.
https://resonite.com
121 stars 2 forks source link

Generalized Matrix Support #2404

Open lxw404 opened 1 week ago

lxw404 commented 1 week ago

Is your feature request related to a problem? Please describe.

Currently there is no way to form generic $M \times N$ matrices and we are stuck with a very limited set of predefined sizes. Virtually all scientific applications depend on generalized matrix math and Basic Linear Algebra Subprograms, a subset of which are mentioned here, which Resonite does not currently support.

Non-scientific applications stand to benefit as well from basic generalized matrices for simplifying/vectorizing equations of large numbers of variables into efficient operations.

Describe the solution you'd like

There should be a way in ProtoFlux to construct and utilize efficient generic-sized vectors, matrices, and possibly even N-dimensional arrays, which are optimized for use in math (separate from basic lists which do not have the same performance/usage considerations).

The first step towards this is a BLAS implementation of which there are many choices:

Describe alternatives you've considered

There is no viable alternative at the moment. Looping through pseudo slot-based matrices is extremely inefficient and does not scale, and doing the operations one by one becomes combinatorially explosive with larger matrix sizes.

Additional Context

This was brought about by a question on discord about performing ND projection into 3D which becomes explosively hard to manage by performing the operations one by one, and is very inefficient. This also is an extension to https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/773 and probably blocked by https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/572.

Requesters

LuxKitty mpmxyz murkythewolf auuser

ColinTimBarndt commented 1 week ago

This would be nice. Having generic matrix support would be even nicer (i.e., multiplying a matrix of vectors with a matrix of floats to get a new matrix of vectors, scalar × vec = vec). This can be used to implement all common curves and splines with their characteristic matrix.

Though I think this would make an implementation too slow by not using an optimized implementation for floats.

Frooxius commented 1 week ago

This is something I'd like to add. We'll probably adopt a good matrix library for this for generalized math operations.

There's a few questions with implementation though, notably - would these be supported as a primitive in a data model or require some sort of "serialization" (e.g. to an array)?

Native support would be easiest, but it makes the matrix behave essentially as a form of collection - its size can vary wildly. You could make a huge matrix that's million elements by million elements. This will require us to handle it in similar way and have some controls there.

The other part is how to access the elements - it would probably make most sense to generalize access to it and just treat it as collection in ProtoFlux (essentially two dimensional array or n-dimensional if it's even more generalized support) for mutations and so on - so it would likely require the collections as you mention.