[C++-sig] Re: trying to compile simple test example with numeric arrays

Faheem Mitha faheem at email.unc.edu
Tue Apr 13 01:54:51 CEST 2004


On Mon, 12 Apr 2004 14:39:46 -0400, David Abrahams
<dave at boost-consulting.com> wrote:

> Faheem Mitha <faheem at email.unc.edu> writes:
>
>> Dear People,
>>
>> I'm trying to compile the following and getting errors. 
>
> What errors?

Oh, sorry about that. Late night message. :-)

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/include/python2.3 -c arr.cc -o
/tmp/temp.\
linux-i686-2.3/arr.o
arr.cc: In function `boost::python::numeric::array
   rem_row(boost::python::numeric::array, boost::python::tuple)':
arr.cc:25: error: passing `const boost::python::numeric::array' as
`this'
   argument of `boost::python::api::object
   boost::python::numeric::array::take(const Sequence&, long int)
[with
   Sequence = boost::python::tuple]' discards qualifiers
error: command 'gcc' failed with exit status 1
make: *** [arr.so] Error 1
make: Target `all' not remade because of errors.

In any case, I've figured out the problem. It does not like y being
declared as const in the definition of rem_row. I am not sure why
though, since take will (presumably) not mess with the "this"
object. Is this some kind of general policy (since some functions
_will_ mess with "this"), and did I miss it in the documentation?

Boost.Python looks really nice, by the way. (Now that I have started
using it). Very clean and polished interface. Definitely a lot easier
to work with than the C API interface. Thanks for writing it. Writing
mirror classes for all the python classes must have been a huge amount
for work. Did you do it all yourself?

Thanks for the reply. Take care.

                                                           Faheem.

>> *********************************************************************
>> #include <boost/python/numeric.hpp>
>> #include <boost/python/tuple.hpp>
>> #include <boost/python/extract.hpp>
>> #include <boost/python/object.hpp>
>> #include <boost/python/module.hpp>
>> #include <boost/python/def.hpp>
>> using namespace boost::python;
>>
>> // select designated rows from a 2d numeric array 
>> numeric::array rem_row(const numeric::array y, const tuple ind)
>> { 
>>   return extract<numeric::array>(y.take<tuple>(ind));
>                                          ^^^^^^^
> Should be unneccessary.

Yes, Actually if I do 

object rem_row(numeric::array& y, const tuple& ind)
{
  return y.take<tuple>(ind);
}

it still works. Is this undesirable practice or not?

Thanks.                                      Faheem.

>> }
>>
>> BOOST_PYTHON_MODULE(arr)
>> {
>>   def("rem_row", rem_row);
>> }
>





More information about the Cplusplus-sig mailing list