bugGNU Octave - Bugs: bug #34536, isvector gives wrong answer when...

 
 

bug #34536: isvector gives wrong answer when checking function_handle

Submitted by:  Juan Pablo Carbajal <juanpi>
Submitted on:  Wed 12 Oct 2011 12:40:16 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: Wont FixAssigned to: None
Originator Name: juanpiOpen/Closed: Closed
Release: 3.4.3Operating System: GNU/Linux

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 Jump to the original submission)

Wed 26 Oct 2011 04:19:13 AM UTC, comment #10:

I know this seems confusing, but this definition of array is just the way Matlab and Octave work.

Unfortunately, the docstring for arrayfun can't be changed to say "numerical array" because "numeric" has a very specific meaning in Octave. See the documentaion for isnumeric

Changing arrayfun to say that it operates on numerical arrays would imply that it does not work on logical or character arrays. This is not the case.

Rik <rik5>
Project Administrator
Wed 12 Oct 2011 01:54:35 PM UTC, comment #9:

To make it concrete

> accumarray(1,1)

ans = 1
octave:61> accumarray(1,@sin)
error: accumarray: wrong type argument `function handle'

>isvector(@sin)

ans = 1

> help accumarray

Create an array by accumulating the elements of a *vector* into the positions defined by their subscripts. The subscripts are defined by the rows of the matrix SUBS and the values by VALS.

Do you see what I mean?

Juan Pablo Carbajal <juanpi>
Project Member
Wed 12 Oct 2011 01:44:33 PM UTC, comment #8:

I see.
So accepting Array is an N-d (with N>=2) collection of object that can be indexed. Then docstring of accumarray and arrayfun should be corrected to say they work on "numerical arrays".

arrayfun.m:
"Execute a function on each element of an array" --> "Execute a function on each element of a numerical array"

accumarray.m:
"Create an array by accumulating the elements of a vector into the positions defined by their subscripts." --> "Create an numerical array by accumulating the elements of a numerical vector into the positions defined by their subscripts."

But I guess "numerical array" is equivalent to "matrix" and "numerical vector" is equivalent to "row matrix" or "column matrix".

Juan Pablo Carbajal <juanpi>
Project Member
Wed 12 Oct 2011 01:36:46 PM UTC, comment #7:

You can also store function handles in struct arrays.

Not all functions work on all types.

The current doc string says:

Return true if X is a vector. A vector is a 2-D array where one of the dimensions is equal to 1. As a consequence a 1x1 array, or scalar, is also a vector.

I think you have a different idea of what "array" means than I do. In Octave, an array is just an N-d (with N >= 2) collection of objects that can be indexed. Array does not necessarily imply a numeric object. If it did, we would not have "cell arrays".

So I don't really see any bug to fix here.

John W. Eaton <jwe>
Project Administrator
Wed 12 Oct 2011 01:11:08 PM UTC, comment #6:

Then imho, the docstring of isvector should say
"A vector is a 2-D arrangement of octave types where one of the dimensions is equal to one"

and not use the word "Array" since it has a very clear meaning like in arrayfun.

also accumarray will not work is the "vector" argument (according to its docstring) is a cell. Therefore there it seems a cell (only container for function handles that I knwon) is not a vector.

Juan Pablo Carbajal <juanpi>
Project Member
Wed 12 Oct 2011 01:09:24 PM UTC, comment #5:

Every object in Octave has a minimum of two dimensions.

Anything that is 1xN or Nx1 is a vector, including objects whose dimensions are 1x1.

is not valid because you can't concatenate function handle objects. They can only be 1x1.

John W. Eaton <jwe>
Project Administrator
Wed 12 Oct 2011 01:02:12 PM UTC, comment #4:

Matlab gives me

>> isvector (@sin)

ans =

1

Søren

Søren Hauberg <hauberg>
Wed 12 Oct 2011 12:58:16 PM UTC, comment #3:

Ok, then the docstring should be more specific and say
"As a consequence a 1x1 array, or scalar, or function_hanlde is also a vector."

Since the default vectors and scalars are numeric and because the following is not valid

[@ischar; @isvector]

Are cells also arrays?
Since isvector(cell(1,N)) or isvector(cell(N,1)) also gives true and the docstring of isvectors says
"A vector is a 2-D array"

Juan Pablo Carbajal <juanpi>
Project Member
Wed 12 Oct 2011 12:49:10 PM UTC, comment #2:

But

is 1, so it is a scalar and a vector, just not a numeric one.

WDMD?

John W. Eaton <jwe>
Project Administrator
Wed 12 Oct 2011 12:43:16 PM UTC, comment #1:

Same applies to function isscalar

Juan Pablo Carbajal <juanpi>
Project Member
Wed 12 Oct 2011 12:40:16 PM UTC, original submission:

Hi the following code fails.

a=@(x) ischar (x);
assert ( !isvector (a) );

It shouldn't. (checked in 3.4.3-rc0 and dev changeset: 1e12601d2697, tag:tip)

Thanks

Juan Pablo Carbajal <juanpi>
Project Member

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by hauberg (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by juanpi (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 26 Oct 2011 04:19:13 AM UTCrik5StatusNone=>Wont Fix
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1