On Fri, May 7, 2010 at 4:08 PM, Alois Schlögl <[email protected]> wrote:
> Jaroslav Hajek wrote:
>>
>> On Thu, May 6, 2010 at 10:24 PM, Alois Schlögl <[email protected]>
>> wrote:
>>>
>>> After looking further into the problem of converting octave code into a
>>> matlab compatible syntax, I concluded that in some cases it is easiest
>>> way
>>> to make the source code compatible. In some cases, there is just no way
>>> to
>>> make an automated conversion. E.g there is no good way to convert  while
>>> (k++ == N) in a automated way. Converting the source code is a simpler
>>> and
>>> more straight forward way.
>>>
>>> The attached patch is doing this. The difficult cases like ++, --, +=,
>>> -=,
>>> /=, &=, *=, |=, and do-until are replaced. Most of the octave specific
>>> syntax (like endfor, endwhile, ## comment, etc.) stays in place.
>>>
>>> Are there are any objections on committing this patch ?
>>>
>>
>> Sure, I object. The computed assignment operators can be treated more
>> efficiently by Octave than their decomposed versions,
>> so I advise everyone to not decompose them unless they really need
>> Matlab compatibility, and I certainly don't want such changes be made
>> in any of the packages I use or maintain.
>> Likewise, indexing expressions in place often makes things more
>> readable and also more efficient (because the temporary is deallocated
>> as soon as it's not needed).
>>
>> FWIW, I don't think += etc. are difficult cases. I just committed a
>> few improvements to oct2mat that makes it attempt to Matlabize some of
>> these constructs. Trying this:
>>
>> b(1,:) += c(2,:);
>> [cols{1:3}] = num2cell (mat){:};
>> if(all((BW2==BW & BW != 0)(:)))
>>  k *= 2 + a;
>>  sub{d} += incr;
>> endif
>> k.x(1,:) += conv (x, y)(:) - [1; a](:);
>>
>>
>> oct2mat gives me:
>>
>> b(1,:) = b(1,:) + c(2,:);
>> o2m_tmp_1 = num2cell (mat);
>> [cols{1:3}] = o2m_tmp_1{:};
>> o2m_tmp_2 = (BW2==BW & BW ~= 0);
>> if(all(o2m_tmp_2(:)))
>>  k = k * (2 + a);
>>  sub{d} = sub{d} + incr;
>> end
>> o2m_tmp_3 = conv (x, y);
>> o2m_tmp_4 = [1; a];
>> k.x(1,:) = k.x(1,:) + o2m_tmp_3(:) - o2m_tmp_4(:);
>>
>> chained assignments and do-until should also be doable.
>>
>> regards
>>
>
>
> Jaroslav,
>
>
> thanks for trying to improve oct2mat. Unfortunately, it does not work with
> me.
>
> When I use mawk, I got this error:
>  $ ./oct2mat test_oct2mat.m
>  awk: ./oct2mat: line 367: function gensub never defined
>  awk: ./oct2mat: line 367: function gensub never defined
>

Yeah, right, gensub is gawk extension. Unfortunately, sub and gsub
don't support the positional captures.

> gawk runs without error but gave this result.
>
> b(1,:) += c(2,:);
> o2m_tmp_1 = (mat);
> [cols{1:3}] = num2cell o2m_tmp_1{:};
> o2m_tmp_2 = (BW2==BW & BW ~= 0);
> if(all(o2m_tmp_2(:)))
>  k *= 2 + a;
>  sub{d} += incr;
> end
> o2m_tmp_3 = (x, y);o2m_tmp_4 = [1; a];
>
> k.x(1,:) += conv o2m_tmp_3(:) - o2m_tmp_4(:);
>

Hmmm. It worked well for me. What's your gawk version?


-- 
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to