Classes | Functions | Variables
gaussian.cpp File Reference
#include <boost/numpy.hpp>
#include <cmath>
#include <memory>
#include <boost/math/constants/constants.hpp>
Include dependency graph for gaussian.cpp:

Go to the source code of this file.

Classes

class  bivariate_gaussian
class  matrix2
struct  mv2_from_python< T, N >
class  vector2

Functions

 BOOST_PYTHON_MODULE (gaussian)
static void copy_ndarray_to_mv2 (bn::ndarray const &array, vector2 &vec)
static void copy_ndarray_to_mv2 (bn::ndarray const &array, matrix2 &mat)
double dot (vector2 const &v1, vector2 const &v2)
vector2 operator* (matrix2 const &m, vector2 const &v)
static bn::ndarray py_get_mu (bp::object const &self)
static bn::ndarray py_get_sigma (bp::object const &self)

Variables

const double M_PI = boost::math::constants::pi<double>()

Function Documentation

BOOST_PYTHON_MODULE ( gaussian  )

Definition at line 289 of file gaussian.cpp.

static void copy_ndarray_to_mv2 ( bn::ndarray const &  array,
vector2 vec 
) [static]

To allow the constructor to work, we need to define some from-Python converters from NumPy arrays to the matrix/vector types. The rvalue-from-python functionality is not well-documented in Boost.Python itself; you can learn more from boost/python/converter/rvalue_from_python_data.hpp. We start with two functions that just copy a NumPy array into matrix/vector objects. These will be used in the templated converted below. The first just uses the operator[] overloads provided by bp::object.

Definition at line 211 of file gaussian.cpp.

static void copy_ndarray_to_mv2 ( bn::ndarray const &  array,
matrix2 mat 
) [static]

Here, we'll take the alternate approach of using the strides to access the array's memory directly. This can be much faster for large arrays.

Definition at line 220 of file gaussian.cpp.

double dot ( vector2 const &  v1,
vector2 const &  v2 
)

Vector inner product.

Definition at line 90 of file gaussian.cpp.

vector2 operator* ( matrix2 const &  m,
vector2 const &  v 
)

Matrix-vector multiplication.

Definition at line 80 of file gaussian.cpp.

static bn::ndarray py_get_mu ( bp::object const &  self) [static]

These two functions are custom wrappers for get_mu and get_sigma, providing the shallow-copy conversion with reference counting described above.

It's also worth noting that these return NumPy arrays that cannot be modified in Python; the const overloads of vector::data() and matrix::data() return const references, and passing a const pointer to from_data causes NumPy's 'writeable' flag to be set to false.

Definition at line 179 of file gaussian.cpp.

static bn::ndarray py_get_sigma ( bp::object const &  self) [static]

Definition at line 189 of file gaussian.cpp.


Variable Documentation

const double M_PI = boost::math::constants::pi<double>()

Definition at line 13 of file gaussian.cpp.



boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40