From 8d5801f8689337669e282595e5c44b4a83b1980a Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Mon, 27 Jun 2016 08:29:26 -0400 Subject: [PATCH 1/2] Add CI using CMake builds. --- .travis.yml | 20 +++++++++++++++ libs/numpy/doc/tutorial/dtype.rst | 28 ++++++++++---------- libs/numpy/doc/tutorial/fromdata.rst | 16 ++++++------ libs/numpy/doc/tutorial/ndarray.rst | 16 ++++++------ libs/numpy/doc/tutorial/simple.rst | 38 ++++++++++++++-------------- libs/numpy/test/runCmakeTest.sh.in | 2 +- 6 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d5add9b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +sudo: required +dist: trusty +language: cpp + +before_install: + - export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g") + - sudo apt-get -qq update + - sudo apt-get install -y libboost-python-dev python-numpy python3-numpy libpython3-dev python-sphinx + - sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python-py34.so /usr/lib/x86_64-linux-gnu/libboost_python3.so + +script: + - mkdir build + - cd build + - cmake -DPYTHON_EXECUTABLE=$PYTHON .. && make && make test ARGS="-V" + - cd ../libs/numpy/doc + - make html + +env: + - PYTHON=/usr/bin/python + - PYTHON=/usr/bin/python3 diff --git a/libs/numpy/doc/tutorial/dtype.rst b/libs/numpy/doc/tutorial/dtype.rst index 02bb513..c604b31 100644 --- a/libs/numpy/doc/tutorial/dtype.rst +++ b/libs/numpy/doc/tutorial/dtype.rst @@ -5,32 +5,32 @@ Here is a brief tutorial to show how to create ndarrays with built-in python dat Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module:: - #include - #include + #include + #include - namespace p = boost::python; - namespace np = boost::numpy; + namespace p = boost::python; + namespace np = boost::numpy; - int main(int argc, char **argv) - { - Py_Initialize(); - np::initialize(); + int main(int argc, char **argv) + { + Py_Initialize(); + np::initialize(); Next, we create the shape and dtype. We use the get_builtin method to get the numpy dtype corresponding to the builtin C++ dtype Here, we will create a 3x3 array passing a tuple with (3,3) for the size, and double as the data type :: - p::tuple shape = p::make_tuple(3, 3); - np::dtype dtype = np::dtype::get_builtin(); - np::ndarray a = np::zeros(shape, dtype); + p::tuple shape = p::make_tuple(3, 3); + np::dtype dtype = np::dtype::get_builtin(); + np::ndarray a = np::zeros(shape, dtype); Finally, we can print the array using the extract method in the python namespace. Here, we first convert the variable into a string, and then extract it as a C++ character array from the python string using the template :: - std::cout << "Original array:\n" << p::extract(p::str(a)) << std::endl; + std::cout << "Original array:\n" << p::extract(p::str(a)) << std::endl; We can also print the dtypes of the data members of the ndarray by using the get_dtype method for the ndarray :: - std::cout << "Datatype is:\n" << p::extract(p::str(a.get_dtype())) << std::endl ; + std::cout << "Datatype is:\n" << p::extract(p::str(a.get_dtype())) << std::endl ; We can also create custom dtypes and build ndarrays with the custom dtypes @@ -52,4 +52,4 @@ We are now ready to create an ndarray with dimensions specified by \*shape\* and np::ndarray new_array = np::zeros(shape,custom_dtype); - } + } diff --git a/libs/numpy/doc/tutorial/fromdata.rst b/libs/numpy/doc/tutorial/fromdata.rst index d2e59fa..993d5e4 100644 --- a/libs/numpy/doc/tutorial/fromdata.rst +++ b/libs/numpy/doc/tutorial/fromdata.rst @@ -6,16 +6,16 @@ The from_data method makes this possible. Like before, first get the necessary headers, setup the namespaces and initialize the Python runtime and numpy module:: - #include - #include + #include + #include - namespace p = boost::python; - namespace np = boost::numpy; + namespace p = boost::python; + namespace np = boost::numpy; - int main(int argc, char **argv) - { - Py_Initialize(); - np::initialize(); + int main(int argc, char **argv) + { + Py_Initialize(); + np::initialize(); Create an array in C++ , and pass the pointer to it to the from_data method to create an ndarray:: diff --git a/libs/numpy/doc/tutorial/ndarray.rst b/libs/numpy/doc/tutorial/ndarray.rst index 02e732c..a2aea58 100644 --- a/libs/numpy/doc/tutorial/ndarray.rst +++ b/libs/numpy/doc/tutorial/ndarray.rst @@ -8,16 +8,16 @@ This tutorial will introduce you to some of the ways in which you can create nda First, as before, initialise the necessary namepaces and runtimes :: - #include - #include + #include + #include - namespace p = boost::python; - namespace np = boost::numpy; + namespace p = boost::python; + namespace np = boost::numpy; - int main(int argc, char **argv) - { - Py_Initialize(); - np::initialize(); + int main(int argc, char **argv) + { + Py_Initialize(); + np::initialize(); Let's now create an ndarray from a simple tuple. We first create a tuple object, and then pass it to the array method, to generate the necessary tuple :: diff --git a/libs/numpy/doc/tutorial/simple.rst b/libs/numpy/doc/tutorial/simple.rst index 3c46296..f56a831 100644 --- a/libs/numpy/doc/tutorial/simple.rst +++ b/libs/numpy/doc/tutorial/simple.rst @@ -5,37 +5,37 @@ Let's start with a simple tutorial to create and modify arrays. Get the necessary headers for numpy components and set up necessary namespaces:: - #include - #include + #include + #include - namespace p = boost::python; - namespace np = boost::numpy; + namespace p = boost::python; + namespace np = boost::numpy; Initialise the Python runtime, and the numpy module. Failure to call these results in segmentation errors:: - int main(int argc, char **argv) - { - Py_Initialize(); - np::initialize(); + int main(int argc, char **argv) + { + Py_Initialize(); + np::initialize(); Zero filled n-dimensional arrays can be created using the shape and data-type of the array as a parameter. Here, the shape is 3x3 and the datatype is the built-in float type:: - p::tuple shape = p::make_tuple(3, 3); - np::dtype dtype = np::dtype::get_builtin(); - np::ndarray a = np::zeros(shape, dtype); + p::tuple shape = p::make_tuple(3, 3); + np::dtype dtype = np::dtype::get_builtin(); + np::ndarray a = np::zeros(shape, dtype); You can also create an empty array like this :: - np::ndarray b = np::empty(shape,dtype); - + np::ndarray b = np::empty(shape,dtype); + Print the original and reshaped array. The array a which is a list is first converted to a string, and each value in the list is extracted using extract< >:: - std::cout << "Original array:\n" << p::extract(p::str(a)) << std::endl; + std::cout << "Original array:\n" << p::extract(p::str(a)) << std::endl; - // Reshape the array into a 1D array - a = a.reshape(p::make_tuple(9)); - // Print it again. - std::cout << "Reshaped array:\n" << p::extract(p::str(a)) << std::endl; - } + // Reshape the array into a 1D array + a = a.reshape(p::make_tuple(9)); + // Print it again. + std::cout << "Reshaped array:\n" << p::extract(p::str(a)) << std::endl; + } diff --git a/libs/numpy/test/runCmakeTest.sh.in b/libs/numpy/test/runCmakeTest.sh.in index efaa756..4ce2966 100755 --- a/libs/numpy/test/runCmakeTest.sh.in +++ b/libs/numpy/test/runCmakeTest.sh.in @@ -1,3 +1,3 @@ #!/bin/bash export PYTHONPATH=@CMAKE_LIBRARY_OUTPUT_DIRECTORY@:${PYTHONPATH} -python $1 \ No newline at end of file +@PYTHON_EXECUTABLE@ $1 From 4b14f7731c8cccd63a41adecd95642a302ccca3b Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Mon, 27 Jun 2016 10:23:30 -0400 Subject: [PATCH 2/2] Add SCons build for Python 2 only. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d5add9b..5b0c3e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,8 @@ script: - cmake -DPYTHON_EXECUTABLE=$PYTHON .. && make && make test ARGS="-V" - cd ../libs/numpy/doc - make html + - cd ../../../ + - if [ "$PYTHON" == "/usr/bin/python" ]; then scons; fi env: - PYTHON=/usr/bin/python