[C++-sig] Re: trying to compile simple test example with numeric arrays
dave at boost-consulting.com
Tue Apr 13 13:51:32 CEST 2004
Faheem Mitha <faheem at email.unc.edu> writes:
> 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
> 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
> argument of `boost::python::api::object
> boost::python::numeric::array::take(const Sequence&, long int)
> 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"
I don't know; AFAICT the numeric array's "take" *method* is
undocumented. I probably assumed it would be a mutating operation,
not having any better info to go on.
> Is this some kind of general policy (since some functions
> _will_ mess with "this"), and did I miss it in the documentation?
Not sure what you're asking, but
clearly shows that it's a non-const member function.
> 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?
With a little help from my friends.
>>> // 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.
I wasn't suggesting you leave out the extract. Are you not using a
fixed-width font in your mailer? Deadly practice for a programmer!
I was suggesting you should leave out "<tuple>".
> Is this undesirable practice or not?
More information about the Cplusplus-sig