Skip to content

Commit

Permalink
DOC: Function docs for set_not_
Browse files Browse the repository at this point in the history
  • Loading branch information
RUrlus committed May 30, 2020
1 parent 211f78c commit baef46c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/source/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,42 @@ Update array
carma::update_array(mat, arr);
}

Transfer ownership
******************

If you want to transfer ownership to the C++ side you can use:

.. code-block:: c++

#include <armadillo>
#include <carma/carma.h>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

arma::Mat<double> steal_array(py::array_t<double> & arr) {
// convert to armadillo matrix
arma::Mat<double> mat = carma::arr_to_mat<double>(arr);
// inform numpy it no longer owns the data
carma::set_not_owndata<double>(arr);
return mat;
}

py::array_t<double> numpy_view(arma::Mat<double> & mat) {
/* Return view on the buffer */
py::array_t<double> arr = carma::mat_to_arr<double>(mat);
// inform numpy it that it doesn't own the data
carma::set_not_owndata<double>(arr)
return arr;
}
py::array_t<double> numpy_view(const arma::Mat<double> & mat) {
/* Return read only view on the buffer */
py::array_t<double> arr = carma::mat_to_arr<double>(mat);
carma::set_not_owndata<double>(arr)
carma::test_set_not_writeable<double>(arr)
return arr;
}
Automatic conversion
********************

Expand Down
12 changes: 12 additions & 0 deletions docs/source/carma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,15 @@ Utility functions to check flags of numpy arrays.
when either not writable, owndata or is not aligned.

:param arr: numpy array to be checked

.. function:: void set_not_owndata(py::array_t<T> & arr)

Set Numpy array's flag OWNDATA to false.

:param arr: numpy array to be changed

.. function:: void set_not_writeable(py::array_t<T> & arr)

Set Numpy array's flag WRITEABLE to false.

:param arr: numpy array to be changed

0 comments on commit baef46c

Please sign in to comment.