Skip to content

Commit 6513bf5

Browse files
authored
Merge branch 'master' into jishnub/genmatvecmul_onepass
2 parents 7703ae2 + 0cbf85f commit 6513bf5

File tree

6 files changed

+51
-22
lines changed

6 files changed

+51
-22
lines changed

src/LinearAlgebra.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,10 @@ function lbt_openblas_onload_callback()
840840
end
841841
end
842842

843-
# If users want to lazily load a different BLAS, they'd need to either change this call, or
844-
# clear the datastructures modified by this call and call it again with their own.
845-
libblastrampoline_jll.add_dependency!(OpenBLAS_jll, libopenblas, lbt_openblas_onload_callback)
843+
function __init__()
844+
# If users want to lazily load a different BLAS, they'd need to either change this call, or
845+
# clear the datastructures modified by this call and call it again with their own.
846+
libblastrampoline_jll.add_dependency!(OpenBLAS_jll, libopenblas, lbt_openblas_onload_callback)
847+
end
848+
846849
end # module LinearAlgebra

src/bunchkaufman.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,8 @@ julia> d, u, p = S; # destructuring via iteration
182182
julia> d == S.D && u == S.U && p == S.p
183183
true
184184
185-
julia> S.U*S.D*S.U' - S.P*A*S.P'
186-
2×2 Matrix{Float64}:
187-
0.0 0.0
188-
0.0 0.0
185+
julia> S.U * S.D * S.U' ≈ S.P * A * S.P'
186+
true
189187
190188
julia> S = bunchkaufman(Symmetric(A, :L))
191189
BunchKaufman{Float64, Matrix{Float64}, Vector{Int64}}
@@ -202,10 +200,8 @@ permutation:
202200
2
203201
1
204202
205-
julia> S.L*S.D*S.L' - A[S.p, S.p]
206-
2×2 Matrix{Float64}:
207-
0.0 0.0
208-
0.0 0.0
203+
julia> S.L * S.D * S.L' ≈ A[S.p, S.p]
204+
true
209205
```
210206
"""
211207
bunchkaufman(A::AbstractMatrix{T}, rook::Bool=false; check::Bool = true) where {T} =

src/matmul.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ end
692692
# the aggressive constprop pushes tA and tB into gemm_wrapper!, which is needed for wrap calls within it
693693
# to be concretely inferred
694694
Base.@constprop :aggressive function syrk_wrapper!(C::StridedMatrix{T}, tA::AbstractChar, A::StridedVecOrMat{T},
695-
alpha::Number, beta::Number) where {T<:BlasFloat}
695+
α::Number, β::Number) where {T<:BlasFloat}
696696
nC = checksquare(C)
697697
tA_uc = uppercase(tA) # potentially convert a WrapperChar to a Char
698698
if tA_uc == 'T'
@@ -708,16 +708,16 @@ Base.@constprop :aggressive function syrk_wrapper!(C::StridedMatrix{T}, tA::Abst
708708

709709
# BLAS.syrk! only updates symmetric C
710710
# alternatively, make non-zero β a show-stopper for BLAS.syrk!
711-
if iszero(beta) || issymmetric(C)
712-
α, β = promote(alpha, beta, zero(T))
711+
if iszero(β) || issymmetric(C)
712+
alpha, beta = promote(α, β, zero(T))
713713
if (alpha isa Union{Bool,T} &&
714714
beta isa Union{Bool,T} &&
715715
stride(A, 1) == stride(C, 1) == 1 &&
716716
_fullstride2(A) && _fullstride2(C))
717717
return copytri!(BLAS.syrk!('U', tA, alpha, A, beta, C), 'U')
718718
end
719719
end
720-
return gemm_wrapper!(C, tA, tAt, A, A, alpha, beta)
720+
return gemm_wrapper!(C, tA, tAt, A, A, α, β)
721721
end
722722
# legacy method
723723
syrk_wrapper!(C::StridedMatrix{T}, tA::AbstractChar, A::StridedVecOrMat{T}, _add::MulAddMul = MulAddMul()) where {T<:BlasFloat} =
@@ -743,7 +743,7 @@ Base.@constprop :aggressive function herk_wrapper!(C::Union{StridedMatrix{T}, St
743743
# Result array does not need to be initialized as long as beta==0
744744
# C = Matrix{T}(undef, mA, mA)
745745

746-
if iszero(β) || issymmetric(C)
746+
if iszero(β) || ishermitian(C)
747747
alpha, beta = promote(α, β, zero(T))
748748
if (alpha isa Union{Bool,T} &&
749749
beta isa Union{Bool,T} &&
@@ -932,7 +932,7 @@ function __generic_matvecmul!(f::F, C::AbstractVector, A::AbstractVecOrMat, B::A
932932
@inbounds begin
933933
if length(B) == 0
934934
for k = eachindex(C)
935-
@stable_muladdmul _modify!(MulAddMul(alpha,beta), false, C, k)
935+
@stable_muladdmul _modify!(MulAddMul(alpha,beta), zero(eltype(C)), C, k)
936936
end
937937
else
938938
for k = eachindex(C)
@@ -953,7 +953,7 @@ function __generic_matvecmul!(::typeof(identity), C::AbstractVector, A::Abstract
953953
@inbounds begin
954954
for i in eachindex(C)
955955
if length(B) == 0
956-
C[i] = false
956+
C[i] = zero(eltype(C))
957957
else
958958
@stable_muladdmul _modify!(MulAddMul(alpha, beta), A[i]*B[1], C, i)
959959
end

src/symmetric.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function copyto!(dest::Symmetric, src::Symmetric)
352352
elseif src.uplo == dest.uplo
353353
copytrito!(dest.data, src.data, src.uplo)
354354
else
355-
transpose!(dest.data, Base.unalias(dest.data, src.data))
355+
copytrito!(dest.data, transpose(Base.unalias(dest.data, src.data)), dest.uplo)
356356
end
357357
return dest
358358
end
@@ -363,7 +363,7 @@ function copyto!(dest::Hermitian, src::Hermitian)
363363
elseif src.uplo == dest.uplo
364364
copytrito!(dest.data, src.data, src.uplo)
365365
else
366-
adjoint!(dest.data, Base.unalias(dest.data, src.data))
366+
copytrito!(dest.data, adjoint(Base.unalias(dest.data, src.data)), dest.uplo)
367367
end
368368
return dest
369369
end
@@ -445,8 +445,6 @@ adjoint(A::Hermitian) = A
445445
transpose(A::Symmetric) = A
446446
adjoint(A::Symmetric{<:Real}) = A
447447
transpose(A::Hermitian{<:Real}) = A
448-
adjoint(A::Symmetric) = Adjoint(A)
449-
transpose(A::Hermitian) = Transpose(A)
450448

451449
real(A::Symmetric{<:Real}) = A
452450
real(A::Hermitian{<:Real}) = A

test/matmul.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ using Base: rtoldefault
66
using Test, LinearAlgebra, Random
77
using LinearAlgebra: mul!, Symmetric, Hermitian
88

9+
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
10+
11+
isdefined(Main, :SizedArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "SizedArrays.jl"))
12+
using .Main.SizedArrays
13+
914
## Test Julia fallbacks to BLAS routines
1015

1116
mul_wrappers = [
@@ -1176,4 +1181,16 @@ end
11761181
end
11771182
end
11781183

1184+
@testset "zero-length generic matvec" begin
1185+
m = SizedArrays.SizedArray{(2,2)}(ones(2,2))
1186+
A = fill(m, 2, 0)
1187+
v = fill(m, size(A,2))
1188+
w = similar(v, size(A,1))
1189+
mul!(w, A, v)
1190+
@test all(iszero, w)
1191+
A = fill(m, 0, 2)
1192+
mul!(w, A', v)
1193+
@test all(iszero, w)
1194+
end
1195+
11791196
end # module TestMatmul

test/symmetric.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,4 +1163,19 @@ end
11631163
end
11641164
end
11651165

1166+
@testset "copyto! with mismatched uplo" begin
1167+
for (S,tf) in ((Symmetric, transpose), (Hermitian, adjoint))
1168+
for (uplo1,uplo2) in [(:U,:L), (:L, :U)]
1169+
M = Matrix{Complex{BigFloat}}(undef, 2, 2)
1170+
M[1,1] = M[2,2] = 3
1171+
isupper = uplo1 == :U
1172+
M[1+!isupper, 1+isupper] = 4+3im
1173+
H1 = S(M, uplo1)
1174+
H2 = 2 * S(tf(M), uplo2)
1175+
copyto!(H2, H1)
1176+
@test H2 == H1
1177+
end
1178+
end
1179+
end
1180+
11661181
end # module TestSymmetric

0 commit comments

Comments
 (0)