bugGNU Octave - Bugs: bug #41441, Broadcasting does not behave...

 
 

bug #41441: Broadcasting does not behave properly on sparse matrices

Submitter:  David Spies <dspyz>
Submitted:  Mon 03 Feb 2014 03:15:29 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Ready For Test Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  11.1.0 (current default) Planned Release:  11.1.0 (current default)
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Jump to the original submission

Thu 04 Dec 2025 02:52:45 PM UTC, comment #10: 

Perhaps we should leave this open until broadcasting support is also fixed for comparison operations as well.

Andreas Bertsatos <pr0m1th3as>
Group Member
Thu 04 Dec 2025 01:56:00 PM UTC, comment #9: 

Pushed to default branch. Passes `make check` with all the new BISTs as well.

Will leave this open for a bit so others can test.

Marked as Ready for test.

Arun Giridhar <arungiridhar>
Group Member
Thu 04 Dec 2025 12:55:04 PM UTC, comment #8: 

I have just posted a patch here https://octave.di ... 7/61?u=pr0m1th3as that fixes the broadcasting for math operators with sparse matrices. Comparison operations are still an issue regarding proper broadcasting.

I also attach the relevant patch here for documentation purposes.


(file #57913)

Andreas Bertsatos <pr0m1th3as>
Group Member
Tue 18 Apr 2023 03:56:04 PM UTC, comment #7: 

unchanged in 8.2.0

Nicholas Jankowski <nrjank>
Group Member
Sun 04 Jul 2021 02:19:15 AM UTC, comment #6: 

just stumbled on this and confirming that this bug still exists in Octave 6.2.0:


>> a  = [1 2 3];

>> a .* a'
ans =

   1   2   3
   2   4   6
   3   6   9

>> b = sparse(a)
b =

Compressed Column Sparse (rows = 1, cols = 3, nnz = 3 [100%])

  (1, 1) -> 1
  (1, 2) -> 2
  (1, 3) -> 3

>> b .* b'
error: product: nonconformant arguments (op1 is 1x3, op2 is 3x1)


Nicholas Jankowski <nrjank>
Group Member
Wed 31 Aug 2016 06:31:54 PM UTC, comment #5: 

Also a problem in SciPy apparently: https://github.co ... scipy/issues/2128

Nir Krakauer <nir_krakauer>
Sat 03 Oct 2015 09:58:25 AM UTC, comment #4: 



Just added a related bug for the diagonal matrices:
https://savannah. ... s/index.php?46110

jan <pfa>
Sat 30 May 2015 07:24:20 PM UTC, comment #3: 

As I just discovered in my near-duplicate report #45219, one key factor is that combinations of one real and one complex sparse matrix fail.

t1 = randn(6,3)+1j*randn(6,3);
t2 = randn(6,1);
s1 = sparse(t1);
s2 = sparse(t2);


These work fine:

t1 + t2
bsxfun( @plus, t1, t2 )


These do not:

>> s1 + s2
error: operator +: nonconformant arguments (op1 is 6x3, op2 is 6x1)
>> bsxfun(@plus,s1,s2)
error: concatenation operator not implemented for '<unknown type>' by 'sparse complex matrix' operations
-verbatim+

Michael C. Grant <mcgrant>
Sun 21 Sep 2014 10:36:40 AM UTC, comment #2: 

I encountered something similar with automatic broadcasting and sparse vectors:

ones(3,10).*[0;2;0] # works as expected

ones(3,10).*sparse(2,1,2,3,1) # does not work

and yields the following error message:
error: product: nonconformant arguments (op1 is 3x10, op2 is 3x1)

I am on version 3.8.1

Sorry for the double post in ( https://savannah. ... u.org/bugs/?35787 ), feels free to removeone of them.

CH <atcl>
Fri 07 Feb 2014 10:01:02 PM UTC, comment #1: 

I have a sort of partial workaround.  Could someone look through it and see if they have any ideas to make it work completely? (It would already if not for bug #40341)


(file #30484)

David Spies <dspyz>
Mon 03 Feb 2014 03:15:29 AM UTC, original submission:  

Broadcasting doesn't work at all for sparse matrices.  There appears to be no good workaround

#Doesn't work automatically for sparse matrix with full vector
octave:1> a = sprand(100000,100000,0.00001);
octave:2> b = rand(100000,1);
octave:3> res = a == b;
error: mx_el_eq: nonconformant arguments (op1 is 100000x100000, op2 is 100000x1)

#Doesn't work explicitly for sparse matrix with full vector
octave:9> res = bsxfun(@eq,a,b);
error: out of memory or dimension too large for Octave's index type

#Doesn't work automatically for sparse matrix with sparse vector
octave:9> b = sparse(b);
octave:10> res = a == b;
error: mx_el_eq: nonconformant arguments (op1 is 100000x100000, op2 is 100000x1)

#Doesn't work explicitly for sparse matrix with sparse vector
octave:10> res = bsxfun(@eq,a,b);
error: out of memory or dimension too large for Octave's index type

#Often there's a special-case work-around, but it's generally unwieldy

octave:10> b_mat = diag(b) * spones(a);
octave:11> [i,j] = find(a);
octave:12> res = sparse(i,j,nonzeros(a) == nonzeros(b_mat));

David Spies <dspyz>

 

Attached Files

Attached Files
file #57913:  bug41441_math_ops.patch added by pr0m1th3as (110KiB - text/x-patch)
file #30484:  spbsxfun.m added by dspyz (2.9KiB - text/x-objcsrc)

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

Attach Files:
   
   
Comment:
   

 

Dependencies

Mail Notification Carbon-Copy List

Carbon-Copy List
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by pr0m1th3as (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by nir_krakauer (Posted a comment)
  • -email is unavailable- added by pfa (Posted a comment)
  • -email is unavailable- added by mcgrant (Posted a comment)
  • -email is unavailable- added by atcl (Posted a comment)
  • -email is unavailable- added by dspyz (Submitted the item)
  •  

    Votes

    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.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

    History

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-12-04 arungiridhar StatusNone Ready For Test
        Fixed ReleaseNone 11.1.0 (current default)
        Planned ReleaseNone 11.1.0 (current default)
    2025-12-04 pr0m1th3as Attached File- Added bug41441_math_ops.patch, #57913
    2025-01-05 mmuetzel Dependencies- bugs #66585 is dependent
    2021-07-26 mmuetzel Dependencies- bugs #60968 is dependent
    2018-12-01 rik5 Dependencies- bugs #55141 is dependent
    2018-11-28 rik5 Dependencies- bugs #55126 is dependent
    2014-02-07 dspyz Attached File- Added spbsxfun.m, #30484

    Back to the top

    Powered by Savane 3.16-598c.
    Corresponding source code