Skip to content
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

Unsuccessful assignment without any error #569

Open
ArmanZarrin97 opened this issue Oct 15, 2024 · 1 comment
Open

Unsuccessful assignment without any error #569

ArmanZarrin97 opened this issue Oct 15, 2024 · 1 comment

Comments

@ArmanZarrin97
Copy link

ArmanZarrin97 commented Oct 15, 2024

I first wrongly created an issue for julia itself, but it is apparently an issue related to SparseArrays.jl. you can find the previous issue here

Hi,

I tried to run this line in one of my functions:

 J[:, isl]=[ki... zeros(length(setdiff(1:nBus,ipq)))...]

J is a sparse matrix with size 120120. J[:, isl] is a column with only four values, which are [11.00 -11.00 44.00 -44.00]. [ki... zeros(length(setdiff(1:nBus,ipq)))...] is a matrix 1201, of which 23 elements are 50.00 and the others equal to zero. The result of running this code is again a column with only four values, which are [0.00 0.00 0.00 0.00]. However, I expect it to be a column with 23, 24,..., or 27 values, which includes 23 values equal to 50.00.

I didn't encounter any error. I believe it should be a bug. By chance I understood that this assignment doesn't work correctly, But it could be in fact dangerous for the others.

I fixed it in this way:

J[:, isl]=[ki... zeros(length(setdiff(1:nBus,ipq)))...]**[:,1]**

Best,
Arman

Here is the reproducible example:

a=spzeros(120,120)

isl=5

a[10,isl]=1
a[14,isl]=1
a[37,isl]=1
a
R=zeros(40,1)
S=50*ones(40,1)
T=zeros(40,1)
b=[R... S... T...]
a
b
a[:,isl]=b ## This is the concerned assignment
sum(b) # =1200.0
sum(a[:,isl]) # =0.0
@adienes
Copy link

adienes commented Oct 16, 2024

perhaps the issue is here

_to_same_csc(::AbstractSparseMatrixCSC{Tv, Ti}, V::AbstractMatrix, I...) where {Tv,Ti} = convert(SparseMatrixCSC{Tv,Ti}, V)

that V could be map(length, I) like it is for the AbstractVector case.

I'm not sure though; I don't know this code very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants