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 06:21:32 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15

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

Let's try that again...

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

> 1) Instead of simply saying the dimensions don't match we could actually
list
> them.  Sample format would be "1x3x5".  The following code will create this
> format.

That would be a good idea.


> dimstr = sprintf ("%dx", size (cond));
> dimstr(end) = []; # remove trailing 'x'

Good use of sprintf, but rather than removing the last character that way,
just reference dimstr(1:end-1) at the location it is used.  This would work
too:

dimstr = sprintf ("%dx", size (cond)) (1:end-1);

but somehow I prefer using the (1:end-1) construct at the point the array is
used.


> 2) Absolute error uses the expression "Exceeds abs tol 0 by ..." while
> relative tolerance uses "Max rel err %g exceeds tol %g".  They should both
use
> the same format whatever it is.

I saw that, but didn't feel like changing it until we thought things were
heading in the right direction.  I'll have to look closely at what that last
variation is doing.  Maybe I could express this more accurately and briefly.


> 3) Multi-dimensional arrays aren't handled properly.
> 
> 
> x = zeros (2,2,3);
> y = x;
> y(1,2,3) = 1;
> assert (x,y)
> error: ASSERT errors for:  assert (x,y)
> 
>    Location  |  Observed  |  Expected  |  Reason
>     [1,6]          0            1         Exceeds abs tol 0 by 1

I didn't think to check three dimensions.


> It's kind of lame, but I think you can use sub2ind to do this.
> 
> 
> erridx = find (x != y);
> if (any (erridx))
>    sz = size (x);
>    nd = ndims (x);
>    subs = cell (1, nd);
>    for idx = erridx(:).'
>      [subs{:}] = ind2sub (sz, idx);
>      loc = ['(' sprintf("%d,", subs{:}) ];
>      loc(end) = ')';
>      ... print location and error ...
>    endfor
> endif

Let me think it over.  Maybe you noticed one small change I made between
versions, which was to use the multiple output argument version of find().  I
had computed the index similar to what you are suggesting (it's not
difficult), but I found


          [I, J] = find (A != B & k);


much more convenient to work with.  And I notice now that this works:


>> A = ones(2,2,3);
>> B = A;
>> B(1,1,1) = 0;
>> B(2,2,2) = 0;
>> [i j k] = find (A != B)
i =

   1
   2

j =

   1
   4

k =

   1
   1


But doesn't that look like a bug?  No dimensions of the matrix in this example
go beyond 3, so how could j be 4?  i j and k should be the same, [1 2]'.

Let's assume that is a bug and that we should be able to get the correct
indeces that way.  So, maybe it would be more convenient to use something
like:


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


How's that?  For this example, I'll print the results of some of the above
commands and intermediate strings:


>> oarg = sprintf ("i%d ", 1:ndims (A))
oarg = i1 i2 i3
>> cstrcat ("[", oarg, "] = find (A != B);")
ans = [i1 i2 i3 ] = find (A != B);
>> eval (cstrcat ("[", oarg, "] = find (A != B);"));
>> cstrcat ("idx = [", oarg, "];")
ans = idx = [i1 i2 i3 ];
>> eval (cstrcat ("idx = [", oarg, "];"));
>> for i = 1:length (i1)
  loc = sprintf("%d,", idx (i,:)) (1:end-1)
end
loc = 1,1,1
loc = 2,4,1


    _______________________________________________________

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]