Skip to content

Instantly share code, notes, and snippets.

@ghorn
ghorn / gist:6242691
Last active December 21, 2015 03:29
llvm AST checker
{-# OPTIONS_GHC -Wall #-}
module Main ( main ) where
import LLVM.General
import LLVM.General.Analysis
import LLVM.General.Context
import Control.Monad.Trans.Error
main :: IO ()
typedef callback_t .....; // callback function
int run_export(int numX, int numU, callback_t * ode, callback_t * ref, .........){
vector<DifferentialState> xvec;
vector<Control> uvec;
for (int k=0; k<numX; k++){
DifferentialState x;
xvec.push_back(x);
# result of symbolic differentaition
def f_sym(x):
f = exp(k*x)
fd = k*exp(k*x)
return (f,fd)
# result of AD
def f_ad(x):
f = exp(k*x)
fd = k*f
{-# OPTIONS_GHC -Wall #-}
{-# Language RankNTypes #-}
{-# Language DeriveFunctor #-}
{-# Language DeriveGeneric #-}
module Dyno.Nlp ( Nlp(..) ) where
import Dyno.Vectorize
import Dyno.TypeVecs
import Dyno.TypeNats
from casadi import *
##### lets integrate something 100 timesteps with 3 different methods #####
# this is whate we want to integrate
def dynamics_fun(x):
xdot = # some complicated shit
return xdot
## 1: inline everything, standard approach to AD afaik
def rk4(x0, h):
ghorn@adler:~$ cat .xsession
# .xsesssion
# nicer looking cursor
xsetroot -cursor_name left_ptr
# background image
xloadimage -onroot -fullscreen ~/Dropbox/desktop_backgrounds/trex_aviators.jpg
# key repeat delay to 250ms, repeat rate to 35Hz
ghorn@adler:~$ cat .xmonad/xmonad.hs
{-# OPTIONS_GHC -Wall #-}
module Main ( main ) where
import XMonad
import qualified XMonad.StackSet as SS
import XMonad.Util.EZConfig ( additionalKeys )
import XMonad.Prompt.Shell ( shellPrompt )
import XMonad.Prompt ( defaultXPConfig )
@ghorn
ghorn / ghc bug?
Created April 6, 2014 14:58
ghc bug?
-- put these two files in a directory and the compile with
-- ghc -fforce-recomp -O2 -prof -fprof-auto-calls Woo.hs
-- Vectorize.hs
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TypeOperators #-}
module Vectorize
( GVectorize(..)
-- multiple shooting
data MsPoint x u a = MsPoint (x a) (u a)
data MsTraj x u n a = MsTraj (Vec n (MsPoint x u a)) (x a)
from casadi import *
x0 = MX.sym('x',10,1);
u = MX.sym('u',10,1);
f = MXFunction([x0,u],[x0])
f.setOption('name','f')
f.init()
h = MX.sym('h',1,1);