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

- densifies zeros #686

Open
willow-ahrens opened this issue Jan 3, 2025 · 2 comments · May be fixed by #688
Open

- densifies zeros #686

willow-ahrens opened this issue Jan 3, 2025 · 2 comments · May be fixed by #688

Comments

@willow-ahrens
Copy link
Collaborator

A - A results in all the zero entries getting converted to -0.0 and being stored explicitly 😬

julia> A = fsprand(5, 5, 0.5)
5×5 Tensor{SparseCOOLevel{2, Tuple{Int64, Int64}, Vector{Int64}, Tuple{Vector{Int64}, Vector{Int64}}, ElementLevel{0.0, Float64, Int64, Vector{Float64}}}}:
 0.0       0.836373  0.73536  0.0         0.83067
 0.0       0.0       0.0      0.0         0.390398
 0.677004  0.0       0.0      0.0         0.605428
 0.0       0.0       0.0      0.00907705  0.728524
 0.0       0.0       0.0      0.878594    0.0

julia> A - A
5×5 Tensor{SparseDictLevel{Int64, Vector{Int64}, Vector{Int64}, Vector{Int64}, Dict{Tuple{Int64, Int64}, Int64}, Vector{Int64}, SparseDictLevel{Int64, Vector{Int64}, Vector{Int64}, Vector{Int64}, Dict{Tuple{Int64, Int64}, Int64}, Vector{Int64}, ElementLevel{0.0, Float64, Int64, Vector{Float64}}}}}:
 -0.0   0.0   0.0  -0.0   0.0
 -0.0  -0.0  -0.0  -0.0   0.0
  0.0  -0.0  -0.0  -0.0   0.0
 -0.0  -0.0  -0.0   0.0   0.0
 -0.0  -0.0  -0.0   0.0  -0.0
 
 julia> countstored(A - A)
25
@willow-ahrens
Copy link
Collaborator Author

After #383, the handling of -0.0 has proven to be a continuing issue. The problem is that there's two ways to evaluate 0.0 + (-0.0) in Finch. We could follow floating point semantics, which gives 0.0. We could also use the fact that 0.0 is an annihilator, which gives -0.0. I'm beginning to think the right choice may be to defer to actual evaluation semantics whenever possible.

@willow-ahrens
Copy link
Collaborator Author

After some thought, we can summarize this issue as:

  • -0.0 + 0.0 = 0.0 (from floating point semantics)
  • -0.0 + 0.0 = -0.0 (from x + 0 = x rule)
    We need one of these to win out over the other when we do constant propagation in Finch.
    I think that we can resolve this by overloading floating point semantics within Finch such that 0.0 + x = 0.0 and 0.0 * x = 0.0, whenever we evaluate floating point at compile time.

@wraith1995 I feel like you would appreciate this.

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.

1 participant