Skip to content

Unsuccessful assignment without any error #569

@ArmanZarrin97

Description

@ArmanZarrin97

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions