summaryrefslogtreecommitdiff
path: root/volk/python
diff options
context:
space:
mode:
authorTom Rondeau2010-12-07 18:50:28 -0500
committerTom Rondeau2010-12-07 18:50:28 -0500
commit239144659b29c0a5ecd83a34e0e57387a1060ed7 (patch)
tree3476e1c123da4696c64cc1756ddec5d971bcf9f2 /volk/python
parente13783aeb84a2c3656c3344a8d52fa2c9ee38a00 (diff)
downloadgnuradio-239144659b29c0a5ecd83a34e0e57387a1060ed7.tar.gz
gnuradio-239144659b29c0a5ecd83a34e0e57387a1060ed7.tar.bz2
gnuradio-239144659b29c0a5ecd83a34e0e57387a1060ed7.zip
Initial checkin for VOLK - Vector-Optimized Library of Kernels. This is a new SIMD library.
It currently stands by itself under the GNU Radio tree and can be used separately. We will integrate the build process into GNU Raio and start building off of its functionality over time.
Diffstat (limited to 'volk/python')
-rw-r--r--volk/python/Makefile.am95
-rw-r--r--volk/python/__init__.py53
-rw-r--r--volk/python/libvector.i47
-rw-r--r--volk/python/libvector_square_ff.i37
-rwxr-xr-xvolk/python/qa_square.py47
-rw-r--r--volk/python/run_tests.in50
6 files changed, 329 insertions, 0 deletions
diff --git a/volk/python/Makefile.am b/volk/python/Makefile.am
new file mode 100644
index 000000000..8485c4793
--- /dev/null
+++ b/volk/python/Makefile.am
@@ -0,0 +1,95 @@
+#
+# Copyright 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS)
+SWIGPYTHONARGS = $(SWIGPYTHONFLAGS) $(SWIGGRFLAGS)
+
+BUILT_SOURCES = $(swig_built_sources)
+
+MOSTLYCLEANFILES = $(BUILT_SOURCES) *.pyc
+
+# Don't distribute the output of swig
+dist-hook:
+ @for file in $(swig_built_sources); do echo $(RM) $(distdir)/$$file; done
+ @for file in $(swig_built_sources); do $(RM) $(distdir)/$$file; done
+
+
+# if we're not using python, ignore the rest...
+
+TESTS =
+
+
+ALL_IFILES = \
+ $(LOCAL_IFILES) \
+ $(NON_LOCAL_IFILES)
+
+NON_LOCAL_IFILES = \
+ $(GNURADIO_CORE_INCLUDEDIR)/swig/gnuradio.i
+
+LOCAL_IFILES = \
+ libvector.i \
+ libvector_square_ff.i
+
+
+# These files are built by SWIG. The first is the C++ glue.
+# The second is the python wrapper that loads the _libvector shared library
+# and knows how to call our extensions.
+
+swig_built_sources = \
+ libvector_swig.cc \
+ libvector_swig.py
+
+# This gets libvector.py installed in the right place.
+# Any hand-written python should be listed here too.
+ourpython_PYTHON = \
+ __init__.py \
+ libvector_swig.py
+
+# Python QA code gets listed here. It's not installed.
+noinst_PYTHON =
+
+# This library contains the swig generated glue
+ourpyexec_LTLIBRARIES = _libvector_swig.la
+
+# These are the source files that go into the shared library
+_libvector_swig_la_SOURCES = \
+ libvector_swig.cc
+
+# Dummy C++ source to cause C++ linking
+nodist_EXTRA__libvector_swig_la_SOURCES = dummy.cc
+
+# magic flags
+_libvector_swig_la_LDFLAGS = $(NO_UNDEFINED) -module -avoid-version
+
+# Link the swig generated code against our library and some python magic.
+_libvector_swig_la_LIBADD = \
+ ../lib/liblibvector.la \
+ $(PYTHON_LDFLAGS)
+
+
+libvector_swig.cc libvector_swig.py: $(LOCAL_IFILES) $(ALL_IFILES)
+ $(SWIG) $(SWIGPYTHONARGS) -module libvector_swig -o libvector_swig.cc $(srcdir)/libvector.i
+
+
+# These swig headers get installed in ${prefix}/include/<component>/swig
+ourswiginclude_HEADERS = \
+ $(LOCAL_IFILES)
diff --git a/volk/python/__init__.py b/volk/python/__init__.py
new file mode 100644
index 000000000..6513a31dd
--- /dev/null
+++ b/volk/python/__init__.py
@@ -0,0 +1,53 @@
+#
+# Copyright 2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+# The presence of this file turns this directory into a Python package
+
+# ----------------------------------------------------------------
+# Temporary workaround for ticket:181 (swig+python problem)
+import sys
+_RTLD_GLOBAL = 0
+try:
+ from dl import RTLD_GLOBAL as _RTLD_GLOBAL
+except ImportError:
+ try:
+ from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL
+ except ImportError:
+ pass
+
+if _RTLD_GLOBAL != 0:
+ _dlopenflags = sys.getdlopenflags()
+ sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL)
+# ----------------------------------------------------------------
+
+
+# import swig generated symbols into the libvector namespace
+from libvector_swig import *
+
+# import any pure python here
+# from libvector_foo import bar
+# from libvector_baz import *
+
+
+# ----------------------------------------------------------------
+# Tail of workaround
+if _RTLD_GLOBAL != 0:
+ sys.setdlopenflags(_dlopenflags) # Restore original flags
+# ----------------------------------------------------------------
diff --git a/volk/python/libvector.i b/volk/python/libvector.i
new file mode 100644
index 000000000..598c20a2a
--- /dev/null
+++ b/volk/python/libvector.i
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+%feature("autodoc", "1"); // generate python docstrings
+
+%include "exception.i"
+%import "gnuradio.i" // the common stuff
+
+%{
+#include "gnuradio_swig_bug_workaround.h" // mandatory bug fix
+#include <stdexcept>
+%}
+
+// ----------------------------------------------------------------
+
+/*
+ * Gather all .i files in this directory together.
+ */
+
+%{
+
+// The .h files
+#include <libvector/libvector_square_ff.h>
+
+%}
+
+// The .i files
+%include <libvector_square_ff.i>
+
diff --git a/volk/python/libvector_square_ff.i b/volk/python/libvector_square_ff.i
new file mode 100644
index 000000000..a1c547cc7
--- /dev/null
+++ b/volk/python/libvector_square_ff.i
@@ -0,0 +1,37 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * First arg is the package prefix.
+ * Second arg is the name of the class minus the prefix.
+ *
+ * This does some behind-the-scenes magic so we can
+ * access gr_example_square_ff from python as howto.square_ff
+ */
+GR_SWIG_BLOCK_MAGIC(libvector,square_ff);
+
+libvector_square_ff_sptr libvector_make_square_ff ();
+
+class libvector_square_ff : public gr_sync_block
+{
+private:
+ libvector_square_ff();
+};
diff --git a/volk/python/qa_square.py b/volk/python/qa_square.py
new file mode 100755
index 000000000..1ee56411f
--- /dev/null
+++ b/volk/python/qa_square.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,2008 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest
+import libvector_swig as libvector
+
+class qa_libvector(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001_square_ff(self):
+ src_data = (-3, 4, -5.5, 2, 3)
+ expected_result = (9, 16, 30.25, 4, 9)
+ src = gr.vector_source_f(src_data)
+ sqr = libvector.square_ff()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, sqr)
+ self.tb.connect(sqr, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
+
+if __name__ == '__main__':
+ gr_unittest.main()
diff --git a/volk/python/run_tests.in b/volk/python/run_tests.in
new file mode 100644
index 000000000..895a849bd
--- /dev/null
+++ b/volk/python/run_tests.in
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# All this strange PYTHONPATH manipulation is required to run our
+# tests using our just built shared library and swig-generated python
+# code prior to installation.
+
+# build tree == src tree unless you're doing a VPATH build.
+# If you don't know what a VPATH build is, you're not doing one. Relax...
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+# Where to look in the build tree for our shared library
+libbld=@abs_top_builddir@/python
+# Where to look in the src tree for swig generated python code
+libsrc=@abs_top_builddir@/python
+# Where to look in the src tree for hand written python code
+py=@abs_top_srcdir@/python
+
+# Where to look for installed GNU Radio python modules
+# FIXME this is wrong on a distcheck. We really need to ask gnuradio-core
+# where it put its python files.
+installed_pythondir=@pythondir@
+installed_pyexecdir=@pyexecdir@
+
+PYTHONPATH="$libbld:$libbld/.libs:$libsrc:$py:$installed_pythondir:$installed_pyexecdir:$PYTHONPATH"
+#PYTHONPATH="$libbld:$libbld/.libs:$libsrc:$py:$installed_pythondir:$installed_pyexecdir"
+
+export PYTHONPATH
+
+#
+# This is the simple part...
+# Run everything that matches qa_*.py and return the final result.
+#
+
+ok=yes
+for file in @srcdir@/qa_*.py
+do
+ if ! $file
+ then
+ ok=no
+ fi
+done
+
+if [ $ok = yes ]
+then
+ exit 0
+else
+ exit 1
+fi