bugGNU Octave - Bugs: bug #66514, spdiags does not...

 
 

bug #66514: spdiags does not "broadcast" elements over selected diagonals

Submitter:  Liang Tang <lt1234>
Submitted:  Tue 03 Dec 2024 02:20:23 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  lt1234 Open/Closed:  * Open
Release:  * 9.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 03 Dec 2024 12:38:55 PM UTC, comment #2: 

Similar issue if the first argument is a scalar.

In Octave 9.2.0:

>> n=9; Z = sparse(n,n); A = spdiags([1], -1:1, Z)
A =

Compressed Column Sparse (rows = 9, cols = 9, nnz = 1 [1.2%])

  (2, 1) -> 1


In Matlab R2024b:

>> n=9; Z = sparse(n,n); A = spdiags([1], -1:1, Z); full(A)

ans =

     1     1     0     0     0     0     0     0     0
     1     1     1     0     0     0     0     0     0
     0     1     1     1     0     0     0     0     0
     0     0     1     1     1     0     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     0     1     1     1     0     0
     0     0     0     0     0     1     1     1     0
     0     0     0     0     0     0     1     1     1
     0     0     0     0     0     0     0     1     1

>>


Markus Mützel <mmuetzel>
Group administrator
Tue 03 Dec 2024 12:35:37 PM UTC, comment #1: 

The output of the original code snippet in Matlab R2024a:

>> n=9; A = spdiags ([1 2 3], -1:1, n, n); full (A)

ans =

     2     3     0     0     0     0     0     0     0
     1     2     3     0     0     0     0     0     0
     0     1     2     3     0     0     0     0     0
     0     0     1     2     3     0     0     0     0
     0     0     0     1     2     3     0     0     0
     0     0     0     0     1     2     3     0     0
     0     0     0     0     0     1     2     3     0
     0     0     0     0     0     0     1     2     3
     0     0     0     0     0     0     0     1     2

>>



To put it in words: Matlab seems to "broadcast" elements of a row vector in the first argument to the diagonals that are selected in the second argument of `spdiag` if it is called with four input arguments.

Same for the three-input-argument form of `spdiag`.
In Matlab R2024a:

>> n=9; Z = sparse (n, n); A = spdiags ([1 2 3], -1:1, Z); full (A)

ans =

     2     3     0     0     0     0     0     0     0
     1     2     3     0     0     0     0     0     0
     0     1     2     3     0     0     0     0     0
     0     0     1     2     3     0     0     0     0
     0     0     0     1     2     3     0     0     0
     0     0     0     0     1     2     3     0     0
     0     0     0     0     0     1     2     3     0
     0     0     0     0     0     0     1     2     3
     0     0     0     0     0     0     0     1     2

>>


Since this would change behavior of Octave, any change should go to the default branch.

Markus Mützel <mmuetzel>
Group administrator
Tue 03 Dec 2024 02:20:23 AM UTC, original submission:  

Commands below emulates the matlab on-line example.  The result here will not match matlab's.  Thanks. 

> n=9;A = spdiags([1 2 3],-1:1,n,n);full(A)

ans =

   2   0   0   0   0   0   0   0   0
   1   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0

Liang Tang <lt1234>

 

(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 mmuetzel (Posted a comment)
  • -email is unavailable- added by lt1234 (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-12-03 mmuetzel StatusNone Confirmed
        Operating SystemMicrosoft Windows Any
        Summaryspdiags does not match one matlab on-line help example spdiags does not "broadcast" elements over selected diagonals

    Back to the top

    Powered by Savane 3.14-04e1.
    Corresponding source code