summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2012-11-03 01:26:03 -0700
committerJosh Blum2012-11-03 01:26:03 -0700
commitebfbb31868f4d6e0ff31ee97943cb446688809b7 (patch)
treea548ac51145b8856b3da4751e9329520d2dbef3d
parent89c99cbdbedda7536677cc5a1a32f5dbb3b3dcb4 (diff)
downloadsandhi-ebfbb31868f4d6e0ff31ee97943cb446688809b7.tar.gz
sandhi-ebfbb31868f4d6e0ff31ee97943cb446688809b7.tar.bz2
sandhi-ebfbb31868f4d6e0ff31ee97943cb446688809b7.zip
begin work on python blocks
-rw-r--r--CMakeLists.txt5
-rw-r--r--include/gras/io_signature.hpp8
-rw-r--r--python/gras/CMakeLists.txt6
-rw-r--r--python/gras/GRAS_Block.i59
-rw-r--r--python/gras/__init__.py5
-rw-r--r--python/gras/__init__.pycbin0 -> 352 bytes
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/block_test.py13
8 files changed, 96 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bb8574f..76c77c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -54,6 +54,11 @@ list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/python)
list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/python/gras)
list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/python/gras/${CMAKE_BUILD_TYPE})
+list(APPEND GRAS_PYTHON_DIRS ${GRAS_SOURCE_DIR}/PMC/python)
+list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/PMC/python)
+list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/PMC/python/PMC)
+list(APPEND GRAS_PYTHON_DIRS ${GRAS_BINARY_DIR}/PMC/python/PMC/${CMAKE_BUILD_TYPE})
+
########################################################################
# Add subdirectories
########################################################################
diff --git a/include/gras/io_signature.hpp b/include/gras/io_signature.hpp
index bb0df5f..75cb69b 100644
--- a/include/gras/io_signature.hpp
+++ b/include/gras/io_signature.hpp
@@ -51,6 +51,14 @@ struct IOSignature : std::vector<int>
this->set_max_streams(max_streams);
}
+ //! Create a signature from a vector of IO widths
+ IOSignature(const std::vector<int> &sig)
+ {
+ this->assign(sig.begin(), sig.end());
+ this->set_min_streams(this->size());
+ this->set_max_streams(this->size());
+ }
+
//! Construct from pointer for backwards compatible shared_ptr usage.
IOSignature(const IOSignature *sig)
{
diff --git a/python/gras/CMakeLists.txt b/python/gras/CMakeLists.txt
index 61e1ba5..334a6a5 100644
--- a/python/gras/CMakeLists.txt
+++ b/python/gras/CMakeLists.txt
@@ -17,10 +17,14 @@ list(APPEND GR_SWIG_INCLUDE_DIRS ${GRAS_INCLUDE_DIRS})
list(APPEND GR_SWIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
set(GR_SWIG_LIBRARIES gras)
+GR_SWIG_MAKE(GRAS_Block GRAS_Block.i)
GR_SWIG_MAKE(GRAS_HierBlock GRAS_HierBlock.i)
GR_SWIG_MAKE(GRAS_ThreadPool GRAS_ThreadPool.i)
GR_SWIG_INSTALL(
- TARGETS GRAS_HierBlock GRAS_ThreadPool
+ TARGETS
+ GRAS_Block
+ GRAS_HierBlock
+ GRAS_ThreadPool
DESTINATION ${GR_PYTHON_DIR}/gras
COMPONENT ${GRAS_COMP_PYTHON}
)
diff --git a/python/gras/GRAS_Block.i b/python/gras/GRAS_Block.i
new file mode 100644
index 0000000..b6d8fa9
--- /dev/null
+++ b/python/gras/GRAS_Block.i
@@ -0,0 +1,59 @@
+//
+// Copyright 2012 Josh Blum
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#define GRAS_API
+
+%module(directors="1") GRAS_Block
+
+%feature("director");
+
+%{
+#include <gras/block.hpp>
+%}
+
+%include <gras/io_signature.i>
+%include <gras/element.i>
+%include <gras/sbuffer.hpp>
+%include <gras/tags.hpp>
+%include <gras/block.hpp>
+%include <PMC/PMC.i>
+
+%pythoncode %{
+
+import numpy
+
+def sig_to_dtype_sig(sig):
+ if sig is None: sig = ()
+ return map(numpy.dtype, sig)
+
+class BlockPython(Block):
+ def __init__(self, name='Block', in_sig=None, out_sig=None):
+ Block.__init__(self, name)
+ self.set_input_signature(in_sig)
+ self.set_output_signature(in_sig)
+
+ def set_input_signature(self, sig):
+ self.__in_sig = sig_to_dtype_sig(sig)
+ Block.set_input_signature(self, IOSignature([s.itemsize for s in self.__in_sig]))
+
+ def set_output_signature(self, sig):
+ self.__out_sig = sig_to_dtype_sig(sig)
+ Block.set_output_signature(self, IOSignature([s.itemsize for s in self.__out_sig]))
+
+ def input_signature(self): return self.__in_sig
+ def output_signature(self): return self.__out_sig
+
+%}
diff --git a/python/gras/__init__.py b/python/gras/__init__.py
index 595efeb..869a361 100644
--- a/python/gras/__init__.py
+++ b/python/gras/__init__.py
@@ -1,2 +1,3 @@
-from GRAS_HierBlock import *
-from GRAS_ThreadPool import *
+from GRAS_Block import BlockPython as Block
+from GRAS_HierBlock import HierBlock, TopBlock
+from GRAS_ThreadPool import ThreadPoolConfig, ThreadPool
diff --git a/python/gras/__init__.pyc b/python/gras/__init__.pyc
new file mode 100644
index 0000000..a639e14
--- /dev/null
+++ b/python/gras/__init__.pyc
Binary files differ
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 695d71a..8dc44e4 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,5 +8,6 @@ include(GrPython)
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B})
set(GR_TEST_PYTHON_DIRS ${GRAS_PYTHON_DIRS})
-GR_ADD_TEST(hier_block ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/hier_block_test.py)
-GR_ADD_TEST(thread_pool ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/thread_pool_test.py)
+GR_ADD_TEST(block_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_test.py)
+GR_ADD_TEST(hier_block_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/hier_block_test.py)
+GR_ADD_TEST(thread_pool_test ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/thread_pool_test.py)
diff --git a/tests/block_test.py b/tests/block_test.py
new file mode 100644
index 0000000..9b53d1f
--- /dev/null
+++ b/tests/block_test.py
@@ -0,0 +1,13 @@
+
+import unittest
+import gras
+import numpy
+
+class BlockTest(unittest.TestCase):
+
+ def test_make_block(self):
+ b = gras.Block('FooBLock')
+ b.set_output_signature([numpy.int32])
+
+if __name__ == '__main__':
+ unittest.main()