From maintainers-request at octave dot org Tue Nov 16 11:46:27 2004 Subject: int octave_value::numel (void) const; From: "John W. Eaton" To: David Bateman Cc: maintainers at octave dot org Date: Tue, 16 Nov 2004 12:46:23 -0500 On 15-Nov-2004, David Bateman wrote: | Is there any reason not to change the definition of numel is ov.h to | be a virtual function like | | virtual int numel (void) const | { return rep->numel (); } | | and then add to ov-base.h | | int numel (void) const { return dims ().numel (); } | | The reason is that the code in symtab.cc for whos uses the numel | function, which with the current code is based solely on the dimension | vector. However the numel for a sparse matrix should be the non-zero | elements only, and so the current behaviour is wrong. Making the above | change allows numel to be overloaded, with a sparse matrix specific | version. | | The only problem I see is that oct-map.h includes its own version of | numel. Issues might arise for the is_empty, and the value of numel | returned in whos for structures, though I'm not sure this is a problem | even in that case. I had assumed that numel would always be equivalent to prod (size ()) but if it is not, then it is fine with me to change the definition of numel so that it can be defined differently in derived classses. jwe