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: Rik
Subject: [Octave-patch-tracker] [patch #8119] Allow variable tolerance and improve error messages for assert.m script
Date: Thu, 08 Aug 2013 19:28:00 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0

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

You can use the same trick that you used on your code, pulling the sub2ind
call out of the loop, on my code as well.  The following runs in equivalent
time without the eval call.


erridx = find (A != B);
err.reason = cell (numel (erridx), 1);
tmp = cell (1, ndims (A));
[tmp{:}] = ind2sub (size (A), erridx);
subs = [tmp{:}];

for i = 1:numel (erridx)
  loc = sprintf ("%d,", subs(i,:));
  err.reason{i} = ["(" loc(1:end-1) ")"];
endfor


It is faster for large erridx, but slower than the original code for small
numbers of elements.  The crossover is ~18 elements.  At that point the total
time is ~4 milliseconds.  So, probably it's not worth switching over given
that most assert statements never report errors, and if they do it is only for
a few elements.

If you really want to speed things up you can do a time/memory tradeoff and
bring the sprintf out of the loop as well.  One call to sprintf to generate a
whole list of strings and then index into the strings in the loop.  This
produces a 4X savings on large matrices, but those aren't the norm.  On
benchmarking, the crossover is still around 18 elements.


    _______________________________________________________

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]