[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: numel(foo{:}) - feature or bug ?
From: |
Sergei Steshenko |
Subject: |
Re: numel(foo{:}) - feature or bug ? |
Date: |
Fri, 5 Aug 2011 09:37:30 -0700 (PDT) |
--- On Fri, 8/5/11, Sergei Steshenko <address@hidden> wrote:
> From: Sergei Steshenko <address@hidden>
> Subject: Re: numel(foo{:}) - feature or bug ?
> To: "Jordi Gutiérrez Hermoso" <address@hidden>
> Cc: address@hidden
> Date: Friday, August 5, 2011, 9:30 AM
>
>
> --- On Fri, 8/5/11, Jordi Gutiérrez Hermoso <address@hidden>
> wrote:
>
> > From: Jordi Gutiérrez Hermoso <address@hidden>
> > Subject: Re: numel(foo{:}) - feature or bug ?
> > To: "Sergei Steshenko" <address@hidden>
> > Cc: "Ben Abbott" <address@hidden>,
> address@hidden
> > Date: Friday, August 5, 2011, 8:32 AM
> > On 5 August 2011 10:14, Sergei
> > Steshenko <address@hidden>
> > wrote:
> > >
> > >
> > > --- On Fri, 8/5/11, Ben Abbott <address@hidden>
> > wrote:
> > >
> > >> From: Ben Abbott <address@hidden>
> > >> Subject: Re: numel(foo{:}) - feature or bug
> ?
> > >> To: "Sergei Steshenko" <address@hidden>
> > >> Cc: address@hidden
> > >> Date: Friday, August 5, 2011, 5:56 AM
> > >> On Aug 5, 2011, at 7:23 AM, Sergei
> > >> Steshenko wrote:
> > >>
> > >> > Hello,
> > >> >
> > >> > first here is screen output of 'help
> numel'
> > in
> > >> octave-3.4.2:
> > >> >
> > >> > "
> > >> > octave:1> help numel
> > >> > `numel' is a built-in function
> > >> >
> > >> > -- Built-in Function: numel (A)
> > >> > -- Built-in Function: numel (A, IDX1,
> > IDX2,
> > >> ...)
> > >> > Return the number of elements
> > >> in the object A. Optionally, if
> > >> > indices IDX1, IDX2, ... are
> > >> supplied, return the number of
> > >> > elements that would result
> > >> from the indexing
> > >> >
> > >> > A(IDX1,
> > >> IDX2, ...)
> > >> >
> > >> > This method is also called
> > >> when an object appears as lvalue with
> > >> > cs-list indexing, i.e.,
> > >> `object{...}' or `object(...).field'.
> > >> >
> > >> > See also: size
> > >>
> > >> In case there is some confusion about what
> > fun(foo{:}) does
> > >> ...
> > >>
> > >> fun(foo{:})
> > >>
> > >> is the same as ...
> > >>
> > >> fun (foo{1}, fun{2}, ..., fun{end})
> > >>
> > >> Thus ...
> > >>
> > >> >> foo{1} = "a";
> > >> >> foo{2} = "ab";
> > >> >> foo{3} = "abc";
> > >> >> foo{4} = [1 2 3 4; 5 6 7 8; 9 10 11
> 12];
> > >> >>
> > >> >> numel (foo{:})
> > >> ans = 72
> > >> >> numel (foo{1})
> > >> ans = 1
> > >> >> numel (foo{1}, foo{2}, foo{3},
> foo{4})
> > >> ans = 72
> > >>
> > >> foo{2:4} constitute 2, 3, 3*4 indices. Thus
> the
> > total
> > >> number if implied indices is 2*3*3*4 = 72
> > >>
> > >> Ben
> > >>
> > >
> > > Somebody has already confirmed that Matlab gives
> the
> > same result, so I'll
> > > have to agree that it's the "truth".
> > >
> > > But I consider it to be a silly truth.
> > >
> > > My simplistic understanding of cell arrays is
> that
> > they are like matrices,
> > > just their elements can be of different types
> (and
> > thus sizes).
> > >
> > > The following example is even more confusing:
> > > "
> > > octave:1> foo2d{1,1} = "a"
> > > foo2d =
> > > {
> > > [1,1] = a
> > > }
> > > octave:2> foo2d{1,2} = "aa"
> > > foo2d =
> > > {
> > > [1,1] = a
> > > [1,2] = aa
> > > }
> > > octave:3> foo2d{2,1} = "b"
> > > foo2d =
> > > {
> > > [1,1] = a
> > > [2,1] = b
> > > [1,2] = aa
> > > [2,2] = [](0x0)
> > > }
> > > octave:4> size(foo2d)
> > > ans =
> > >
> > > 2 2
> > >
> > > octave:5> numel(foo2d{:})
> > > ans = 0
> > > octave:6> foo2d
> > > foo2d =
> > > {
> > > [1,1] = a
> > > [2,1] = b
> > > [1,2] = aa
> > > [2,2] = [](0x0)
> > > }
> > > octave:7> foo2d{2,2} = [1 2 3 4 5; 6 7 8 9
> 10]
> > > foo2d =
> > > {
> > > [1,1] = a
> > > [2,1] = b
> > > [1,2] = aa
> > > [2,2] =
> > >
> > > 1 2 3 4 5
> > > 6 7 8 9 10
> > >
> > > }
> > > octave:8> size(foo2d)
> > > ans =
> > >
> > > 2 2
> > >
> > > octave:9> numel(foo2d{:})
> > > ans = 20
> > > octave:10>
> > > ".
> > >
> > > First, in
> > >
> > > "
> > > octave:5> numel(foo2d{:})
> > > ans = 0
> > > "
> > >
> > > zero number of elements which is simply false,
> i.e.
> > _total_ number of
> > > elements, as 'help numel' says, is definitely
> _not_
> > zero.
> >
> > It's not false. You seem to have misunderstood what
> > foo2d{:} is, i.e.
> > its type is cs-list, not cell.
> >
> >
> > http://www.gnu.org/software/octave/doc/interpreter/Comma-Separated-Lists-Generated-from-Cell-Arrays.html#Comma-Separated-Lists-Generated-from-Cell-Arrays
> >
> > What I agree could use an explanation is that the
> indices
> > passed to
> > numel may not necessarily be numerical indices, but
> rather
> > size() is
> > called on them. I'll update numel's docstring.
> >
> > HTH,
> > - Jordi G. H.
> >
> >
> >
> > In this regard
> >
>
> Sorry, Jordi, doesn't make sense to me.
>
> The same 2-d example in more detail:
>
> "
> octave:1> foo2d{1,1} = "a"
> foo2d =
> {
> [1,1] = a
> }
> octave:2> foo2d{:}
> ans = a
> octave:3> sizeof(foo2d)
> ans = 1
> octave:4> numel(foo2d{:})
> ans = 1
> octave:5> foo2d{1,2} = "aa"
> foo2d =
> {
> [1,1] = a
> [1,2] = aa
> }
> octave:6> size(foo2d)
> ans =
>
> 1 2
>
> octave:7> numel(foo2d{:})
> ans = 2
> octave:8> foo2d{2,1} = "b"
> foo2d =
> {
> [1,1] = a
> [2,1] = b
> [1,2] = aa
> [2,2] = [](0x0)
> }
> octave:9> size(foo2d)
> ans =
>
> 2 2
>
> octave:10> foo2d{:}
> ans = a
> ans = b
> ans = aa
> ans = [](0x0)
> octave:11> numel(foo2d{:})
> ans = 0
> octave:12> foo2d{2,2} = [1 2 3 4 5; 6 7 8 9 10]
> foo2d =
> {
> [1,1] = a
> [2,1] = b
> [1,2] = aa
> [2,2] =
>
> 1 2 3
> 4 5
> 6 7 8
> 9 10
>
> }
> octave:13> sizeof(foo2d)
> ans = 84
> octave:14> size(foo2d)
> ans =
>
> 2 2
>
> octave:15> numel(foo2d{:})
> ans = 20
> ".
>
> If you look carefully at this excerpt:
>
> "
> octave:6> size(foo2d)
> ans =
>
> 1 2
>
> octave:7> numel(foo2d{:})
> ans = 2
> octave:8> foo2d{2,1} = "b"
> foo2d =
> {
> [1,1] = a
> [2,1] = b
> [1,2] = aa
> [2,2] = [](0x0)
> }
> octave:9> size(foo2d)
> ans =
>
> 2 2
>
> octave:10> foo2d{:}
> ans = a
> ans = b
> ans = aa
> ans = [](0x0)
> octave:11> numel(foo2d{:})
> ans = 0
> ",
>
> you'll see that:
>
> 1) I am _adding_ an element:
>
> octave:8> foo2d{2,1} = "b"
> foo2d =
> {
> [1,1] = a
> [2,1] = b
> [1,2] = aa
> [2,2] = [](0x0)
> }
>
> 2)
> "
> octave:9> size(foo2d)
> ans =
>
> 2 2
> "
> kind of acknowledges he above addition by changing its
> output from
> "1 2" to "2 2", i.e. now we have _two_ rows instead of
> one;
>
>
> 3) my _eyes_ see the element in foo2d{:}:
> "
> octave:10> foo2d{:}
> ans = a
> ans = b
> ans = aa
> ans = [](0x0)
> ".
>
> In fact, my _eyes_ see _three_ non-empty elements _not_
> zero;
>
> 4) immediately after that my _eyes_ see:
>
> "
> octave:11> numel(foo2d{:})
> ans = 0
> ",
>
> i.e. _zero_, not _three_.
>
> And zero instead of three is _nonsense_ to me. Call me
> dumb.
>
> ...
>
> I think 'octave' should have a 'enable_stupid_matlab_bugs'
> flag.
>
> Thanks,
> Sergei.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
Oh, if somebody wants (pseudo)scientific terminology, then here it is:
Why does adding an element causes non-monotonicity in numel(foo2d{:}) ?
Thanks,
Sergei.
- Re: numel(foo{:}) - feature or bug ?, (continued)
Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
Re: numel(foo{:}) - feature or bug ?, Ben Abbott, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?, Jordi Gutiérrez Hermoso, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?,
Sergei Steshenko <=
- Re: numel(foo{:}) - feature or bug ?, Marco atzeri, 2011/08/05
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/06
- Re: numel(foo{:}) - feature or bug ?, Marco atzeri, 2011/08/06
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/06
- Re: numel(foo{:}) - feature or bug ?, Marco atzeri, 2011/08/06
- Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/06
Re: numel(foo{:}) - feature or bug ?, Jordi Gutiérrez Hermoso, 2011/08/05
Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
Re: numel(foo{:}) - feature or bug ?, Sergei Steshenko, 2011/08/05
Re: numel(foo{:}) - feature or bug ?, fork, 2011/08/05