Skip to content

Commit

Permalink
Fix Strassen, add a test (#1803)
Browse files Browse the repository at this point in the history
* Add real Strassen doctest
  • Loading branch information
lgoettgens committed Sep 23, 2024
1 parent 548894f commit efb6ceb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Matrix-Strassen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ The speedup depends on the ring and the entry sizes.
```jldoctest; setup = :(using AbstractAlgebra)
julia> m = matrix(ZZ, rand(-10:10, 1000, 1000));
julia> n = similar(m);
julia> n1 = similar(m); n2 = similar(m); n3 = similar(m);
julia> n = mul!(n, m, m);
julia> n1 = mul!(n1, m, m);
julia> n = Strassen.mul!(n, m, m);
julia> n2 = Strassen.mul!(n2, m, m);
julia> n = Strassen.mul!(n, m, m; cutoff = 100);
julia> n3 = Strassen.mul!(n3, m, m; cutoff = 100);
julia> n1 == n2 == n3
true
```
"""
module Strassen
Expand Down Expand Up @@ -140,7 +143,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff)
#nmod_mat_window_init(Cc, C, 0, 2*bnc, a, c);
Cc = view(C, 1:a, 2*bnc+1:c)
#nmod_mat_mul(Cc, A, Bc);
Cc = AbstractAlgebra.mul!(Cc, A, Bc)
AbstractAlgebra.mul!(Cc, A, Bc) # needs to mutate Cc
end

if a > 2*anr #last row of A by B -> last row of C
Expand All @@ -149,7 +152,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff)
#nmod_mat_window_init(Cr, C, 2*anr, 0, a, c);
Cr = view(C, 2*anr+1:a, 1:c)
#nmod_mat_mul(Cr, Ar, B);
Cr = AbstractAlgebra.mul!(Cr, Ar, B)
AbstractAlgebra.mul!(Cr, Ar, B) # needs to mutate Cr
end

if b > 2*anc # last col of A by last row of B -> C
Expand All @@ -160,7 +163,7 @@ function mul!(C::MatElem{T}, A::MatElem{T}, B::MatElem{T}; cutoff::Int = cutoff)
#nmod_mat_window_init(Cb, C, 0, 0, 2*anr, 2*bnc);
Cb = view(C, 1:2*anr, 1:2*bnc)
#nmod_mat_addmul(Cb, Cb, Ac, Br);
Cb = AbstractAlgebra.mul!(Cb, Ac, Br)
AbstractAlgebra.addmul!(Cb, Ac, Br) # needs to mutate Cb
end

return C
Expand Down

0 comments on commit efb6ceb

Please # to comment.