bugGNU Octave - Bugs: bug #55249, function ones does not always...

 
 

bug #55249: function ones does not always return a valid matrix

Submitter:  Anders Lennartsson <andersbertil>
Submitted:  Wed 19 Dec 2018 10:40:35 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 21 Dec 2018 02:03:05 PM UTC, comment #5: 

Thanks for looking into this. I will adapt my oct-code for the case of ranges. This bug report can be closed.

Anders Lennartsson <andersbertil>
Thu 20 Dec 2018 06:49:17 PM UTC, comment #4: 

I tried playing around in Matlab to see if there were any compatibility issues, and couldn't come up with any. If this is expected behavior, can anyone come up with a specific problem, or compatibility tests that would indicate any problems with the current operation?

Nicholas Jankowski <nrjank>
Group Member
Thu 20 Dec 2018 05:08:25 PM UTC, comment #3: 

There are no visible indications because the difference is supposed to be completely internal. An ordinary user at the Octave command line should not need to know whether a row of ones is a true row vector or a range, they are identical from a behavior point of view.


>> A = ones (1, 100);
>> B = [A];
>> C = repmat (1, 1, 100);
>> isequal (A, B)
ans = 1
>> all (A == B)
ans = 1
>> isequal (A, C)
ans = 1
>> all (A == C)
ans = 1


Mike Miller <mtmiller>
Group Member
Thu 20 Dec 2018 08:18:34 AM UTC, comment #2: 

Thanks for the quick response.

After reading the manual, no what I reported is not a bug.

Although after some investigation, it would be useful if such ranges by default were printed in a way as to indicate that they are ranges instead of being printed as expanded row vectors. There are no visible indications of a difference between the following:
octave:15> ones(1,4)
ans =

   1   1   1   1

octave:16> [1 1 1 1]
ans =

   1   1   1   1


Moreover, why does not zeros(1,n) return a range? It may be less useful but the inconsistency this creates seems a bit dull at first glance. For example,
zeros(1,4)+1 is identical to [ones(1,4)]
and ones(1,4)-1 is not identical to zeros(1,4) although visibly indistinguishable.





Anders Lennartsson <andersbertil>
Wed 19 Dec 2018 11:14:39 PM UTC, comment #1: 

Thank you for the detailed bug report. What you are seeing is correct, but Octave does this intentionally. When the function 'ones' is called as 'ones(1,N)' for any N, Octave intentionally returns a "range" type instead of a fully allocated row vector. The "range" type is documented in the user manual at http://octave.org/doc/interpreter/Ranges.html.

To force conversion of a range into a normal matrix variable, you can use any of the following:


c = [c];
c = horzcat (c);


and other similar operations.

The range type is an intentional optimization that is supposed to save memory, look like a matrix, and transparently expand itself to a matrix when needed.

Does this information address the issue for you, or do you still think that this is a bug?

Mike Miller <mtmiller>
Group Member
Wed 19 Dec 2018 10:40:35 PM UTC, original submission:  

The function ones seems to return an object which is not always a matrix.

With Octave 4.4.1-2~bpo9+1 running on Debian I can recreate the problem as follows:

a=linspace(-2,2,6)
b=ones(length(a),1)
c=ones(1,length(a))
d=[1 1 1 1 1 1]
ff=zeros(1,length(a))


Everything looks fine, but checking the variables with an extended version of paramdemo.cc, it turns out that c is not a matrix although a, b, d and ff passes the test.

The code for paramdemo.cc is attached as a file. It was compiled with gcc 6.3.0 on Debian stretch by mkoctfile paramdemo.cc

Output for the 4 variables that are matrices is

Number of input arguments  : 1
Number of output arguments : 0
Argument is of type numeric.
  Argument is a matrix.
    Argument number of dimensions are : 2
    Dimension 0 is : 1
    Dimension 1 is : 6
    Number of ones : 1
    Chopping trailing singletons.
    Argument number of dimensions are : 2
    Number of ones : 1
    Chopping all singletons.
    Argument number of dimensions are : 2
    Number of ones : 1
    Dimension 0 is : 6
    Dimension 1 is : 1
    vector length is 6.
    Argument is vector: 1
    Argument length: 2
    Argument num_ones: 1
  real matrix
    vector length is 6.
    Argument is vector: 1
    Argument length: 2
    Argument num_ones: 1
Properties of input array:
  includes only int, Inf or NaN values
  includes only integers in [-10,10]



while output for the variable c is

Number of input arguments  : 1
Number of output arguments : 0
Argument is of type numeric.
Properties of input array:
  includes only int, Inf or NaN values
  includes only integers in [-10,10]


If c is added to zeros(1,length(a)) the result passes the test.

As I do not see any use case for this behaviour, it seems this is a bug.

Anders Lennartsson <andersbertil>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #45701:  paramdemo.cc added by andersbertil (4KiB - text/x-c++src)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by andersbertil (Submitted the item)
  • -email is unavailable- added by andersbertil
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-12-21 rik5 StatusNone Works For Me
        Open/ClosedOpen Closed
    2018-12-19 andersbertil Attached File- Added paramdemo.cc, #45701
        Carbon-Copy- Added andersbertil

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code