int octave_value::numel (void) const;

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

int octave_value::numel (void) const;

David Bateman-3
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.

Regards
David


--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Reply | Threaded
Open this post in threaded view
|

int octave_value::numel (void) const;

John W. Eaton-6
On 15-Nov-2004, David Bateman <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

David Bateman-3
In reply to this post by David Bateman-3
> I had assumed that numel would always be equivalent to
>
>  prod (size ())

Its not true for the sparse class, in fact see what happens for

a= speye(1e6);
whos a

*** local user variables:

  Prot Name         Size                     Bytes  Class
  ==== ====         ====                     =====  =====
   rwd a      1000000x1000000                    0  sparse

Total is 3567587328 elements using 0 bytes

or with the new sparse class gives

*** local user variables:

  Prot Name         Size                     Bytes  Class
  ==== ====         ====                     =====  =====
   rwd a      1000000x1000000             16000004  sparse matrix

Total is 3567587328 elements using 16000004 bytes


Which is clearly wrong due to an overflow in the the integer calculation
prod(size(a))... Which is probably why matlab chose to only count the
non-zero elements in numel...

>
> 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.

Ok, I'll submit a patch then..

Cheers
David


--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

David Bateman-3
In reply to this post by David Bateman-3
Try the attached patch, though I can't test it due to the configure
problems I'm having

D.

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

John W. Eaton-6
On 16-Nov-2004, David Bateman <[hidden email]> wrote:

| Try the attached patch, though I can't test it due to the configure
| problems I'm having

I applied these changes.

Thanks,

jwe


Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

David Bateman-3
According to John W. Eaton <[hidden email]> (on 11/16/04):

> On 16-Nov-2004, David Bateman <[hidden email]> wrote:
>
> | Try the attached patch, though I can't test it due to the configure
> | problems I'm having
>
> I applied these changes.
>
> Thanks,
>
> jwe
You also need the attached one line patch so that the "end" keyword
will work correctly for types where numel() is not the same as
dims().numel()...

Cheers
David

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

patch.end (268 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

John W. Eaton-6
On 17-Nov-2004, David Bateman <[hidden email]> wrote:

| You also need the attached one line patch so that the "end" keyword
| will work correctly for types where numel() is not the same as
| dims().numel()...

OK, I made this change and added the following comment:

  // We want numel = prod (size ()) here, so dont' use
  // index_object->numel () as that may be different (it is
  // the number of nonzero elements for sparse arrays).

Is that accurate?

Thanks,

jwe


Reply | Threaded
Open this post in threaded view
|

Re: int octave_value::numel (void) const;

David Bateman-3
According to John W. Eaton <[hidden email]> (on 11/17/04):

> On 17-Nov-2004, David Bateman <[hidden email]> wrote:
>
> | You also need the attached one line patch so that the "end" keyword
> | will work correctly for types where numel() is not the same as
> | dims().numel()...
>
> OK, I made this change and added the following comment:
>
>   // We want numel = prod (size ()) here, so dont' use
>   // index_object->numel () as that may be different (it is
>   // the number of nonzero elements for sparse arrays).
>
> Is that accurate?

Perfect :-)

D.

--
David Bateman                                [hidden email]
Motorola CRM                                 +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary