ALGLBRAIC!
May 22, 2022 ยท View on GitHub
A python library and CLI utility for generating libraries of algebraic GLSL functions.
Featuring included generators:
complex-numbersdual-numbersquaternionsclifford-algebras
Examples of generated GLSL code can be found in the examples/ directory.
CLI usage examples
Quaternions
> algl quaternions
Output to a directory
> algl --out ./glsl/ clifford-algebra cga2d '1 1 1 -1'
A more complex example
In this example we use the complex-numbers and clifford-algebra generators together
in sequence to generate functions for a Clifford algebra with the complex numbers as its
base ring:
> algl --glslify --out ./glsl/ complex-numbers clifford-algebra --base C GAComplex '1 1 1 -1'
The --base option passed to the clifford-algebra generator specifies that the base struct
for this Clifford algebra should be C, the name of the struct outputted by complex-numbers.
The --glslify option passed at the beginning creates an index.glsl file with
glslify-import directives for importing all of the
generated glslify files in the order they were generated.
CLI help
Use the --help option!
> algl --help
> algl <COMMAND> --help
You might be wondering...
What about other algebras?
I made alglbraic with geometric algebra in mind but the underlying library is flexible
enough to generate GLSL code for any algebra you can get SymPy to print. If you're
interested in other algebras I recommend reading the code in alglbraic/algebras.
What about performance?
The code generated by this library is not optimized in any special way! It just bakes out all of the math into GLSL code. If you find it to be quick that's only because it's running on the GPU and everything is happening in parallel.
Big algebras?
This tool probably isn't a good fit for generic computations of operations for algebras with more than 32 or maybe 64 basis dimensions.
Development
To get started you'll need to install Poetry.
Install dependencies
> poetry shell
followed by
> poetry install
Tests
> pytest
or:
> ptw
Updating snapshots
If you change something in a way that breaks the snapshots, the only way I've found to update them
is by carefully deleting the snapshot file for the thing that's changed and re-running pytest.