bugGNU Octave - Bugs: bug #35150, spdiags() 4-argument...

 
 

bug #35150: spdiags() 4-argument incompatibility

Submitter:  None
Submitted:  Wed 21 Dec 2011 11:16:19 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  dbateman
Originator Name:  J.J. Green Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 21 May 2012 10:56:31 AM UTC, comment #4: 

Cicking on the link with the "Date, comment #N" title brough up an "unflag as spam" button.

John W. Eaton <jwe>
Group administrator
Mon 21 May 2012 12:23:39 AM UTC, comment #3: 

Sorry I accidently flagged an entry in this bug report as spam, and I can't seem to remove the flag !! In any case the error here is a combination of the addition of broadcast operators and the bug fix in the changeset

http://hg.savannah.gnu.org/hgweb/octave/rev/1f0243949b77

which combined means that spdiags treated row vectors of values badly. I believe a more generic fix is


diff --git a/scripts/sparse/spdiags.m b/scripts/sparse/spdiags.m
--- a/scripts/sparse/spdiags.m
+++ b/scripts/sparse/spdiags.m
@@ -79,8 +79,8 @@
     ## Create new matrix of size mxn using v,c
     [j, i, v] = find (v);
     offset = max (min (c(:), n-m), 0);
-    j = j + offset(i);
-    i = j-c(:)(i);
+    j = j(:) + offset(i(:));
+    i = j - c(:)(i(:));
     idx = i > 0 & i <= m & j > 0 & j <= n;
     A = sparse (i(idx), j(idx), v(idx), m, n);
   endif


I'll push this fix and so am closing this bug

D.

David Bateman <dbateman>
Group Member
Wed 11 Jan 2012 04:29:36 PM UTC, comment #2: 

[resent with corrected formatting]

The following micropatch seems to fix this problem. The effect just to trim the non-relevant parts of the input.

--- scripts/sparse/spdiags.m 2012-01-11 17:02:52.000000000 +0100
+++ spdiags.m 2012-01-11 16:56:26.000000000 +0100
@@ -78,6 +78,10 @@
else
## Create new matrix of size mxn using v,c
[j, i, v] = find (v);
+ idx = (i <= m) & (j <= n);
+ i = i(idx);
+ j = j(idx);
+ v = v(idx);
offset = max (min (c(:), n-m), 0);
j = j + offset(i);
i = j-c(:)(i);


Anonymous
Wed 11 Jan 2012 04:25:24 PM UTC, comment #1: 

The following micropatch seems to fix this problem. The effect just to trim the non-relevant parts of the input.
+verbose+
--- scripts/sparse/spdiags.m 2012-01-11 17:02:52.000000000 +0100
+++ spdiags.m 2012-01-11 16:56:26.000000000 +0100
@@ -78,6 +78,10 @@
   else
     ## Create new matrix of size mxn using v,c
     [j, i, v] = find (v);
+    idx = (i <= m) & (j <= n);
+    i = i(idx);
+    j = j(idx);
+    v = v(idx);
     offset = max (min (c(:), n-m), 0);
     j = j + offset(i);
     i = j-c(:)(i);
-verbose-

Anonymous
Wed 21 Dec 2011 11:16:19 PM UTC, original submission:  

For some small (seemingly silly) cases, Octave's spdiags() fails

octave:16> spdiags([0.5 -1 0.5], 0:2, 1, 1)
error: spdiags: A(I): index out of bounds; value 7 out of bound 3
error: called from:
error:   /usr/local/share/octave/3.5.90+/m/sparse/spdiags.m at line 85, column 7

while Matlab's suceeds

>> spdiags([0.5 -1 0.5], 0:2, 1, 1)

ans =

   (1,1)       0.5000

In fact these cases are not as silly as they first appear, they are used as the starting point for adaptive refinement schemes.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

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 jwe (Posted a comment)
  • -email is unavailable- added by dbateman (Updated the item)
  • -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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-05-21 dbateman Open/ClosedOpen Closed
        Discussion LockLocked None
    2012-05-21 dbateman StatusNone Fixed
        Assigned toNone dbateman
    2012-05-21 dbateman Summary[SPAM] spdiags() 4-argument incompatibility spdiags() 4-argument incompatibility

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code