|
[yoda-svn] r388 - in trunk: . pyext pyext/yoda src testsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgSat Sep 3 00:44:17 BST 2011
Author: davemallows Date: Sat Sep 3 00:44:17 2011 New Revision: 388 Log: Changed to Cython and fixed parameter mix-up in ReaderAIDA Added: trunk/pyext/cyoda.pxd trunk/pyext/yoda.pyx Replaced: trunk/tests/test-yoda-1.py (contents, props changed) Deleted: trunk/pyext/yoda/ trunk/tests/test-yoda-2.py trunk/tests/test-yoda-3.py Modified: trunk/ChangeLog trunk/configure.ac trunk/pyext/Makefile.am trunk/pyext/setup.py.in trunk/src/ReaderAIDA.cc trunk/tests/Makefile.am Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Thu Sep 1 22:47:38 2011 (r387) +++ trunk/ChangeLog Sat Sep 3 00:44:17 2011 (r388) @@ -1,3 +1,17 @@ +2011-09-03 Dave Mallows <dave.mallows at gmail.com> + + * Fixed ReaderAIDA: x-value and low y-error interchanged when filling + Scatter2D. + + * Changed to Cython for Python bindings: Swig bindings were in need of + serious amounts of work. Cython should provide a means to provide more + Pythonic bindings to YODA. A minimal subset of ReaderAIDA, Scatter2D + and Point2D have been wrapped. + + * Modified configure.ac, Makefile.am and pyext/Makefile.am to reflect + change to Cython. Added cython.m4 from python-efl (Part of the + enlightenment project; LGPL) + 2011-08-31 Dave Mallows <dave.mallows at gmail.com> * Fixed python tests by installing python extension to pyext/build Modified: trunk/configure.ac ============================================================================== --- trunk/configure.ac Thu Sep 1 22:47:38 2011 (r387) +++ trunk/configure.ac Sat Sep 3 00:44:17 2011 (r388) @@ -71,47 +71,19 @@ enable_pyext=no fi fi -## SWIG checks + +## Cython checks (Probably need some help...) if test x$enable_pyext == xyes; then - AC_PROG_SWIG - if test x$SWIG == x; then - AC_MSG_ERROR([Can't build Python extension since swig could not be found]) + cython_required_version=0.13 + AM_CHECK_CYTHON([$cython_required_version], [:], [:]) + if test "x$CYTHON_FOUND" != "xyes"; then + AC_MSG_ERROR([Can't build Python extension since Cython >= 0.13 could not be found]) enable_pyext=no else - ## Test that SWIG makes a compilable source file... - ## cf. g++ 4.x requires that string literal is "_const_ char*" - cat > conftest.i <<EOL -%module conftest -%{ - void foo(); -%} -void foo(); -EOL - AC_MSG_CHECKING([if $SWIG can make a Python function wrapper]) - flag_ok=yes - stat_string=`$SWIG -c++ -python conftest.i 2>&1 1>&5` ; test -z "$stat_string" || flag_ok=no - AC_MSG_RESULT([$flag_ok]) - if test x$flag_ok != xyes; then - AC_MSG_ERROR([Can't build Python extension since $SWIG is not able to make a Python wrapper]) - enable_pyext=no - else - swig_compiler=$CXX - AC_CEDAR_CHECKCXXFLAG([-Wno-format], [AC_MSG_NOTICE([adding -Wno-format to swig compilation test]); - swig_compiler="$swig_compiler -Wno-format"]) - AC_MSG_CHECKING([if $SWIG is compatible with the $CXX compiler]) - flag_ok=yes - if test x$flag_ok == xyes; then - stat_string=`$swig_compiler -c conftest_wrap.cxx -I$python_incpath 2>&1 1>&5` ; test -z "$stat_string" || flag_ok=no - fi - AC_MSG_RESULT([$flag_ok]) - if test x$flag_ok != xyes; then - AC_MSG_ERROR([Can't build Python extension since $SWIG is not compatible with $CXX. Get a newer SWIG version!]) - enable_pyext=no - fi - fi + cython_compiler=$CXX fi - rm -rf conftest* fi + ## Finish if test x$enable_pyext == xyes; then AC_MSG_NOTICE([All Python build checks successful: 'yoda' Python extension will be built]) @@ -168,7 +140,7 @@ AC_CONFIG_FILES([include/Makefile include/YODA/Makefile]) AC_CONFIG_FILES([src/Makefile src/tinyxml/Makefile]) AC_CONFIG_FILES([tests/Makefile]) -AC_CONFIG_FILES([pyext/Makefile pyext/yoda/Makefile pyext/setup.py]) +AC_CONFIG_FILES([pyext/Makefile pyext/setup.py]) #AC_CONFIG_FILES([bin/Makefile bin/yoda-config]) AC_OUTPUT Modified: trunk/pyext/Makefile.am ============================================================================== --- trunk/pyext/Makefile.am Thu Sep 1 22:47:38 2011 (r387) +++ trunk/pyext/Makefile.am Sat Sep 3 00:44:17 2011 (r388) @@ -1,10 +1,13 @@ if ENABLE_PYEXT -SUBDIRS = yoda . +SUBDIRS = . +CYTHONFLAGS = @CYTHONFLAGS@ -all-local: yoda/yodawrap_wrap.cc +all-local: yoda.cc $(PYTHON) setup.py build $(PYTHON) setup.py install --install-lib=build/ +yoda.cc: + $(PYTHON) -m cython --cplus yoda.pyx install-exec-local: $(PYTHON) setup.py install --prefix=$(DESTDIR)$(prefix) Added: trunk/pyext/cyoda.pxd ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/cyoda.pxd Sat Sep 3 00:44:17 2011 (r388) @@ -0,0 +1,29 @@ +from libcpp.vector cimport vector +from libcpp.string cimport string +from libcpp.pair cimport pair + +cdef extern from "YODA/AnalysisObject.h" namespace "YODA": + cdef cppclass AnalysisObject: + string type() + +cdef extern from "YODA/Reader.h" namespace "YODA": + cdef cppclass Reader: + vector[AnalysisObject *] read(string filename) + +cdef extern from "YODA/Scatter2D.h" namespace "YODA": + cdef cppclass Scatter2D: + size_t numPoints() + vector[Point2D] points() + +cdef extern from "YODA/Point2D.h" namespace "YODA": + cdef cppclass Point2D: + Point2D(Point2D &p) + double x() + double y() + double xMin() + double xMax() + pair[double,double] xErrs() + pair[double,double] yErrs() + +cdef extern from "YODA/ReaderAIDA.h" namespace "YODA::ReaderAIDA": + Reader& create() Modified: trunk/pyext/setup.py.in ============================================================================== --- trunk/pyext/setup.py.in Thu Sep 1 22:47:38 2011 (r387) +++ trunk/pyext/setup.py.in Sat Sep 3 00:44:17 2011 (r388) @@ -3,28 +3,29 @@ ## Get setup tools from distutils.core import setup, Extension -"""A SWIG wrapper on the YODA (Yet more Objects for Data Analysis) data analysis +"""A Cython wrapper on the YODA (Yet more Objects for Data Analysis) data analysis library. All the functionality (histograms, profile histograms, scatter plots, and I/O) of YODA's C++ API are (or at least should be) provided for Python use via this module. """ - ## Extension definition import os incdir = os.path.abspath('@top_srcdir@/include') srcdir = os.path.abspath('@top_srcdir@/src') -ext = Extension('_yodawrap', - ['@srcdir@/yoda/yodawrap_wrap.cc'], - include_dirs=[incdir], - library_dirs=[srcdir, os.path.join(srcdir,'.libs')], - libraries=['YODA']) + +ext = Extension( + "yoda", + ["yoda.cpp"], + language='c++', + include_dirs=[incdir], + library_dirs=[srcdir, os.path.join(srcdir,'.libs')], + libraries=['stdc++','YODA'] +) ## Setup definition setup(name = 'YODA', version = '@PACKAGE_VERSION@', - ext_package = 'yoda', ext_modules = [ext], - py_modules = ['yoda.__init__', 'yoda.yodawrap'], author = ['Andy Buckley'], author_email = 'andy at insectnation.org', url = 'http://projects.hepforge.org/yoda/', Added: trunk/pyext/yoda.pyx ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/pyext/yoda.pyx Sat Sep 3 00:44:17 2011 (r388) @@ -0,0 +1,80 @@ +cimport cyoda +from libcpp.vector cimport vector +from libcpp.string cimport string +from libcpp.pair cimport pair + +cdef class AnalysisObject: + """Base object class""" + cdef cyoda.AnalysisObject *thisptr + + def type(self): + return self.thisptr.type().c_str() + +cdef class Point2D: + cdef cyoda.Point2D *thisptr + + @property + def x(self): + return self.thisptr.x() + + @property + def y(self): + return self.thisptr.y() + + @property + def xErrs(self): + cdef pair[double, double] xErrs = self.thisptr.xErrs() + return (xErrs.first, xErrs.second) + + @property + def yErrs(self): + cdef pair[double, double] yErrs = self.thisptr.yErrs() + return (yErrs.first, yErrs.second) + + def __repr__(self): + return 'Point2D({0},{1})'.format(self.x, self.y) + + +cdef class Scatter2D(AnalysisObject): + + @property + def numPoints(self): + return self.ptr().numPoints() + + cdef cyoda.Scatter2D * ptr(self): + return <cyoda.Scatter2D *> self.thisptr + + @property + def points(self): + cdef vector[cyoda.Point2D] vec + cdef int i + cdef cyoda.Point2D *p + vec = self.ptr().points() + out = [] + for i in range(vec.size()): + pt = Point2D() + p = new cyoda.Point2D(vec[i]) + pt.thisptr = p + out.append(pt) + + return out + +cdef class ReaderAIDA: + def read(self, char *filename): + cdef vector[cyoda.AnalysisObject *] vec + cdef int i + vec = cyoda.create().read(string(filename)) + out = [] + for i in range(vec.size()): + if str(vec[i].type().c_str()) == 'Scatter2D': + print (<cyoda.Scatter2D *> vec[i]).points().at(0).x(),\ + (<cyoda.Scatter2D *> vec[i]).points().at(0).y() + ana = Scatter2D() + else: + ana = AnalysisObject() + + ana.thisptr = vec[i] + + out.append(ana) + + return out Modified: trunk/src/ReaderAIDA.cc ============================================================================== --- trunk/src/ReaderAIDA.cc Thu Sep 1 22:47:38 2011 (r387) +++ trunk/src/ReaderAIDA.cc Sat Sep 3 00:44:17 2011 (r388) @@ -70,7 +70,7 @@ double xcentre, xerrplus, xerrminus, ycentre, yerrplus, yerrminus; xssC >> xcentre; xssP >> xerrplus; xssM >> xerrminus; yssC >> ycentre; yssP >> yerrplus; yssM >> yerrminus; - dps->addPoint(xcentre, xerrminus, xerrplus, ycentre, yerrminus, yerrplus); + dps->addPoint(xcentre, ycentre, xerrminus, xerrplus, yerrminus, yerrplus); } else { cerr << "Couldn't get <measurement> tag" << endl; /// @todo Throw an exception here? Modified: trunk/tests/Makefile.am ============================================================================== --- trunk/tests/Makefile.am Thu Sep 1 22:47:38 2011 (r387) +++ trunk/tests/Makefile.am Sat Sep 3 00:44:17 2011 (r388) @@ -74,4 +74,4 @@ testscatter2Dmodify\ testscatter3Dcreate\ testscatter3Dmodify\ - test-yoda-1.py test-yoda-2.py + test-yoda-1.py Added: trunk/tests/test-yoda-1.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/test-yoda-1.py Sat Sep 3 00:44:17 2011 (r388) @@ -0,0 +1,14 @@ +#! /usr/bin/env python + +import yoda +import unittest + +class TestReader(unittest.TestCase): + def setUp(self): + print "Set Up" + + def test_reader(self): + reader = yoda.ReaderAIDA() + +if __name__=='__main__': + unittest.main()
More information about the yoda-svn mailing list |