bugGNU Octave - Bugs: bug #37390, In matlab repmat can have empty...

 
 

bug #37390: In matlab repmat can have empty inputs

Submitter:  None
Submitted:  Tue 18 Sep 2012 10:16:45 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  bpabbott
Originator Name:  R Crozier Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 03 Oct 2012 03:40:17 PM UTC, comment #10: 

I left it open to allow to allow some time for testing.  There's been enough time, so I'm marking it fixed and closing it.

Ben Abbott <bpabbott>
Group Member
Wed 03 Oct 2012 03:12:28 PM UTC, comment #9: 

Is there any reason not to close this report?

John W. Eaton <jwe>
Group administrator
Sat 22 Sep 2012 09:28:44 PM UTC, comment #8: 
Ben Abbott <bpabbott>
Group Member
Sat 22 Sep 2012 09:12:31 PM UTC, comment #7: 

Ben,

Typo in last message. I meant to say

I would NOT put it high on the kludge scale.

Michael Godfrey <godfrey>
Group Member
Sat 22 Sep 2012 09:10:51 PM UTC, comment #6: 

Ben,

This might have been a chance to try:

  switch...
    case {  ... }
     .
     .
     .
But, it is pretty clear the way it is.
I would put it high on the kludge scale.

Important thing is it works!

Michael Godfrey <godfrey>
Group Member
Sat 22 Sep 2012 08:48:32 PM UTC, comment #5: 

I've attached a 3rd attempt that works for me (admittedly it looks kludgy)



(file #26619)

Ben Abbott <bpabbott>
Group Member
Sat 22 Sep 2012 06:28:38 PM UTC, comment #4: 

Ok, I didn't look closely enough and misunderstood what ML was doing.

I did some experimenting with Matlab and put together the attached changeset. It still needs some work to properly handle the example below.


>> repmat (x, [1 3; 1 1])

ans =

     1     2     3

>> repmat (x, [1 1; 1 1])

ans =

     1     2     3


Any idea what ML is doing here?

(file #26618)

Ben Abbott <bpabbott>
Group Member
Sat 22 Sep 2012 10:01:17 AM UTC, comment #3: 

Incidentally, there are further differences in behaviour, for example the following in ML:

>> repmat(1, [2,2], 3)


ans(:,:,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000

>> repmat(1, [2,2], 3, 3)

Error using repmat
Too many input arguments.
 

>> repmat(1, [2,2,2], 3)


ans(:,:,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,2) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,3) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000

>> repmat(1, [2,2,2], [3,3])


ans(:,:,1,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,1,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,1,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000


ans(:,:,2,2,1) =

     1.0000e+000     1.0000e+000
     1.0000e+000     1.0000e+000
... lots more output

So it seems m and n need not be scalar in ML, the dimensions are in fact just tacked onto each other. This is consistent with what was seen with empty inputs. Therefore you could get rid of the error and just do something like:

# check second arg first so it will be one if both
# m and n are empty
if (isempty (n))
n = 1;
endif
if (isempty (m))
m = n;
n = 1;
endif

if isvector(m) && isvector(n)
idx = [m(:)',n(:)'];
else
error('M and N must be scalars or vectors')
endif

Richard <crobar>
Sat 22 Sep 2012 09:35:00 AM UTC, comment #2: 

I realised I made a mistake when I first reported this.

Repmat does not replace empty values with 1, it ignores them and treats the non-empty values as if they were the first argument:

>> repmat([1,2,3], [], 4)


ans =

     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000

>> repmat([1,2,3], 4, [])


ans =

     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000

so your patch is not quite right. Something like the following might work:

# check second arg first so it will be one if both
# m and n are empty
if (isempty (n))
    n = 1;
endif
if (isempty (m))
    m = n;
    n = 1;
endif

Richard <crobar>
Sat 22 Sep 2012 01:14:57 AM UTC, comment #1: 
Ben Abbott <bpabbott>
Group Member
Tue 18 Sep 2012 10:16:45 PM UTC, original submission:  

In Matlab I get the following output from repmat:

>> repmat([1,2,3], [], 4)


ans =

     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000

>> repmat([1,2,3], 2, [])


ans =

     1.0000e+000     2.0000e+000     3.0000e+000
     1.0000e+000     2.0000e+000     3.0000e+000

>> repmat([1,2,3], [], [])


ans =

     1.0000e+000     2.0000e+000     3.0000e+000

Empty arguments appear to be treated as 1. Octave does not permit this behaviour.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #26619:  changeset.patch added by bpabbott (3KiB - application/octet-stream - 3rd attempt)
file #26618:  changeset.patch added by bpabbott (2KiB - application/octet-stream - 2nd attempt)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by crobar (Posted a comment)
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-10-03 bpabbott StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2012-09-22 bpabbott Attached File- Added changeset.patch, #26619
    2012-09-22 bpabbott Attached File- Added changeset.patch, #26618
    2012-09-22 bpabbott StatusNone Ready For Test
        Assigned toNone bpabbott
        Release3.6.1 dev

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code