Home

What is ArmaNpy?

ArmaNpy is a set of SWIG interface files (typemaps) which allows generating Python bindings to C++ code which uses the Armadillo matrix library.

From within Python any Armadillo matrices are represented as NumPy matrices. This is possible due to the same memory layout used. Copying of memory is avoided whenever possible. It also supports boost::shared_ptr wrapped return values of Armadillo matrices.

Note that sparse matrices are not supported.

Usage

See the files example/example.i and test/test.i how to use ArmaNpy to generate bindings for a set of classes defined in example/example.hpp and test/test.hpp.
See example/example.py and test/armanpy_tests.py for the Python side of usage (note that armanpy_tests.py is just unit tests).

How to compile and run the example and the tests?

1) Use CMake to generate your build system based on the provided CMakeLists file in the example or test dir.
2) Build the resulting project.
3) Run the Python script example.py or armanpy_tests.py

From the command line this can be done as follows for the examples (adapt to your path settings and use '\' instead of '/' on Windows). The some holds for the tests:

cd /path/to/armanpy/example
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DARMADILLO_INCLUDE_DIR=/path/to/your/armadillo/include
cmake --build . --config Release
cd ..
python example.py

or

python armanpy_tests.py

Note : The -DCMAKE_BUILD_TYPE=Release is used bcs on Windows a typical Python distribution does not come with the debug version of the Python libraries. Hence, the build would fail for the Debug configuration.

Remark : To use 64bit under Windows add e.g. -G "Visual Studio 11 Win64" to the first cmake command.

Credits

The idea of wrapping Armadillo matrices by NumPy arrays was taken from Michael Forbes`
https://bitbucket.org/mforbes/swig_cpp_python/src/cd7cef820273?at=default.

Copyright (C) 2012-2014 Thomas Natschläger (thomas.natschlaeger@gmail.com)

License

ArmaNpy is provided without any warranty of fitness
for any purpose. You can redistribute it
and/or modify it under the terms of the GNU
Lesser General Public License (LGPL) as published
by the Free Software Foundation, either version 3
of the License or (at your option) any later version.
(see http://www.opensource.org/licenses for more info)

TODO

  • allow for const arma::Mat< ... > * (should be the same as const arma::Mat< ... > &)
  • allow for arma::Mat< ... > *( should be the same as arma::Mat< ... > &)