bugGNU Octave - Bugs: bug #53356, svd: allow 2 return arguments

 
 

bug #53356: svd: allow 2 return arguments

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Fri 16 Mar 2018 06:36:28 AM 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
   

Jump to the original submission

Sat 28 Jul 2018 05:18:29 AM UTC, comment #7: 

I committed Marco's patch here (https://hg.savannah.gnu.org/hgweb/octave/rev/825e1d0dfa8e).  There is no problem with memork leaks.  Marking as fixed and closing report.

Rik <rik5>
Group administrator
Sat 17 Mar 2018 10:09:54 PM UTC, comment #6: 

I'm sure that works but it'd be interesting to know what happens to the unused element of the ovl object. Some crude testing suggests it is cleaned up properly.

A=randn(1000)+i*randn(1000);
for k=1:10;system('free -m');[U S]=svd(A,0);end

We should lose about 160Mb if the missing V argument were leaked.

Output:

              total        used        free      shared  buff/cache   available
Mem:           7823        1432        4353          87        2037        5977
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1511        4273          85        2038        5899
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1493        4290          87        2039        5916
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1493        4290          86        2039        5916
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1496        4288          86        2039        5914
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1480        4302          85        2041        5931
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1477        4304          85        2040        5934
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1477        4304          85        2041        5933
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1508        4272          85        2042        5903
Swap:          8191           0        8191
              total        used        free      shared  buff/cache   available
Mem:           7823        1541        4240          85        2042        5869
Swap:          8191           0        8191


Ceral Paquet <octavebugs>
Sat 17 Mar 2018 05:45:08 PM UTC, comment #5: 

Let's try again with svd3.diff.

(file #43583)

Marco Caliari <caliari>
Group Member
Sat 17 Mar 2018 05:01:07 PM UTC, comment #4: 

Something I don't know is if this will result in a memory leak:

svd.cc


          if (nargout == 0 || nargout == 1)
            retval(0) = sigma.extract_diag ();
          else
            retval = ovl (result.left_singular_matrix (),
                          sigma,
                          result.right_singular_matrix ());


What happens to result.right_singular_matrix() after it is passed back to caller and not used?

Ceral Paquet <octavebugs>
Fri 16 Mar 2018 01:31:36 PM UTC, comment #3: 

svd2.diff passes the tests, thanks.

(file #43570)

Marco Caliari <caliari>
Group Member
Fri 16 Mar 2018 01:05:11 PM UTC, comment #2: 

Yes that works! Only question does it pass the purity test as it's not strictly a documented behaviour of MATLAB's svd function.

Ceral Paquet <octavebugs>
Fri 16 Mar 2018 12:19:55 PM UTC, comment #1: 

What about the attached diff?

(file #43569)

Marco Caliari <caliari>
Group Member
Fri 16 Mar 2018 06:36:28 AM UTC, original submission:  

In MATLAB, you can request 1, 2 or 3 return arguments from svd function. Currently Octave throws an error which is inconvenient.


>> A=rand(4,3);
>> S=svd(A);
>> [U S V]=svd(A);
>> [U S]=svd(A);
error: Invalid call to svd.  Correct usage is:

 -- S = svd (A)
 -- [U, S, V] = svd (A)
 -- [U, S, V] = svd (A, ECON)


It would be better if Octave could quietly discard the 3rd return argument.

Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #43583:  svd3.diff added by caliari (3KiB - application/x-tex)
file #43570:  svd2.diff added by caliari (988B - application/x-tex)
file #43569:  svd.diff added by caliari (803B - application/x-tex)

 

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 mtmiller (Updated the item)
  • -email is unavailable- added by caliari (Updated the item)
  • -email is unavailable- added by octavebugs (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-28 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
        Release4.2.1 dev
    2018-03-20 mtmiller CategoryNone Octave Function
        Item GroupNone Matlab Compatibility
    2018-03-17 caliari Attached File- Added svd3.diff, #43583
    2018-03-16 caliari Attached File- Added svd2.diff, #43570
    2018-03-16 caliari Attached File- Added svd.diff, #43569
        StatusNone Patch Submitted

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code