help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{


From: Sergei Steshenko
Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, sizeof(foo{:})
Date: Mon, 8 Aug 2011 22:27:42 -0700 (PDT)

--- On Mon, 8/8/11, James Sherman Jr. <address@hidden> wrote:

From: James Sherman Jr. <address@hidden>
Subject: Re: foo_cs = foo{:} - feature or bug ? (octave-3.4.2); also, 
sizeof(foo{:})
To: "Sergei Steshenko" <address@hidden>
Cc: "address@hidden" <address@hidden>
Date: Monday, August 8, 2011, 11:06 AM



And I am trying to tell the following:



in



"

octave:4> foo_cs = foo{:}

foo_cs = a

"



one can see, that that "not object" is somehow converted into 'foo_cs',

using whatever implicit rules.





Likewise, in



"

octave:6> sizeof(1 + 2)

ans =  8

"



the "1 + 2", which is an _expression_, is first converted (apparently) into

a _single_ double value, and the size of that double value is (apparently)

displayed.



So, the inconsistency, as I see it, is:



arithmetic expressions are _by_ _default_ converted into a _single_

memory location holding their value, and that memory location size in

bytes is dispalyed;



_opposed_ _to_ _that_



comma separated list is _not_ converted when 'sizeof' is called, but

some _deafault_ conversion is called in case of



"

octave:4> foo_cs = foo{:}

foo_cs = a

".



I.e. why for arithmetic expressions in case of "sizeof(1 + 2)" I see

something like:



invisible_result = 1 + 2; sizeof(invisible_result)



, but for comma-separated list in case of "sizeof(foo{:})" I do _not_ see



invisible_result = foo{:}; sizeof(invisible_result)

I'm confused on your use of word inconsistency.In case A, something happens.In 
case B, something else happens.
This isn't an inconsistency, its how different things (an object vs. a comma 
separated list) are handled by octave.
I'm not sure if this is an entirely accurate analogy, but I think of comma 
separated lists as almost like a macro.  foo{:} is shorthand (for lack of a 
better term) for writing out each element in the list with commas in between 
them.
The assignment when you write:foo_cs = foo{:}is the same as if you wrotefoo_cs 
= foo{1},foo{2},...,foo{end};
Thus the result of the linefoo_cs = foo{:}
is to assign the first cell of foo to the variable foo_cs and that is it.
A small example:octave-3.2.4.exe:2> foo{1} = 4;octave-3.2.4.exe:3> foo{2} = 5;
octave-3.2.4.exe:4> c = foo{:}c =  4octave-3.2.4.exe:5> c = 4,5;c =  4
Hope this helps. 

--------------------------------------------------------------------------


Regarding

"
I'm confused on your use of word inconsistency.In case A, something happens.In 
case B, something else happens.
This isn't an inconsistency, its how different things (an object vs. a comma 
separated list) are handled by octave.
".

Let's again look at 'help sizeof':

"
help sizeof
`sizeof' is a built-in function

 -- Built-in Function:  sizeof (VAL)
     Return the size of VAL in bytes.

     See also: whos
...
".

_Typically_ VAL means value; to me in

"
octave:2> foo = {1, 2, 3}
foo =
{
  [1,1] =  1
  [1,2] =  2
  [1,3] =  3
}
octave:3> foo_cs = foo{:}
foo_cs =  1
octave:4> 
"

the

"
octave:3> foo_cs = foo{:}
foo_cs =  1
"

part looks like a (awkward) way of taking/making a value out of a list,
that is why I expect 'sizeof' to work on that value - because it _does_
work on '1 + 2' expression.

Regards,
  Sergei.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]