Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 22 .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
- cd ../../../
- if [ "$PYTHON" == "/usr/bin/python" ]; then scons; fi

env:
- PYTHON=/usr/bin/python
- PYTHON=/usr/bin/python3
28 changes: 14 additions & 14 deletions 28 libs/numpy/doc/tutorial/dtype.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/numpy.hpp>
#include <iostream>
#include <boost/numpy.hpp>
#include <iostream>

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<double>();
np::ndarray a = np::zeros(shape, dtype);
p::tuple shape = p::make_tuple(3, 3);
np::dtype dtype = np::dtype::get_builtin<double>();
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 <char const \* > template ::

std::cout << "Original array:\n" << p::extract<char const *>(p::str(a)) << std::endl;
std::cout << "Original array:\n" << p::extract<char const *>(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<char const *>(p::str(a.get_dtype())) << std::endl ;
std::cout << "Datatype is:\n" << p::extract<char const *>(p::str(a.get_dtype())) << std::endl ;

We can also create custom dtypes and build ndarrays with the custom dtypes

Expand All @@ -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);

}
}
16 changes: 8 additions & 8 deletions 16 libs/numpy/doc/tutorial/fromdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/numpy.hpp>
#include <iostream>
#include <boost/numpy.hpp>
#include <iostream>

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::

Expand Down
16 changes: 8 additions & 8 deletions 16 libs/numpy/doc/tutorial/ndarray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/numpy.hpp>
#include <iostream>
#include <boost/numpy.hpp>
#include <iostream>

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 ::

Expand Down
38 changes: 19 additions & 19 deletions 38 libs/numpy/doc/tutorial/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/numpy.hpp>
#include <iostream>
#include <boost/numpy.hpp>
#include <iostream>

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<float>();
np::ndarray a = np::zeros(shape, dtype);
p::tuple shape = p::make_tuple(3, 3);
np::dtype dtype = np::dtype::get_builtin<float>();
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<char const *>(p::str(a)) << std::endl;
std::cout << "Original array:\n" << p::extract<char const *>(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<char const *>(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<char const *>(p::str(a)) << std::endl;
}

2 changes: 1 addition & 1 deletion 2 libs/numpy/test/runCmakeTest.sh.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
export PYTHONPATH=@CMAKE_LIBRARY_OUTPUT_DIRECTORY@:${PYTHONPATH}
python $1
@PYTHON_EXECUTABLE@ $1
Morty Proxy This is a proxified and sanitized view of the page, visit original site.