|
| 1 | +/*! |
| 2 | + * \file bindings/python/include/MGIS/Python/NumPySupport.hxx |
| 3 | + * \brief |
| 4 | + * \author Thomas Helfer |
| 5 | + * \date 07/11/2018 |
| 6 | + * \copyright (C) Copyright Thomas Helfer 2018. |
| 7 | + * Use, modification and distribution are subject |
| 8 | + * to one of the following licences: |
| 9 | + * - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying |
| 10 | + * file LGPL-3.0.txt) |
| 11 | + * - CECILL-C, Version 1.0 (See accompanying files |
| 12 | + * CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt). |
| 13 | + */ |
| 14 | + |
| 15 | +#ifndef LIB_MGIS_PYTHON_NUMPYSUPPORT_HXX |
| 16 | +#define LIB_MGIS_PYTHON_NUMPYSUPPORT_HXX |
| 17 | + |
| 18 | +#include <span> |
| 19 | +#include <vector> |
| 20 | +#include <variant> |
| 21 | +#include <boost/python/object.hpp> |
| 22 | +#include "MGIS/Config.hxx" |
| 23 | + |
| 24 | +namespace mgis::python { |
| 25 | + |
| 26 | + //! \brief initialize NumPy |
| 27 | + void initializeNumPy(); |
| 28 | + |
| 29 | + /*! |
| 30 | + * \brief create a 1D-ndarray object from a vector. |
| 31 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 32 | + * the vector. |
| 33 | + * \param[in] v: values |
| 34 | + */ |
| 35 | + boost::python::object wrapInNumPyArray(std::span<double>&); |
| 36 | + /*! |
| 37 | + * \brief create a 1D-ndarray object from a vector. |
| 38 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 39 | + * the vector. |
| 40 | + * \param[in] v: values |
| 41 | + */ |
| 42 | + boost::python::object wrapInNumPyArray( |
| 43 | + std::variant<std::span<double>, std::vector<double>>&); |
| 44 | + /*! |
| 45 | + * \brief create a 1D-ndarray object from a vector. |
| 46 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 47 | + * the vector. |
| 48 | + * \param[in] v: vector holding the values |
| 49 | + */ |
| 50 | + boost::python::object wrapInNumPyArray(std::vector<double>&); |
| 51 | + /*! |
| 52 | + * \brief create a 2D-ndarray object from a vector. |
| 53 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 54 | + * the vector. |
| 55 | + * \param[in] v: values |
| 56 | + * \param[in] nc: number of columns |
| 57 | + */ |
| 58 | + boost::python::object wrapInNumPyArray(std::span<double>&, |
| 59 | + const mgis::size_type); |
| 60 | + /*! |
| 61 | + * \brief create a 2D-ndarray object from a vector. |
| 62 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 63 | + * the vector. |
| 64 | + * \param[in] v: values |
| 65 | + * \param[in] nc: number of columns |
| 66 | + */ |
| 67 | + boost::python::object wrapInNumPyArray( |
| 68 | + std::variant<std::span<double>, std::vector<double>>&, |
| 69 | + const mgis::size_type); |
| 70 | + /*! |
| 71 | + * \brief create a 2D-ndarray object from a vector. |
| 72 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 73 | + * the vector. |
| 74 | + * \param[in] v: vector holding the values |
| 75 | + * \param[in] nc: number of columns |
| 76 | + */ |
| 77 | + boost::python::object wrapInNumPyArray(std::vector<double>&, |
| 78 | + const mgis::size_type); |
| 79 | + /*! |
| 80 | + * \brief create a 3D-ndarray object from a vector. |
| 81 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 82 | + * the vector. |
| 83 | + * \param[in] v: values |
| 84 | + * \param[in] nl: number of line |
| 85 | + * \param[in] nc: number of columns |
| 86 | + */ |
| 87 | + boost::python::object wrapInNumPyArray(std::span<double>&, |
| 88 | + const mgis::size_type, |
| 89 | + const mgis::size_type); |
| 90 | + /*! |
| 91 | + * \brief create a 3D-ndarray object from a vector. |
| 92 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 93 | + * the vector. |
| 94 | + * \param[in] v: values |
| 95 | + * \param[in] nl: number of line |
| 96 | + * \param[in] nc: number of columns |
| 97 | + */ |
| 98 | + boost::python::object wrapInNumPyArray( |
| 99 | + std::variant<std::span<double>, std::vector<double>>&, |
| 100 | + const mgis::size_type, |
| 101 | + const mgis::size_type); |
| 102 | + /*! |
| 103 | + * \brief create a 3D-ndarray object from a vector. |
| 104 | + * The ndarray does not own the data, the lifetime of which is handled by |
| 105 | + * the vector. |
| 106 | + * \param[in] v: vector holding the values |
| 107 | + * \param[in] nl: number of line |
| 108 | + * \param[in] nc: number of columns |
| 109 | + */ |
| 110 | + boost::python::object wrapInNumPyArray(std::vector<double>&, |
| 111 | + const mgis::size_type, |
| 112 | + const mgis::size_type); |
| 113 | + |
| 114 | + std::span<mgis::real> mgis_convert_to_span(const boost::python::object&); |
| 115 | + |
| 116 | +} // end of namespace mgis::python |
| 117 | + |
| 118 | +#endif /* LIB_MGIS_PYTHON_NUMPYSUPPORT_HXX */ |
0 commit comments