bugGNU Octave - Bugs: bug #35157, Naive users baffled by...

 
 

bug #35157: Naive users baffled by "complex scalar type invalid as index value"

Submitted by:  Clem <clemwang>
Submitted on:  Fri 23 Dec 2011 03:00:56 AM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Clem Open/Closed:  Closed
Release:  3.4.0 Operating System:  Mac OS

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Sun 01 Jan 2012 07:09:39 PM UTC, comment #18: 
Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Sat 31 Dec 2011 04:13:29 AM UTC, comment #17: 

The proposed patch looks good.  What about adding a test for the new behavior to test_index-wfi-f.m?

%!shared x
%! x = 1:5;
%!error <attempted to use a complex scalar as an index> x(i)
%!error <attempted to use a complex scalar as an index> x(j)
%!error <attempted to use a complex scalar as an index> x(1+i)

Rik <rik5>
Project Administrator
Fri 30 Dec 2011 04:45:59 AM UTC, comment #16: 

How about the attached patch? With I get the following:

octave:1> x = rand(2)
x =

   0.14818   0.29744
   0.54033   0.76772

octave:2> x(i)
error: attempted to use a complex scalar as an index
       (forgot to initialize i or j?)
octave:2> x(1+i)
error: attempted to use a complex scalar as an index
       (forgot to initialize i or j?)

(file #24712)

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Tue 27 Dec 2011 08:00:01 PM UTC, comment #15: 

FWIW, matlab is as follows:

>> a(i)
??? Subscript indices must either be real positive integers or logicals.

which fully corresponds to Michael's view that a(i) should be no different than a(pi), and which is probably the least confusing and most helpful message.

Muhali <muhali>
Fri 23 Dec 2011 10:08:12 PM UTC, comment #14: 

I very gratified that so many people are interested in this issue!

I didn't know about the command


help --list

I would suggest that the --list option that be shown when you just type help.  It's not now, at least in 3.4.0:

help
>> help

  For help with individual commands and functions type

    help NAME

  (replace NAME with the name of the command or function you would
  like to learn more about).

  For a more detailed introduction to GNU Octave, please consult the
  manual.  To read the manual from the prompt type

    doc

  GNU Octave is supported and developed by its user community.
  For more information visit http://www.octave.org.

(Should I make a bug report for that?)

Also....  I don't know how to get this done, but the binary builds are often behind and/or incomplete.   3.4.0 is the most recent Mac binary and it comes with the doc command inactivated. (I think Jordi told me that.)

>> doc true
info: Cannot find node `Top'.
info: Cannot find node `Top'.

I know this is a sensitive subject, but I found it was not easy building Octave on my own, which makes it even more important to make the latest binaries available to those students taking the two Stanford Classes as well as others.

A few of the students in ml-class.org struggled because in the past semester because only Windows binary available was the older Windows version 3.2.4.  I'm glad to see 3.4.3 is now available for Windows from Octave Forge, which is just in time for the new Semester classes for ml-class.org and pgm-class.org.  I note that the Mac binary is still at 3.4.0, but I won't complain as that's pretty close to 3.4.3.

I'll be taking pgm-class.org, so I will endeavor to relay any useability issues to the bug list.

I will say that my impression is that most of the students were pretty happy with using Octave.  So, on behalf of my fellow students taking ml-class.org, thanks a lot for building a great system for us to use.  It made a big difference in our learning of Machine Learning.

Clem <clemwang>
Fri 23 Dec 2011 08:31:35 PM UTC, comment #13: 

One thing to remember is that it is the typeinfo of the index expression which is being checked, not the actual characters 'i' or 'e'.  For example:

a = [1:3];
idx = i;
a(idx)

error: complex scalar type invalid as index value

I agree with Jordi that it is useful to know why the index expression is failing.  In some cases the expression may be very complex (pun intended) and it would be useful in debugging to have this extra information.

As for the problem with 'doc XXX', I fixed that in this changeset on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/8a2dc08886ea)

Rik <rik5>
Project Administrator
Fri 23 Dec 2011 06:27:58 PM UTC, comment #12: 

One more thing:

doc i    takes you to advanced indexing
doc I    takes you to the i (I,j,J) functions
         in the Math Constants
doc j and
doc J    take you to the graphics functions

The behavior of i, j, and J could be considered
a bug.

I now remember why I try never to use i, I, j, J
as variables.  This is probably "well-known"?

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 06:10:53 PM UTC, comment #11: 

Well, I just discovered the: help --list
command.  Very useful and very verbose.
And, it appears at an appropriate place
in the Manual (but, who reads Manuals?).

I suspect that not many of the thousands of students
(and staff!!) on the ML course got to know about
help --list.

So, the error message that started this thread
might usefully point out that the argument is a
built-in function of an invalid type, and, maybe,
refer to the right place in the Manual.

Anyhow, after a few false starts, reading the Manual
has proved pretty useful!

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 05:49:12 PM UTC, comment #10: 

>>Furthermore, the reason you don't see i and j as variables is because by default they're not.


Right, and exist actually says that.  But, this does not seem
to be widely known.  At least, a Section in the Manual titled
something like "Initial definitions"  would be a help.  And,
a way to keep it in sync with the code would be very nice.

pi is also a function.  Another thing that I did not know
until now!

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 05:36:55 PM UTC, comment #9: 

I don't see a reason to not provide a more specific error message if it's something that is already being checked for.

Also, given the frequency with which i and j are chosen as index variable, I think a(i) is provoking an error far more frequently than a(e) is.

Furthermore, the reason you don't see i and j as variables is because by default they're not. They're in fact functions, and when you do i = 1, you're shadowing function.  You can do i(2,5) with i's default value, for example, to get a matrix full of i.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Fri 23 Dec 2011 05:32:48 PM UTC, comment #8: 

It is not clear that i and j should be special cases.
How about pi, e, etc...?

By the way:
octave:1> a(pi) =1
error: subscript indices must be either positive integers or logicals

This message seems to be pretty popular already....

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 05:08:43 PM UTC, comment #7: 

I kind of like that the error message explicitly recognises that you used non-real values. I think that should be kept.

However, I was thinking this might be better:

error: complex scalar type invalid as index value (forgot to assign a value to i or j?)

The a(i) and a(j) mistake for default values of i and j is probably common enough that explicitly asking the user if that's the mistake might be useful.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Fri 23 Dec 2011 05:06:49 PM UTC, comment #6: 

An afterthought:

who and whos do not list the predefined variables. exist
tells you the right answer, for example:
octave:5> exist i
ans =  5

but
octave:8> exist
error: Invalid call to exist.  Correct usage is:

 -- Built-in Function:  exist (NAME, TYPE)

Maybe extending exist would be a good choice?

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 04:59:13 PM UTC, comment #5: 

There will always be people who do not read or
understand error messages.  But, the messages should be
made clearer, simpler, and more precise whenever possible.

In this case I agree that the error message was not clear,
and the suggested improvement was not much better.

Many users are not clear about what variables are predefined.

A simple improvement in this case would be to use the message
that you get for:

octave:1> a(1.23)=1
error: subscript indices must be either positive integers or logicals
octave:1>

instead of:
octave:1> a(j)=1
error: complex scalar type invalid as index value
error: assignment failed, or no method for `<unknown type> = scalar'
octave:1>

Note this case:
octave:1> a(e)=1
error: subscript indices must be either positive integers or logicals
octave:1>

It does not make sense to treat "e" differently from "i" or
"j".

Somewhat related to this, I tried to lookup what variables
are predefined in Octave.  I could not find a Section in
the Manual that lists these, nor did searches of the pdf
find anything.  Ideally, such a Section should be generated
from the current Octave code.  And, a command ("predefined" ?)
would be useful.

Does anyone know where to start in the source files to find
them all?

Michael Godfrey <godfrey>
Project Member
Fri 23 Dec 2011 08:16:34 AM UTC, comment #4: 

I'm not adverse to making Octave more accessible. It's just that I don't think this change does that. I don't see any evidence in the four that you posted that the people tried to understand the error message. For a lot of people, error messages are invisible and meaningless gibberish, regardless of what you write there. This is evident by how frequently we have to ask "what's the error message?" when people say "Octave crashes, help" or "something is wrong, help". People are so used to not understanding some or most error messages that they learn to ignore all of them, unless they are blindingly bad (everyone in the class jumped when "division by zero" was mentioned by the fminunc code).

In the four examples you posted, the people seemed to have stopped reading as soon as they faced an error message and made no visible attempt to understand it. I don't think the mention of complex numbers confused them any further. It simply happened to be a common error people encountered in this class, but I don't think the wording of the error is bad.

The most useful error message could be "default uninitialised non-real value of `i' used as an index value", or something like that which explicitly says that i was uninitialised and used as an index. However, it would require some hacks in the parser to recognise the a(i) and a(j) indexing forms and throw an error about them. It would require a more thorough patch than just finding the current error message and rewording it.

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Fri 23 Dec 2011 07:38:12 AM UTC, comment #3: 

Hi Jordi-

I think the size and composition of Octave's user base has shifted a bit, now that Prof Ng is using it to teach his very popular Stanford Machine Learning course last semester and next semester.  Prof Koller will be teaching another free Stanford course (pgm-class.org) next semester that uses Octave.  Anyone in the world can sign up for these free classes.  Tens of thousands have!

I followed the class forums quite a bit.  I saw that a number of people had a lot of catching up to do: a few people asking "what is e?"  There was at least one enterprising High School student in the mix.  So, there's plenty of opportunity for confusion now that the flood gates are open.

So, for better or worse, Octave is getting a big boost in popularity and some of those users need more help than Octave users in the past.  Some users are actually reasonably knowledgeable, but are unused to vectorization and their Linear Algebra is very rusty or even non-existent.

Heck, I'll even confess that I was momentarily confused by this error message, but I figured it out after a moment or two since complex numbers were not foremost on my mind.  I wouldn't have felt insulted by my proposed error message, although I did feel a little silly making the mistake in the first place...

I would agree with a premise that Octave shouldn't be "dumbed down" to help those who probably shouldn't be using it in the first place, but a lot of people will be using it for the first time.  IMHO, a little extra help that doesn't get in the way of the experienced user would be ideal.

Here are a few instances of people specifically getting confused by this error message.  For some of these people, English isn't their first language, so the capitalization would be helpful.  I hope this helps convince you of the need.

Omar posted this:

http://www.ml-class.org/course/qna/view?id=3493

using y alone is not working 101 not comfort with 50001

also using y(i) complex scalar type

also using(y==i)(i) complex scalar type

what should i do ?!

And Simone appears to be confused here:
http://www.ml-class.org/course/qna/view?id=4781

Hi everyone, I keep getting this error when running recoverdata.m : error: complex scalar type invalid as index value

And Ari was confused here:

http://www.ml-class.org/course/qna/view?id=4575

But unfortunately it's giving me the error: complex scalar type invalid as index value

Can anybody please tell me where I'm making the mistake.

And Pol is puzzled in this post:

http://www.ml-class.org/course/qna/view?id=2868

despite it is accepted by the course my error now (when finishing the 50th iteration of the first label) is the following:

Iteration 50 | Cost: 1.359936e-02 error: complex scalar type invalid as index value error:

Clem <clemwang>
Fri 23 Dec 2011 07:23:02 AM UTC, comment #2: 

Sorry, typo, I meant "wording" instead of "working".

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Fri 23 Dec 2011 06:34:04 AM UTC, comment #1: 

I think that working (especially with the Capital Letters) may be a little insulting to most Octave users, as if they didn't know what complex numbers are. I can't imagine any Octave user thinking that "complex scalar" means "complicated scalar". Do you have any evidence that such a user exists?

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
Fri 23 Dec 2011 03:00:56 AM UTC, original submission:  

The free Stanford Machine Learning Class (ml-class.org) used Octave with very good results, so thousands thank you for all your hard work on Octave.

However, some students do not have a good background in mathematics.

A not uncommon error was to use i as an index variable and forget to initialize it, leading to an error like this:

a = [1 2 3]
a(i)
error: complex scalar type invalid as index value

To the naive user, the word "complex" first suggests "complicated" and not "A number from the Complex Number Set".

I suggest an alternate wording (with capitalizations):

error: index values must not be from the Set of Complex Numbers.

Admitted a small, five minute change, but it would save a few people-hours of frustration and confusion.

Thanks

Clem <clemwang>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #24712:  clx-idx.patch added by jordigh (864B - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by clemwang (Submitted the item)
  • -email is unavailable- added by clemwang
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-01-01 jordigh StatusNone => Fixed
        Open/ClosedOpen => Closed
    2011-12-30 jordigh Attached File- => Added clx-idx.patch, #24712
    2011-12-23 clemwang Carbon-Copy- => Added clem@clem.com

    Back to the top


    Powered by Savane 3.5