-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aliasing problem with SparseMatrixCSC
and SparseVector
#34630
Comments
The original idea was that end-users are not supposed to use the |
Yes, these constructors are not documented are not user facing (cf #31724 (comment) and discussion) This is why I didn't really understand #31724 (comment) because |
If even the authors of |
that may be true. But they are supposed to use If I replace the constructor call with this call to |
Right, if you are not messing around with the constructors directly, you should get "good behaviour". I guess this all stems from the treatment of stored zeros, which at first glance appears to not be consistent. |
I don't see the relationship to the storage of zeros. This issue appears much more serious to me. EDIT: |
Thanks for the analysis. Is the aliasing happening in a call to |
The aliasing happens in the constructors |
Would making a copy in |
It would solve the issue, but at cost of inefficiency. |
I do think it makes sense for Lines 539 to 541 in 3720edf
|
In
v1.2.0
andv1.5.0
it is easy to create a corrupted sparse object unintentionally:Reason seems to be that the constructors
SparseMatrixCSC{Tv,Ti}(S::SparseMatrixCSC)
andSparseVector{Tv,Ti}(s:SparseVector)
may produce objects, which share some but not all of their fields with the source objects.
That is for example the case, if
Ti == eltype(S.rowval)
andTv != eltype(S.nzval)
. That results in inconsistent objects when one of them is modified. For example:where the sizes of the component vectors of
b
diverge.IMO the constructors should be changed to not use
convert
, but make copies.The issue surfaced in
v1.5
(but not inv1.2
) when doing a calculation like follows, where thecorruption of
B
was rather unexpected:The text was updated successfully, but these errors were encountered: