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

-0.0, storing zeros other than zero(eltype(v)) #294

Closed
LilithHafner opened this issue Nov 24, 2022 · 2 comments · Fixed by #296
Closed

-0.0, storing zeros other than zero(eltype(v)) #294

LilithHafner opened this issue Nov 24, 2022 · 2 comments · Fixed by #296

Comments

@LilithHafner
Copy link
Member

For almost any value and assignable expression in Julia, this holds:

expr = value
@assert expr === value

I wish this held, too:

v = spzeros(1)
value = -0.0
v[1] = value
@assert v[1] === value
@chriselrod
Copy link

chriselrod commented May 11, 2023

No.

julia> v = zeros(1); # Vector{Float64}

julia> value = 0;

julia> v[1] = value;

julia> @assert v[1] === value
ERROR: AssertionError: v[1] === value
Stacktrace:
 [1] top-level scope
   @ REPL[18]:1

Also, it is not hard to get -0.0 accidentally

julia> -3.4 * 0.0
-0.0

why should we have to filter these manually?

@SobhanMP
Copy link
Member

1: you're forcing the type here tho, that's not part of @LilithHafner's point
2: not all zeros are equal, i personally learned it the hard way JuliaDiff/ForwardDiff.jl#542 this way we only remove zeros we are sure we can restore.

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

Successfully merging a pull request may close this issue.

3 participants