Package boxmin :: Package tests :: Module cfitfn
[hide private]

Source Code for Module boxmin.tests.cfitfn

 1  # This program is public domain. 
 2   
 3  ## \file 
 4  # \brief Helper functions and classes for a python fitting library 
 5  # 
 6   
 7  import boxmin._boxmin  as _boxmin 
 8  import numpy as nx 
 9   
10 -def dense(x):
11 """Force x to be a dense array""" 12 try: 13 if x.iscontiguous(): return x 14 finally: 15 return nx.array(x,'d')
16 17
18 -class cfitfn:
19 """Wrapper class to turn a pointer to a compiled C function and data 20 packet into a callable object."""
21 - def __call__(self,x):
22 return _boxmin.eval(self,dense(x))
23
24 - def __init__(self,generator, *args, **kw):
25 """cfitfn(pycfn_generator, args) 26 27 Return a callable object based on the supplied compiled C function generator""" 28 (self.cfitfn,self.cfitdata) = apply(generator,args,kw) 29 self.__doc__ = generator.__doc__
30
31 - def __repr__(self):
32 return self.__doc__
33