Code Monkey home page Code Monkey logo

gajit's Introduction

gajit

A JIT compiler for geometric algebra in python

Using Gaalop and numba this package symbolically optimises geomteric algebra algorithms, generates numpy code and JITs the resultant code. Currently only supports Cl(4,1), still very experimental and hacky. Currently produces around an order of magnitude speed up for normally written algorithms and around 2-4x speed up over hand optimised code. Many further optimisations are possible that so far have not been implemented, Pull Requests welcomed.

Example usage

The package comes in the form of a decorator that can be applied to normal functions written with the clifford GA syntax. Grade masks can be specified as arguements this is highly recommended for both run and compile time speedups verbosity of the JIT process can be adjusted for debugging:

from gajit import *
from clifford.g3c import *

@gajit(mask_list=[layout.grade_mask(1), layout.grade_mask(3)], verbose=1)
def pp_algo_wrapped(P, C):
    Cplane = C ^ einf
    Cd = C * (Cplane)
    L = (Cplane * P * Cplane) ^ Cd ^ einf
    pp = Cd ^ (L * e12345)
    return pp

def pp_algo(P, C):
    Cplane = C ^ einf
    Cd = C * (Cplane)
    L = (Cplane * P * Cplane) ^ Cd ^ einf
    pp = Cd ^ (L * e12345)
    return pp

The jitted function can be called as normal and much faster than the original

from clifford.tools.g3c import *
import time

P = random_conformal_point()
C = random_circle()

print( pp_algo_wrapped(P, C) )
print( pp_algo(P, C) )
   
start_time = time.time()
for i in range(10000):
    pp_algo_wrapped(P, C)
t_gaalop = time.time() - start_time
print('gaJIT ALGO: ', t_gaalop)

start_time = time.time()
for i in range(10000):
    pp_algo(P, C)
t_trad = time.time() - start_time
print('TRADITIONAL: ', t_trad)

print('T/G: ', t_trad / t_gaalop)

Getting Gaalop

This requires Gaalop to be compiled in command line interface (cli) mode, instructions on setting this up are on the TODO list

TODO

  • Describe the Gaalop CLI setup and environment variables
  • Provide a pip installable setup.py
  • Host on pypi
  • Implement more transpilation of CLUSCRIPT language features
  • Implement a non-mapped metric for speed + simplicity
  • Implement a proper codegen cache system
  • Add a blade mask inference option

gajit's People

Contributors

hugohadfield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.