|
[yoda-svn] r540 - in trunk/pyext/yoda: . includeblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Nov 15 18:26:10 GMT 2012
Author: davemallows Date: Thu Nov 15 18:26:09 2012 New Revision: 540 Log: Adding Cython mapping for Scatter2D::transformX/Y Modified: trunk/pyext/yoda/core.pyx trunk/pyext/yoda/declarations.pxd trunk/pyext/yoda/include/Scatter2D.pyx Modified: trunk/pyext/yoda/core.pyx ============================================================================== --- trunk/pyext/yoda/core.pyx Thu Nov 15 17:25:41 2012 (r539) +++ trunk/pyext/yoda/core.pyx Thu Nov 15 18:26:09 2012 (r540) @@ -6,6 +6,7 @@ from libcpp.vector cimport vector from libcpp.pair cimport pair from libcpp.map cimport map +import ctypes # Pure python imports from itertools import repeat, imap Modified: trunk/pyext/yoda/declarations.pxd ============================================================================== --- trunk/pyext/yoda/declarations.pxd Thu Nov 15 17:25:41 2012 (r539) +++ trunk/pyext/yoda/declarations.pxd Thu Nov 15 18:26:09 2012 (r540) @@ -11,7 +11,7 @@ void err "translate_yoda_error" () ctypedef map[string, string] Annotations - +ctypedef double (*dbl_dbl_fptr) (double) # Distributions @@ -514,6 +514,9 @@ Scatter2D combineWith(Scatter2D) Scatter2D combineWith(vector[Scatter2D]) + void Scatter2D_transformX "YODA::transformX" (Scatter2D&, dbl_dbl_fptr) + void Scatter2D_transformY "YODA::transformY" (Scatter2D&, dbl_dbl_fptr) + #}}} Scatter2D # Scatter3D {{{ Modified: trunk/pyext/yoda/include/Scatter2D.pyx ============================================================================== --- trunk/pyext/yoda/include/Scatter2D.pyx Thu Nov 15 17:25:41 2012 (r539) +++ trunk/pyext/yoda/include/Scatter2D.pyx Thu Nov 15 18:26:09 2012 (r540) @@ -1,5 +1,7 @@ #TODO: Tidy up + docstrings etc. +cdef object transform_functor = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double) + cdef class Scatter2D(AnalysisObject): """ 2D Scatter plot. @@ -66,3 +68,24 @@ self._Scatter2D().combineWith(deref(other._Scatter2D())) else: self._Scatter2D().combineWith(deref(other._Scatter2D())) + + + def transformX(self, f): + try: + callback = transform_functor(f) + except: + raise RuntimeError("Callback be of type (double) -> double") + + fptr = (<c.dbl_dbl_fptr*><size_t>ctypes.addressof(callback))[0] + + c.Scatter2D_transformX(deref(self._Scatter2D()), fptr) + + def transformY(self, f): + try: + callback = transform_functor(f) + except: + raise RuntimeError("Callback be of type (double) -> double") + + fptr = (<c.dbl_dbl_fptr*><size_t>ctypes.addressof(callback))[0] + + c.Scatter2D_transformY(deref(self._Scatter2D()), fptr)
More information about the yoda-svn mailing list |