octave-patch-tracker
[Top][All Lists]
Advanced

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

[Octave-patch-tracker] [patch #8119] Allow variable tolerance and improv


From: Dan Sebald
Subject: [Octave-patch-tracker] [patch #8119] Allow variable tolerance and improve error messages for assert.m script
Date: Wed, 07 Aug 2013 23:20:51 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15

Follow-up Comment #16, patch #8119 (project octave):

I think I knew that already about deletion versus indexing, from decades ago
perhaps.

Generally, eval() is slow (maybe it needs to be improved internally), but
using it could be to advantage if it achieves something in a more efficient
way than can be done otherwise.  I sought a way to keep the eval outside of a
loop.  The amount of material inside of a loop is often the most critical
thing when the loop has many iterations, and avoiding an interpreted loop by
using a loop internal to the command is best.  Your proposal has ind2sub() and
sprintf() inside the loop.

We can put the two evals into one eval:


oarg = sprintf ("i%d ", 1:ndims (A));
eval (cstrcat ("[", oarg, "] = ind2sub (size (A), find (A != B)); ", ...
               "idx = [", oarg, "];"));
for i = 1:length (i1)
  loc = sprintf("%d,", idx (i,:));
end


Here are some timing comparisons for when the loop is small:


>> A = ones(4);
>> B = zeros (size (A));
>>
>> err.reason = cell (sizeof (A), 1);
>> t_start = cputime ();
>>
>> oarg = sprintf ("i%d ", 1:ndims (A));
>> eval (cstrcat ("[", oarg, "] = ind2sub (size (A), find (A != B)); ", ...
               "idx = [", oarg, "];"));
>> for i = 1:length (i1)
  loc = sprintf("%d,", idx (i,:));
  err.reason {i} = ["(" loc(1:end-1) ")"];
endfor
>>
>> cputime () - t_start
ans =  0.049992
>>
>> err.reason = cell (sizeof (A), 1);
>> t_start = cputime ();
>>
>> erridx = find (A != B);
>> sz = size (A);
>> nd = ndims (A);
>> subs = cell (1, nd);
>> for idx = erridx(:).'
  [subs{:}] = ind2sub (sz, idx);
  loc = sprintf("%d,", subs{:});
  err.reason {i} = ["(" loc(1:end-1) ")"];
endfor
>>
>> cputime () - t_start
ans =  0.043994


and for when the loop is large:


>> A = ones(10,10,10,10,10);
>> B = zeros (size (A));
>>
>> err.reason = cell (sizeof (A), 1);
>> t_start = cputime ();
>>
>> oarg = sprintf ("i%d ", 1:ndims (A));
>> eval (cstrcat ("[", oarg, "] = ind2sub (size (A), find (A != B)); ", ...
               "idx = [", oarg, "];"));
>> for i = 1:length (i1)
  loc = sprintf("%d,", idx (i,:));
  err.reason {i} = ["(" loc(1:end-1) ")"];
endfor
>>
>> cputime () - t_start
ans =  7.2319
>>
>> err.reason = cell (sizeof (A), 1);
>> t_start = cputime ();
>>
>> erridx = find (A != B);
>> sz = size (A);
>> nd = ndims (A);
>> subs = cell (1, nd);
>> for idx = erridx(:).'
  [subs{:}] = ind2sub (sz, idx);
  loc = sprintf("%d,", subs{:});
  err.reason {i} = ["(" loc(1:end-1) ")"];
endfor
>>
>> cputime () - t_start
ans =  9.4526


Which is slightly faster isn't that critical really as this pertains to the
case where a test fails, which is supposed to be rare.

I will make another pass at the changeset (may be this weekend).


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?8119>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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