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

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

Add a New Comment Rich Markup

## Discussion

Tue 18 Apr 2023 03:56:04 PM UTC, comment #7:

unchanged in 8.2.0

Nicholas Jankowski <nrjank>
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>
Wed 31 Aug 2016 06:31:54 PM UTC, comment #5:

Also a problem in SciPy apparently: https://github.com/scipy/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.gnu.org/bugs/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.gnu.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

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

Attach Files:

Comment:

Attached Files
file #30484:  spbsxfun.m added by dspyz (3KiB - text/x-objcsrc)

## Dependencies

Depends on the following items: None found

Digest:
bug dependencies.

## Mail Notification Carbon-Copy List

Carbon-Copy List
• -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)
•

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.

## History

Follow 4 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
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