On Tue, May 25, 2010 at 1:16 PM, Alois Schlögl <alois.schlo...@tugraz.at> wrote:
> Søren Hauberg wrote:
>>
>>>>> -  c = 1 + sum ((x-y)(:)'*z*((x-y)(:)));
>>>>> +  c = 1 + sum (vec(x-y)'*z*(vec(x-y)));
>>>> What is the purpose of this (and similar) change?
>>>
>>> Its again an issue with oct2mat, which can not deal well with (x-y)(:),
>>> especially if these are used within more complicated constructs. Using
>>> vec() avoids this problem.
>>
>> Can't 'oct2mat' just call 'vec' for these types of expressions? It just
>> seems to me that changing code to fit 'oct2mat' is not the right
>> approach (it should be the other way around; that way 'oct2mat' would be
>> more useful). In this case it might even have an impact on performance,
>> though I doubt it matters.
>
>
> No, its not possible to have a general purpose solution for the (...)(:)
> issue. Lets look at the following example [F (x-y)(:)].
> If F is a function, it should be converted to [vec(F(x-y))], but if F is
> a variable, the correct translation is [F vec(x-y)]. oct2mat can not
> know which is correct, because it needs to know the context of this
> expression. In worst case, whether F is a function or variable is
> determined only at runtime.
>

Er, no, (un?)fortunately. This is one of the design flaws of Matlab.
[F (x-y)(:)] is always interpreted as [F, (x-y)(:)], regardless of
whether F is a function or a variable. I think that (expr)(:) should
be always equivalent to vec(expr), at least I can't think of a
counter-example. On the contrary, I don't want the former being
converted to the latter, because the latter involves an extra overhead
of a function call.

I would also like to note that

   arglist = {args{1:narg-1}, x+a*dx, args{narg+1:end}};
   fx = feval (f,arglist{:});

can be simply written as

   fx = feval (f, args{1:narg-1}, x+a*dx, args{narg+1:end});

i.e. you can use more than one cs-lists in an expression.


-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

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

_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to