matrix.cpp
Go to the documentation of this file.
00001 // Copyright Jim Bosch 2010-2012.
00002 // Distributed under the Boost Software License, Version 1.0.
00003 //    (See accompanying file LICENSE_1_0.txt or copy at
00004 //          http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #define BOOST_NUMPY_INTERNAL
00007 #include <boost/numpy/internal.hpp>
00008 #include <boost/numpy/matrix.hpp>
00009 
00010 namespace boost 
00011 {
00012 namespace numpy 
00013 { 
00014 namespace detail 
00015 {
00016 inline python::object get_matrix_type() 
00017 {
00018   python::object module = python::import("numpy");
00019   return module.attr("matrix");
00020 }
00021 } // namespace boost::numpy::detail
00022 } // namespace boost::numpy
00023 
00024 namespace python
00025 {
00026 namespace converter 
00027 {
00028 
00029 PyTypeObject const * object_manager_traits<numpy::matrix>::get_pytype()
00030 {
00031   return reinterpret_cast<PyTypeObject*>(numpy::detail::get_matrix_type().ptr());
00032 }
00033 
00034 } // namespace boost::python::converter
00035 } // namespace boost::python
00036 
00037 namespace numpy 
00038 {
00039 
00040 python::object matrix::construct(python::object const & obj, dtype const & dt, bool copy) 
00041 {
00042   return numpy::detail::get_matrix_type()(obj, dt, copy);
00043 }
00044 
00045 python::object matrix::construct(python::object const & obj, bool copy) 
00046 {
00047   return numpy::detail::get_matrix_type()(obj, object(), copy);
00048 }
00049 
00050 matrix matrix::view(dtype const & dt) const 
00051 {
00052   return matrix(python::detail::new_reference
00053     (PyObject_CallMethod(this->ptr(), const_cast<char*>("view"), const_cast<char*>("O"), dt.ptr())));
00054 }
00055 
00056 matrix matrix::copy() const 
00057 {
00058   return matrix(python::detail::new_reference
00059     (PyObject_CallMethod(this->ptr(), const_cast<char*>("copy"), const_cast<char*>(""))));
00060 }
00061 
00062 matrix matrix::transpose() const 
00063 {
00064   return matrix(python::extract<matrix>(ndarray::transpose()));
00065 }
00066 
00067 } // namespace boost::numpy
00068 } // namespace boost


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