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

Weird DivideError: materialize and rational matmul #199

Open
Voltobene opened this issue Sep 30, 2021 · 2 comments
Open

Weird DivideError: materialize and rational matmul #199

Voltobene opened this issue Sep 30, 2021 · 2 comments

Comments

@Voltobene
Copy link

I came across some strange behaviour which I was able to break down to the following:

julia> using LazyArrays
julia> A = zeros(Rational{Int64}, 2, 2);
julia> B = zeros(Rational{Int64}, 2, 25);
julia> materialize(@~ A * B)

throws (even on a clean julia 1.6.3, LazyArrays V 0.22.1)

julia> materialize(@~ A * B)
ERROR: DivideError: integer division error
Stacktrace:
  [1] div
    @ ./int.jl:261 [inlined]
  [2] divgcd
    @ ./rational.jl:45 [inlined]
  [3] *(y::Bool, x::Rational{Int64})
    @ Base ./rational.jl:319
...

Interestingly enough, the following (invoking A * B upfront) works:

julia> A * B;
julia> materialize(@~ A * B)
2×25 Matrix{Rational{Int64}}:
 0//1  0//1  0//1  0//1  0//1  0//1    0//1  0//1  0//1  0//1  0//1  0//1
 0//1  0//1  0//1  0//1  0//1  0//1     0//1  0//1  0//1  0//1  0//1  0//1

Maybe some not yet compiled code is the culprit?

@dlfivefifty
Copy link
Member

@tkf I think you wrote the macro? I'm not familiar enough to understand what could be happening here.

@dlfivefifty
Copy link
Member

@Voltobene always include the full stacktrace in an issue as it makes it more obvious what the problem might be:

julia> materialize(@~ A * B)
ERROR: DivideError: integer division error
Stacktrace:
  [1] div
    @ ./int.jl:261 [inlined]
  [2] divgcd
    @ ./rational.jl:45 [inlined]
  [3] *(y::Bool, x::Rational{Int64})
    @ Base ./rational.jl:319
  [4] macro expansion
    @ ~/Projects/julia-1.6/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:221 [inlined]
  [5] macro expansion
    @ ./simdloop.jl:77 [inlined]
  [6] lmul!
    @ ~/Projects/julia-1.6/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:220 [inlined]
  [7] materialize!
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/lmul.jl:73 [inlined]
  [8] lmul!
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/lmul.jl:47 [inlined]
  [9] tiled_blasmul!(tile_size::Int64, α::Rational{Int64}, A::Matrix{Rational{Int64}}, B::Matrix{Rational{Int64}}, β::Bool, C::Matrix{Rational{Int64}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/NI7mz/src/muladd.jl:131
 [10] materialize!(M::ArrayLayouts.MulAdd{ArrayLayouts.DenseColumnMajor, ArrayLayouts.DenseColumnMajor, ArrayLayouts.DenseColumnMajor, Rational{Int64}, Matrix{Rational{Int64}}, Matrix{Rational{Int64}}, Matrix{Rational{Int64}}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/NI7mz/src/muladd.jl:241
 [11] muladd!
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/muladd.jl:70 [inlined]
 [12] copyto!
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/muladd.jl:77 [inlined]
 [13] copy(M::ArrayLayouts.MulAdd{ArrayLayouts.DenseColumnMajor, ArrayLayouts.DenseColumnMajor, ArrayLayouts.ZerosLayout, Rational{Int64}, Matrix{Rational{Int64}}, Matrix{Rational{Int64}}, FillArrays.Zeros{Rational{Int64}, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}})
    @ ArrayLayouts ~/.julia/packages/ArrayLayouts/NI7mz/src/muladd.jl:72
 [14] copy
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/mul.jl:108 [inlined]
 [15] materialize
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/mul.jl:105 [inlined]
 [16] mul
    @ ~/.julia/packages/ArrayLayouts/NI7mz/src/mul.jl:106 [inlined]
 [17] copy
    @ ~/.julia/packages/LazyArrays/zulEl/src/linalg/mul.jl:13 [inlined]
 [18] materialize(A::Applied{LazyArrays.MulStyle, typeof(*), Tuple{Matrix{Rational{Int64}}, Matrix{Rational{Int64}}}})
    @ LazyArrays ~/.julia/packages/LazyArrays/zulEl/src/lazyapplying.jl:82
 [19] top-level scope
    @ REPL[4]:1

Nevermind @tkf looks unrelated to the macro.

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