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

 
 

bug #37390: In matlab repmat can have empty inputs

Submitted by:  None
Submitted on:  Tue 18 Sep 2012 10:16:45 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: Ben Abbott <bpabbott>
Originator Name: R CrozierOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 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.

 

(Jump to the original submission 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>
Project MemberIn charge of this item.
Wed 03 Oct 2012 03:12:28 PM UTC, comment #9:

Is there any reason not to close this report?

John W. Eaton <jwe>
Project Administrator
Sat 22 Sep 2012 09:28:44 PM UTC, comment #8:

Ok, I've pushed a changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/32fd31378052

Ben Abbott <bpabbott>
Project MemberIn charge of this item.
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>
Project 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>
Project 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>
Project MemberIn charge of this item.
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.

Any idea what ML is doing here?

(file #26618)

Ben Abbott <bpabbott>
Project MemberIn charge of this item.
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:

I've pushed a changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/e1f59fd57756

Ben Abbott <bpabbott>
Project MemberIn charge of this item.
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 File(s):
   
   
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
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by godfrey (Posted a comment)
  • -unavailable- added by crobar (Posted a comment)
  • -unavailable- added by bpabbott (Posted a comment)
  • -unavailable- added by None (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 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 03 Oct 2012 03:40:17 PM UTCbpabbottStatusReady For Test=>Fixed
      Open/ClosedOpen=>Closed
    Sat 22 Sep 2012 08:48:32 PM UTCbpabbottAttached File-=>Added changeset.patch, #26619
    Sat 22 Sep 2012 06:28:38 PM UTCbpabbottAttached File-=>Added changeset.patch, #26618
    Sat 22 Sep 2012 01:14:57 AM UTCbpabbottStatusNone=>Ready For Test
      Assigned toNone=>bpabbott
      Release3.6.1=>dev

    Back to the top


    Powered by Savane 3.1-cleanup1