Skip to content

Commit

Permalink
Set allocatetmp=false by default
Browse files Browse the repository at this point in the history
Better to be safe than optimized
  • Loading branch information
timholy committed Dec 19, 2023
1 parent 857e7e8 commit feaf05e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/symwoodbury.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SymWoodbury{T,AType,BType,DType,DpType} <: AbstractWoodbury{T}
end

"""
W = SymWoodbury(A, B, D; allocatetmp::Bool=true)
W = SymWoodbury(A, B, D; allocatetmp::Bool=false)
Represent a matrix of the form `W = A + BDBᵀ`, where `A` and `D` are symmetric.
Equations `Wx = b` will be solved using the
Expand All @@ -28,7 +28,7 @@ or factorization.
See also [Woodbury](@ref), where `allocatetmp` is explained.
"""
function SymWoodbury(A, B::AbstractVecOrMat, D; allocatetmp::Bool=true)
function SymWoodbury(A, B::AbstractVecOrMat, D; allocatetmp::Bool=false)
@noinline throwdmm(B, D, A) = throw(DimensionMismatch("Sizes of B ($(size(B))) and/or D ($(size(D))) are inconsistent with A ($(size(A)))"))

n = size(A, 1)
Expand Down
6 changes: 3 additions & 3 deletions src/woodbury.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Woodbury{T,AType,UType,VType,CType,CpType} <: AbstractWoodbury{T}
end

"""
W = Woodbury(A, U, C, V; allocatetmp::Bool=true)
W = Woodbury(A, U, C, V; allocatetmp::Bool=false)
Represent a matrix `W = A + UCV`.
Equations `Wx = b` will be solved using the
Expand All @@ -27,14 +27,14 @@ If `allocatetmp` is true, temporary storage used for intermediate steps in
multiplication and division will be allocated.
!!! warning
If you'll use the same `W` in multiple threads, you should set `allocatetmp=false`
If you'll use the same `W` in multiple threads, you should use `allocatetmp=false`
or risk data races.
See also [SymWoodbury](@ref).
"""
function Woodbury(A, U::AbstractMatrix, C, V::AbstractMatrix; allocatetmp::Bool=true)
function Woodbury(A, U::AbstractMatrix, C, V::AbstractMatrix; allocatetmp::Bool=false)
@noinline throwdmm1(U, V, A) = throw(DimensionMismatch("Sizes of U ($(size(U))) and/or V ($(size(V))) are inconsistent with A ($(size(A)))"))
@noinline throwdmm2(k) = throw(DimensionMismatch("C should be $(k)x$(k)"))

Expand Down
2 changes: 1 addition & 1 deletion test/symwoodbury.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ for elty in (Float32, Float64, ComplexF32, ComplexF64, Int)
ε = eps(abs2(float(one(elty))))
A = Diagonal(a)

for W in (SymWoodbury(A, B, D), SymWoodbury(A, B, D; allocatetmp=false), SymWoodbury(A, B[:,1][:], 2.))
for W in (SymWoodbury(A, B, D), SymWoodbury(A, B, D; allocatetmp=true), SymWoodbury(A, B[:,1][:], 2.))

@test issymmetric(W)
F = Matrix(W)
Expand Down
2 changes: 1 addition & 1 deletion test/woodbury.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for elty in (Float32, Float64, ComplexF32, ComplexF64, Int)
T = Tridiagonal(dl, d, du)

# Matrix for A
for W in (Woodbury(T, U, C, V), Woodbury(T, U, C, V; allocatetmp=false))
for W in (Woodbury(T, U, C, V), Woodbury(T, U, C, V; allocatetmp=true))
@test size(W, 1) == n
@test size(W) == (n, n)
@test axes(W) === (Base.OneTo(n), Base.OneTo(n))
Expand Down

0 comments on commit feaf05e

Please sign in to comment.