From bc20cc1ed727c569b436cc9c2cf7e5878b5a4f2c Mon Sep 17 00:00:00 2001 From: Philippe Tillet Date: Thu, 19 Nov 2015 19:22:11 -0500 Subject: [PATCH] Python: updated wrapper to match C++ API --- python/src/bind/core.cpp | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/python/src/bind/core.cpp b/python/src/bind/core.cpp index 33e53bb77..7c04f8224 100644 --- a/python/src/bind/core.cpp +++ b/python/src/bind/core.cpp @@ -46,7 +46,7 @@ np::dtype to_np_dtype(sc::numeric_type const & T) throw() } } -bp::tuple get_shape(sc::array const & x) +bp::tuple get_shape(sc::array_base const & x) { return bp::make_tuple(x.shape()[0], x.shape()[1]); } @@ -303,14 +303,10 @@ void export_core() .def(bp::other() OP bp::self) \ ADD_SCALAR_HANDLING(OP) - bp::class_ > - ( "array", bp::no_init) - .def("__init__", bp::make_constructor(detail::create_array, bp::default_call_policies(), (bp::arg("obj"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")= bp::object()))) - .def(bp::init()) - .add_property("dtype", &sc::array::dtype) - .add_property("context", bp::make_function(&sc::array::context, bp::return_internal_reference<>())) - .add_property("T", &sc::array::T) + bp::class_("array_base", bp::no_init) + .add_property("dtype", &sc::array_base::dtype) + .add_property("context", bp::make_function(&sc::array_base::context, bp::return_internal_reference<>())) + .add_property("T", &sc::array_base::T) .add_property("shape", &detail::get_shape) ADD_ARRAY_OPERATOR(+) ADD_ARRAY_OPERATOR(-) @@ -327,23 +323,33 @@ void export_core() .def(bp::self_ns::str(bp::self_ns::self)) ; - bp::class_ > + bp::class_, bp::bases > + ( "array", bp::no_init) + .def("__init__", bp::make_constructor(detail::create_array, bp::default_call_policies(), (bp::arg("obj"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")= bp::object()))) + .def(bp::init()) + ; + + bp::class_ > + ("view", bp::no_init) + ; + + bp::class_ > ("scalar", bp::no_init) .def("__init__", bp::make_constructor(detail::construct_scalar, bp::default_call_policies(), (bp::arg(""), bp::arg("context")=bp::object()))) - ; + ; //Other numpy-like initializers bp::def("empty", &detail::create_empty_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=bp::object())); //Assign - bp::def("assign", static_cast(&sc::assign));\ - bp::def("assign", static_cast(&sc::assign));\ + bp::def("assign", static_cast(&sc::assign));\ + bp::def("assign", static_cast(&sc::assign));\ //Binary #define MAP_FUNCTION(name) \ - bp::def(#name, static_cast(&sc::name));\ - bp::def(#name, static_cast(&sc::name));\ - bp::def(#name, static_cast(&sc::name));\ + bp::def(#name, static_cast(&sc::name));\ + bp::def(#name, static_cast(&sc::name));\ + bp::def(#name, static_cast(&sc::name));\ bp::def(#name, static_cast(&sc::name)); MAP_FUNCTION(maximum) @@ -354,7 +360,7 @@ void export_core() //Unary #define MAP_FUNCTION(name) \ - bp::def(#name, static_cast(&sc::name));\ + bp::def(#name, static_cast(&sc::name));\ bp::def(#name, static_cast(&sc::name)); bp::def("zeros", &detail::create_zeros_array, (bp::arg("shape"), bp::arg("dtype") = bp::scope().attr("float32"), bp::arg("context")=bp::object())); @@ -380,7 +386,7 @@ void export_core() /*--- Reduction operators----*/ //--------------------------------------- #define MAP_FUNCTION(name) \ - bp::def(#name, static_cast(&sc::name));\ + bp::def(#name, static_cast(&sc::name));\ bp::def(#name, static_cast(&sc::name)); MAP_FUNCTION(sum)