JuliaLinearAlgebra / Octavian.jl

Multi-threaded BLAS-like library that provides pure Julia matrix multiplication
https://julialinearalgebra.github.io/Octavian.jl/stable/
Other
230 stars 18 forks source link

Results inconsistent with LinearAlgebra.mul! #121

Closed GiggleLiu closed 2 years ago

GiggleLiu commented 2 years ago

MWE

julia> using LinearAlgebra

julia> LinearAlgebra.mul!(fill(NaN, 2, 2), randn(2,2), randn(2,2), 1, 0)
2×2 Matrix{Float64}:
  0.416567   0.0524288
 -0.851354  -3.77905

julia> using Octavian

julia> Octavian.matmul!(fill(NaN, 2, 2), randn(2,2), randn(2,2), 1, 0)
2×2 Matrix{Float64}:
 NaN  NaN
 NaN  NaN

It is not an issue in most cases, however, due to the fact that similar sometimes can create an array with NaNs inside. Octavian.matmul!(similar(a, size(a, 1), size(b, 2)), a, b, true, false) does not correspond to matrix multiplication. Related issue is https://github.com/TensorBFS/TropicalGEMM.jl/issues/16

Since I bind (pirate) the Octavian.matmul! to matrix multiplication in TropicalGEMM, so I need to fix it anyway. Wondering if I should fix it in Octavian or TropicalGEMM?

chriselrod commented 2 years ago

Octavian uses static(0) as the multiplier, but it could add a check.

Might be worth finding out at which point false gets promoted to 0.0.

GiggleLiu commented 2 years ago

Thanks, it makes sense.