[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #45622] Sparsity of sparse matrix when assigni
From: |
Amro |
Subject: |
[Octave-bug-tracker] [bug #45622] Sparsity of sparse matrix when assigning all elements |
Date: |
Sat, 25 Jul 2015 04:13:19 +0000 |
User-agent: |
Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0 |
URL:
<http://savannah.gnu.org/bugs/?45622>
Summary: Sparsity of sparse matrix when assigning all
elements
Project: GNU Octave
Submitted by: amro_octave
Submitted on: Sat 25 Jul 2015 07:13:18 AM EEST
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: WTF, Matlab?!?
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 4.0.0
Operating System: Any
_______________________________________________________
Details:
I was reading bug #45589, and I found other incompatibilities with regard to
sparse matrices.
Consider the following example:
>> M = sparse(4,4);
>> M(:) = 1;
>> issparse(M) % MATLAB -> false, Octave -> true
>> nnz(M) % MATLAB -> 16, Octave -> 16
>> nzmax(M) % MATLAB -> 16, Octave -> 16
In the latest MATLAB R2015a, the matrix "M" becomes full, while in Octave
4.0.0 it maintains its sparsity.
I guess MATLAB determined that it was more space-efficient to just convert the
matrix to full rather than just keep it in sparse storage, seeing that we fill
all the elements with non-zero values.
Note that the outcome is different from the following code:
M = sparse(4,4);
for i=1:numel(M)
M(i) = 1; % also try: 0
end
where the matrix "M" stays sparse in both MATLAB and Octave.
----
Another inconsistency:
>> A1 = sparse(4,4);
>> A1(:) = 0;
>> issparse(A1) % MATLAB -> true, Octave -> true
>> nnz(A1) % MATLAB -> 0, Octave -> 0
>> nzmax(A1) % MATLAB -> 1, Octave -> 0
>> A2 = sparse(4,4);
>> A2(:) = zeros(size(A2));
>> issparse(A1) % MATLAB -> false, Octave -> true
>> nnz(A1) % MATLAB -> 0, Octave -> 0
>> nzmax(A1) % MATLAB -> 16, Octave -> 0
>> A3 = sparse(4,4);
>> A3(:) = zeros(numel(A3),1);
>> issparse(A1) % MATLAB -> false, Octave -> true
>> nnz(A1) % MATLAB -> 0, Octave -> 0
>> nzmax(A1) % MATLAB -> 16, Octave -> 0
>> whos A*
In Octave, all three cases are the same, and the resulting matrix remains
sparse.
However in MATLAB, "A1" is the only one that stays sparse, and the other two
"A2" and "A3" are converted to full. Also note that the "A1" storage (nzmax)
is expanded to one.
So it seems that "A(:) = scalar" is treated differently from "A(:) =
vector/matrix" in MATLAB, even if scalar/vector/matrix are all zeros...
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?45622>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #45622] Sparsity of sparse matrix when assigning all elements,
Amro <=