bugGNU Octave - Bugs: bug #46672, magic (N) should not error for any...

 
 

bug #46672: magic (N) should not error for any integer input values

Submitter:  Bernardo Sulzbach <mafagafogigante>
Submitted:  Sat 12 Dec 2015 03:03:23 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 12 Dec 2015 03:43:22 PM UTC, comment #1: 

Pushed and rebased:

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

If you want to get rid of your local copy of this commit, do

   hg strip -r c42e0b0c73927b862dc57930059b1eee0700e974

After that, pull again.

Jordi GutiƩrrez Hermoso <jordigh>
Group Member
Sat 12 Dec 2015 03:03:23 PM UTC, original submission:  

MATLAB behavior:

 magic(-1) = []
 magic(0) = []
 magic(1) = 1
 magic(2) = [1 3; 4 2]
 magic(3) = [8 1 6; 3 5 7; 4 9 2]
 magic(4) = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1]


Octave old behavior:

 magic(-1) // errors
 magic(0) // errors
 magic(1) = 1 // ==
 magic(2) // errors
 magic(3) = [8 1 6; 3 5 7; 4 9 2] // ==
 magic(4) = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1] // ==


Octave behavior after this patch

 magic(-1) = [] // ==
 magic(0) = [] // ==
 magic(1) = 1 // ==
 magic(2) = [4 3; 1 2] // As in MATLAB, not a magic square (there is not one for n == 2).
                       // But this one is slightly different from MATLAB's.
                       // This is because we some things here are done differently,
                       // but it is a minor issue that I considered not worthy of
                       // further investigation.
 magic(3) = [8 1 6; 3 5 7; 4 9 2] // ==
 magic(4) = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1] // ==


Old documentation note: Note: N must be greater than 2 for the magic square to exist.

New documentation note: Note: N must be a scalar greater than or equal to 3.  If you supply N less than 3, magic returns either a nonmagic square, or else the degenerate magic squares 1 and [].

The new docs reflect MATLAB documentation and perfectly describe the new behavior of magic(N) for these "odd" values of N.

The tests provided in magic.m pass with my patch.

Bernardo Sulzbach <mafagafogigante>

 

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

Attach Files:
   
   
Comment:
   

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by mafagafogigante (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-12-12 jordigh StatusNone Fixed
        Open/ClosedOpen Closed
    2015-12-12 mafagafogigante Attached File- Added magic-matlab-compatibility.diff, #35707
    2015-12-12 mafagafogigante Attached File- Added magic-m-matlab-compatibility.diff, #35703

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code