bugGNU Octave - Bugs: bug #56609, rand(n) accepts non-integral (n)


bug #56609: rand(n) accepts non-integral (n)

Submitted by:  A.R. Burgers <arb>
Submitted on:  Thu 11 Jul 2019 06:36:53 AM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

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


Sat 13 Jul 2019 02:55:58 AM UTC, comment #2: 

I checked in a fix in this cset (https://hg.savannah.gnu.org/hgweb/octave/rev/84cdeeaf0dce).

CLosing report.

Rik <rik5>
Project Administrator
Thu 11 Jul 2019 03:22:42 PM UTC, comment #1: 

Matlab used to be quite loose about input validation and so Octave copied that behavior for rand.  Also note that this looseness is only present when there is a single dimension argument.  If more than one dimension is specified then they must all be non-negative integers.  For example,

rand (1.5, 3)
error: rand: conversion of 1.5 to int64_t value failed

The code to change is in rand.cc at line 171.

else if (tmp.is_scalar_type ())
    double dval = tmp.double_value ();

    if (octave::math::isnan (dval))
      error ("%s: NaN is invalid matrix dimension", fcn);

    dims.resize (2);

    dims(0) = dims(1) = octave::math::nint_big (dval);

    goto gen_matrix;

Rik <rik5>
Project Administrator
Thu 11 Jul 2019 06:36:53 AM UTC, original submission:  

octave accepts rand(2.5), not eye(2.5). octave seems to do rand(round(n))

octave:11> version
ans = 5.1.1
octave:12> eye(2.5)
error: eye: conversion of 2.5 to int value failed
octave:12> rand(2.5)
ans =

   0.45678   0.59128   0.71431
   0.74580   0.18234   0.58583
   0.61076   0.82043   0.76781


>> rand(2.5)
Error using rand
Size inputs must be integers.

A.R. Burgers <arb>


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

Attach Files:

No files currently attached


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 arb (Submitted the item)

    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
    2019-07-13 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2019-07-11 rik5 StatusNone => Confirmed
        Release5.1.0 => dev

    Back to the top

    Powered by Savane 3.5