octave-maintainers
[Top][All Lists]
Advanced

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

FYI: improved indexing error messages


From: Jaroslav Hajek
Subject: FYI: improved indexing error messages
Date: Sat, 27 Feb 2010 08:49:17 +0100

hi all,

by the change
http://hg.savannah.gnu.org/hgweb/octave/rev/e5ae13b8b2c2
I improved error messages for indexing to be more informative.

the following commands

a = zeros (8, 1);
a(10)
a(12) = []
a = zeros (8);
a(9, 5)
a(4, 11)
a(14, :) = []
a = zeros (5, 5, 5);
a(1, 3, 6)
a(7, 2, 3)
a(:, :, 6) = []

now produce the following messages:

octave:1> a = zeros (8, 1);
octave:2> a(10)
error: A(I): index out of bounds; value 10 out of bound 8
octave:2> a(12) = []
error: A(I) = []: index out of bounds; value 12 out of bound 8
octave:2> a = zeros (8);
octave:3> a(9, 5)
error: A(I,J): row index out of bounds; value 9 out of bound 8
octave:3> a(4, 11)
error: A(I,J): column index out of bounds; value 11 out of bound 8
octave:3> a(14, :) = []
error: A(..,I,..) = []: index out of bounds; value 14 out of bound 8
octave:3> a = zeros (5, 5, 5);
octave:4> a(1, 3, 6)
error: A(I,J,...): index to dimension 3 out of bounds; value 6 out of bound 5
octave:4> a(7, 2, 3)
error: A(I,J,...): index to dimension 1 out of bounds; value 7 out of bound 5
octave:4> a(:, :, 6) = []
error: A(..,I,..) = []: index out of bounds; value 6 out of bound 5

previously, octave gave the same message for all cases:

octave:1> a = zeros (8, 1);
octave:2> a(10)
error: A(I): Index exceeds matrix dimension.
octave:2> a(12) = []
error: A(I): Index exceeds matrix dimension.
octave:2> a = zeros (8);
octave:3> a(9, 5)
error: A(I): Index exceeds matrix dimension.
octave:3> a(4, 11)
error: A(I): Index exceeds matrix dimension.
octave:3> a(14, :) = []
error: A(I): Index exceeds matrix dimension.
octave:3> a = zeros (5, 5, 5);
octave:4> a(1, 3, 6)
error: A(I): Index exceeds matrix dimension.
octave:4> a(7, 2, 3)
error: A(I): Index exceeds matrix dimension.
octave:4> a(:, :, 6) = []
error: A(I): Index exceeds matrix dimension.
octave:4>

rebuilding with this change, you may notice a few test failing. These
rely on the exact format of the error message, as was used before. I
didn't simply fixed those because I think we need a more general
solution, rather than relying on a particular format. It would be best
if we could throw the error with a particular ID, but there are two
obstacles:

1. liboctave currently can't throw errors with a particular ID
(there's warning_with_id, but no error_with_id)
2. I think the test mechanism doesn't support IDs either.

should we fix these two? Or does someone have a better idea?

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


reply via email to

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