All Projects → fwilliams → numpyeigen

fwilliams / numpyeigen

Licence: MIT License
Fast zero-overhead bindings between NumPy and Eigen

Programming Languages

python
139335 projects - #7 most used programming language
C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to numpyeigen

Numpycpp
A c++ header library for matrix operation inspired Numpy Scipy, MATLAB only using Eigen.
Stars: ✭ 30 (-60%)
Mutual labels:  numpy, eigen, scipy
skinner
Skin export / import tools for Autodesk Maya
Stars: ✭ 68 (-9.33%)
Mutual labels:  binding, numpy, scipy
Cheatsheets Ai
Essential Cheat Sheets for deep learning and machine learning researchers https://medium.com/@kailashahirwar/essential-cheat-sheets-for-machine-learning-and-deep-learning-researchers-efb6a8ebd2e5
Stars: ✭ 14,095 (+18693.33%)
Mutual labels:  numpy, scipy
Ml Feynman Experience
A collection of analytics methods implemented with Python on Google Colab
Stars: ✭ 217 (+189.33%)
Mutual labels:  numpy, scipy
PVMismatch
An explicit Python PV system IV & PV curve trace calculator which can also calculate mismatch.
Stars: ✭ 51 (-32%)
Mutual labels:  numpy, scipy
Pyhf
pure-Python HistFactory implementation with tensors and autodiff
Stars: ✭ 171 (+128%)
Mutual labels:  numpy, scipy
Tftb
A Python module for time-frequency analysis
Stars: ✭ 185 (+146.67%)
Mutual labels:  numpy, scipy
Orange3
🍊 📊 💡 Orange: Interactive data analysis
Stars: ✭ 3,152 (+4102.67%)
Mutual labels:  numpy, scipy
Data Analysis
主要是爬虫与数据分析项目总结,外加建模与机器学习,模型的评估。
Stars: ✭ 142 (+89.33%)
Mutual labels:  numpy, scipy
dsp-theory
Theory of digital signal processing (DSP): signals, filtration (IIR, FIR, CIC, MAF), transforms (FFT, DFT, Hilbert, Z-transform) etc.
Stars: ✭ 643 (+757.33%)
Mutual labels:  numpy, scipy
audiophile
Audio fingerprinting and recognition
Stars: ✭ 17 (-77.33%)
Mutual labels:  numpy, scipy
object-detection-with-deep-learning
demonstrating use of convolution neural networks to detect objects in a video
Stars: ✭ 17 (-77.33%)
Mutual labels:  numpy, scipy
Psi4numpy
Combining Psi4 and Numpy for education and development.
Stars: ✭ 170 (+126.67%)
Mutual labels:  numpy, scipy
Micropython Ulab
a numpy-like fast vector module for micropython, circuitpython, and their derivatives
Stars: ✭ 166 (+121.33%)
Mutual labels:  numpy, scipy
Pybotics
The Python Toolbox for Robotics
Stars: ✭ 192 (+156%)
Mutual labels:  numpy, scipy
Piecewise linear fit py
fit piecewise linear data for a specified number of line segments
Stars: ✭ 141 (+88%)
Mutual labels:  numpy, scipy
polytope
Geometric operations on polytopes of any dimension
Stars: ✭ 51 (-32%)
Mutual labels:  numpy, scipy
Ml Cheatsheet
A constantly updated python machine learning cheatsheet
Stars: ✭ 136 (+81.33%)
Mutual labels:  numpy, scipy
Nptdms
NumPy based Python module for reading TDMS files produced by LabView
Stars: ✭ 138 (+84%)
Mutual labels:  numpy, scipy
introduction to ml with python
도서 "[개정판] 파이썬 라이브러리를 활용한 머신 러닝"의 주피터 노트북과 코드입니다.
Stars: ✭ 211 (+181.33%)
Mutual labels:  numpy, scipy

NumpyEigen - Fast zero-overhead bindings between NumPy and Eigen Build Status Build status

NumpyEigen makes it easy to transparently convert NumPy dense arrays and SciPy sparse matrices to Eigen with zero copy overhead while taking advantage of Eigen's expression template system for maximum performance.

Eigen is a C++ numerical linear algebra library. It uses expression templates to pick the fastest numerical algorithms for a given set of input types. NumPy and SciPy are libraries exposing fast numerical routines in Python.

Since type information in Python is only available at runtime, it is not easy to write bindings which accept multiple NumPy or SciPy types, have zero copy overhead, and can make use of the fastest numerical kernels in Eigen. NumpyEigen transparently generates bindings which do all of the above, exposing numpy type information at compile time to C++ code.

Zero Copy-Overhead

Bindings written with NumpyEigen have zero copy overhead from Python to C++ and vice versa for any NumPy dense array or SciPy CSR or CSC sparse matrix.

Binding Function Overloading

NumpyEigen allows type overloading of binding input arguments. The type of the argument is made available at compile time to the C++ code. This type information is in turn used to drive Eigen's expression template system to choose the fastest numerical algorithm for a given input type.

Build System Support

NumpyEigen comes built-in with CMake tools to integrate with existing build systems in a single line of code. A set of scripts to integrate with other build systems will be included in the future.

Minimal Dependencies

NumpyEigen only requires the system to have a valid C++ 14 (or later) compiler and a running Python interpreter with version >= 2.7.

NumpyEigen uses pybind11 under the hood which is included automatically by the cmake project.

Example

See the Example Project Repository for a fully running example project.

When compiled, the following code will generate a function foo(a, b, c, d, e, f) callable from Python. foo returns a tuple of values computed from its inputs.

#include <npe.h>
#include <tuple>
#include <string>

// Create a function named foo exposed to python
npe_function(foo)                     

// The arguments to foo are as follows:
// Each of these are transparently converted from numpy types to appropriate Eigen::Map types
// wiith zero copy overhead.
npe_arg(a, dense_double, dense_float)   // a is a numpy array with dtype either float or double
npe_arg(b, matches(a))                  // b is a numpy array whose type has to match a
npe_arg(c, dense_int, dense_long)       // c is a numpy array whose type is either int or long
npe_arg(d, std::string)                 // d is a string
npe_arg(f, sparse_float, sparse_double) // f is a sparse matrix whose data is either float or double
npe_arg(e, int)                         // e is an int

// NumpyEigen supports doc strings which are expression evaluating to C strings or std::string types
npe_doc("A function which computes various values from input matrices")

// The C++ code for the function starts after this line
npe_begin_code()

// npe_Matrix_* are Eigen::Matrix<T> or Eigen::SparseMatrix<T> types corresponding to the inputs
npe_Matrix_a ret1 = a + b;
npe_Matrix_a ret2 = a - c;
int ret3 = d + std::string("concatenated");
int ret4 = e + 2;
npe_Matrix_f ret5 = f * 1.5;

// npe::move() wraps an Eigen type in a NumPy or SciPy type with zero copy overhead
return std::make_tuple(npe::move(ret1), npe::move(ret2), ret3, ret4, npe::move(ret5));

npe_end_code()

Building with CMake

To create a Python Module named mymodule which exposes the function foo, stored in foo.cpp add the following to your CMakeLists.txt:

# Make numpyeigen available in the current project
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /path/to/numpyeigen/cmake)
include(numpyeigen)

npe_add_module(mymodule, BINDING_SOURCES foo.cpp)

Configuring NumpyEigen

NumpyEigen exposes several configuration options via CMake:

  • NPE_PYTHON_EXECUTABLE: The path to the python interpreter to build against. This interpreter is used to determine the correct headers and libraries when building.
  • NPE_PYTHON_VERSION: Request a specific version of Python on the system . NOTE: if NPE_PYTHON_EXECUTABLE is set, then this option is ignored.
  • NPE_WITH_EIGEN: NumpyEigen includes a bundled version of Eigen for convenience. If this option is set, then an interface library named Eigen3::Eigen is exposed and used to compile NumpyEigen modules.
  • NPE_ROOT: The path to the root of the NumpyEigen codebase. If you include numpyeigen.cmake directly from this repository, you do not need to set this.

Building and Running Tests

Building the tests should be as easy as:

mkdir build
cd build
cmake ..
make
make test

There's an tests/environment.yml file which can be used to generate conda environment with a ll the right dependencies by running:

conda env create -f environment.yml
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].