1 // Copyright Jim Bosch 2010-2012.
2 // Copyright Stefan Seefeld 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 #define BOOST_PYTHON_NUMPY_INTERNAL
8 #include <boost/python/numpy/internal.hpp>
9 #include <boost/python/numpy/matrix.hpp>
10
11 namespace boost { namespace python { namespace numpy
12 {
13 namespace detail
14 {
get_matrix_type()15 inline object get_matrix_type()
16 {
17 object module = import("numpy");
18 return module.attr("matrix");
19 }
20 } // namespace boost::python::numpy::detail
21 } // namespace boost::python::numpy
22
23 namespace converter
24 {
25
get_pytype()26 PyTypeObject const * object_manager_traits<numpy::matrix>::get_pytype()
27 {
28 return reinterpret_cast<PyTypeObject*>(numpy::detail::get_matrix_type().ptr());
29 }
30
31 } // namespace boost::python::converter
32
33 namespace numpy
34 {
35
construct(object const & obj,dtype const & dt,bool copy)36 object matrix::construct(object const & obj, dtype const & dt, bool copy)
37 {
38 return numpy::detail::get_matrix_type()(obj, dt, copy);
39 }
40
construct(object const & obj,bool copy)41 object matrix::construct(object const & obj, bool copy)
42 {
43 return numpy::detail::get_matrix_type()(obj, object(), copy);
44 }
45
view(dtype const & dt) const46 matrix matrix::view(dtype const & dt) const
47 {
48 return matrix(python::detail::new_reference
49 (PyObject_CallMethod(this->ptr(), const_cast<char*>("view"), const_cast<char*>("O"), dt.ptr())));
50 }
51
copy() const52 matrix matrix::copy() const
53 {
54 return matrix(python::detail::new_reference
55 (PyObject_CallMethod(this->ptr(), const_cast<char*>("copy"), const_cast<char*>(""))));
56 }
57
transpose() const58 matrix matrix::transpose() const
59 {
60 return matrix(extract<matrix>(ndarray::transpose()));
61 }
62
63 }}} // namespace boost::python::numpy
64