<s> import cffi <EOL> f = cffi . FFI ( ) <EOL> f . cdef ( """<STR_LIT>""" ) <EOL> l = f . dlopen ( "<STR_LIT>" ) <EOL> b = l . cpBodyNew ( <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> print b . m , b . p . x <EOL> b . p . x = <NUM_LIT> <EOL> print b . m , b . p . x <EOL> import timeit <EOL> import operator <EOL> import math <EOL> class Vec2d ( ) : <EOL> """<STR_LIT>""" <EOL> __slots__ = [ '<STR_LIT:x>' , '<STR_LIT:y>' ] <EOL> @ classmethod <EOL> def from_param ( cls , arg ) : <EOL> """<STR_LIT>""" <EOL> return cls ( arg ) <EOL> def getd ( self ) : <EOL> return { '<STR_LIT:x>' : self . x , '<STR_LIT:y>' : self . y } <EOL> def __init__ ( self , x_or_pair = None , y = None ) : <EOL> if x_or_pair != None : <EOL> if y == None : <EOL> self . x = x_or_pair [ <NUM_LIT:0> ] <EOL> self . y = x_or_pair [ <NUM_LIT:1> ] <EOL> else : <EOL> self . x = x_or_pair <EOL> self . y = y <EOL> def __getitem__ ( self , key ) : <EOL> if key == <NUM_LIT:0> : <EOL> return self . x <EOL> elif key == <NUM_LIT:1> : <EOL> return self . y <EOL> else : <EOL> raise IndexError ( "<STR_LIT>" + str ( key ) + "<STR_LIT>" ) <EOL> def __setitem__ ( self , key , value ) : <EOL> if key == <NUM_LIT:0> : <EOL> self . x = value <EOL> elif key == <NUM_LIT:1> : <EOL> self . y = value <EOL> else : <EOL> raise IndexError ( "<STR_LIT>" + str ( key ) + "<STR_LIT>" ) <EOL> def update ( self , * args , ** kwargs ) : <EOL> print '<STR_LIT>' , args , kwargs <EOL> for k , v in dict ( * args , ** kwargs ) . iteritems ( ) : <EOL> self [ k ] = v <EOL> def __add__ ( self , other ) : <EOL> if isinstance ( other , Vec2d ) : <EOL> return Vec2d ( self . x + other . x , self . y + other . y ) <EOL> elif hasattr ( other , "<STR_LIT>" ) : <EOL> return Vec2d ( self . x + other [ <NUM_LIT:0> ] , self . y + other [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return Vec2d ( self . x + other , self . y + other ) <EOL> __radd__ = __add__ <EOL> def __iadd__ ( self , other ) : <EOL> if isinstance ( other , Vec2d ) : <EOL> self . x += other . x <EOL> self . y += other . y <EOL> elif hasattr ( other , "<STR_LIT>" ) : <EOL> self . x += other [ <NUM_LIT:0> ] <EOL> self . y += other [ <NUM_LIT:1> ] <EOL> else : <EOL> self . x += other <EOL> self . y += other <EOL> return self <EOL> def __sub__ ( self , other ) : <EOL> if isinstance ( other , Vec2d ) : <EOL> return Vec2d ( self . x - other . x , self . y - other . y ) <EOL> elif ( hasattr ( other , "<STR_LIT>" ) ) : <EOL> return Vec2d ( self . x - other [ <NUM_LIT:0> ] , self . y - other [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return Vec2d ( self . x - other , self . y - other ) <EOL> def __rsub__ ( self , other ) : <EOL> if isinstance ( other , Vec2d ) : <EOL> return Vec2d ( other . x - self . x , other . y - self . y ) <EOL> if ( hasattr ( other , "<STR_LIT>" ) ) : <EOL> return Vec2d ( other [ <NUM_LIT:0> ] - self . x , other [ <NUM_LIT:1> ] - self . y ) <EOL> else : <EOL> return Vec2d ( other - self . x , other - self . y ) <EOL> def __isub__ ( self , other ) : <EOL> if isinstance ( other , Vec2d ) : <EOL> self . x -= other . x <EOL> self . y -= other . y <EOL> elif ( hasattr ( other , "<STR_LIT>" ) ) : <EOL> self . x -= other [ <NUM_LIT:0> ] <EOL> self . y -= other [ <NUM_LIT:1> ] <EOL> else : <EOL> self . x -= other <EOL> self . y -= other <EOL> return self <EOL> def cpvrotate ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return Vec2d ( self . x * other . x - self . y * other . y , self . x * other . y + self . y * other . x ) <EOL> def run ( ) : <EOL> b = l . cpBodyNew ( <NUM_LIT:15> , <NUM_LIT> ) <EOL> for x in range ( <NUM_LIT> ) : <EOL> s = <NUM_LIT:0> <EOL> for x in range ( <NUM_LIT:10> ) : <EOL> b . p = Vec2d ( <NUM_LIT:1> , <NUM_LIT:3> ) . getd ( ) <EOL> v1 = Vec2d ( b . p . x , b . p . y ) <EOL> v2 = Vec2d ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> b . p = ( v1 + v2 . cpvrotate ( v1 ) ) . getd ( ) <EOL> v3 = Vec2d ( b . p . x , b . p . y ) <EOL> s += v3 . x + v3 . y <EOL> def main ( ) : <EOL> t = timeit . Timer ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % t . timeit ( number = <NUM_LIT:1> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> doprof = <NUM_LIT:0> <EOL> if not doprof : <EOL> main ( ) <EOL> else : <EOL> import cProfile , pstats <EOL> prof = cProfile . run ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> stats = pstats . Stats ( "<STR_LIT>" ) <EOL> stats . strip_dirs ( ) <EOL> stats . sort_stats ( '<STR_LIT>' , '<STR_LIT:time>' , '<STR_LIT>' ) <EOL> stats . print_stats ( <NUM_LIT:30> ) </s>
