Skip to content

Commit 437b35d

Browse files
authored
Merge branch 'master' into sgj/evalpoly
2 parents e051033 + 8cc4216 commit 437b35d

34 files changed

+633
-217
lines changed

.ci/create_sysimage.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using PackageCompiler, Libdl
2+
3+
function create_sysimage_linear_algebra()
4+
sysimage = tempname() * "." * Libdl.dlext
5+
6+
if haskey(ENV, "BUILDKITE")
7+
ncores = Sys.CPU_THREADS
8+
else
9+
ncores = ceil(Int, Sys.CPU_THREADS / 2)
10+
end
11+
12+
withenv("JULIA_IMAGE_THREADS" => ncores) do
13+
create_sysimage(["LinearAlgebra", "Test", "Distributed", "Dates", "Printf", "Random"]; sysimage_path=sysimage, incremental=false, filter_stdlibs=true)
14+
end
15+
return sysimage, ncores
16+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include("create_sysimage.jl")
2+
sysimage, ncores = create_sysimage_linear_algebra()
3+
doc_file = joinpath(@__DIR__, "..", "docs", "make.jl")
4+
withenv("JULIA_NUM_THREADS" => 1) do
5+
run(`$(Base.julia_cmd()) --sysimage=$sysimage --project=$(dirname(doc_file)) $doc_file`)
6+
end

.ci/create_sysimage_and_run_tests.jl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
using PackageCompiler, Libdl
2-
3-
sysimage = tempname() * "." * Libdl.dlext
4-
5-
if haskey(ENV, "BUILDKITE")
6-
ncores = Sys.CPU_THREADS
7-
else
8-
ncores = ceil(Int, Sys.CPU_THREADS / 2)
9-
end
10-
11-
withenv("JULIA_IMAGE_THREADS" => ncores) do
12-
create_sysimage(["LinearAlgebra", "Test", "Distributed", "Dates", "Printf", "Random"]; sysimage_path=sysimage, incremental=false, filter_stdlibs=true)
13-
end
14-
1+
include("create_sysimage.jl")
2+
sysimage, ncores = create_sysimage_linear_algebra()
153
current_dir = @__DIR__
164
cmd = """Base.runtests(["LinearAlgebra"]; propagate_project=true, ncores=$ncores)"""
175
withenv("JULIA_NUM_THREADS" => 1) do

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
version: 'nightly'
2222
- name: Generate docs
2323
run: |
24-
julia --project --color=yes -e ''
25-
julia --project --color=yes -e 'using Pkg; Pkg.respect_sysimage_versions(false); Pkg.activate("docs"); Pkg.develop(PackageSpec(path = pwd()))'
26-
julia --project=docs --color=yes docs/make.jl
24+
julia --color=yes --project=.ci -e 'using Pkg; Pkg.instantiate()'
25+
julia --color=yes --project=docs -e 'using Pkg; Pkg.instantiate()'
26+
julia --color=yes --project=.ci .ci/create_sysimage_and_run_docs.jl
2727
env:
2828
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
4+
5+
[sources]
6+
LinearAlgebra = {path = ".."}

src/LinearAlgebra.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Base: USE_BLAS64, abs, acos, acosh, acot, acoth, acsc, acsch, adjoint, as
1616
permutedims, permuterows!, power_by_squaring, promote_rule, real, sec, sech, setindex!,
1717
show, similar, sin, sincos, sinh, size, sqrt, strides, stride, tan, tanh, transpose, trunc,
1818
typed_hcat, vec, view, zero
19+
import Base: AbstractArray, AbstractMatrix, Array, Matrix
1920
using Base: IndexLinear, promote_eltype, promote_op, print_matrix,
2021
@propagate_inbounds, reduce, typed_hvcat, typed_vcat, require_one_based_indexing,
2122
splat, BitInteger

src/adjtrans.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ const AdjointAbsVec{T} = Adjoint{T,<:AbstractVector}
319319
const AdjointAbsMat{T} = Adjoint{T,<:AbstractMatrix}
320320
const TransposeAbsVec{T} = Transpose{T,<:AbstractVector}
321321
const TransposeAbsMat{T} = Transpose{T,<:AbstractMatrix}
322-
const AdjOrTransAbsVec{T} = AdjOrTrans{T,<:AbstractVector}
323-
const AdjOrTransAbsMat{T} = AdjOrTrans{T,<:AbstractMatrix}
322+
const AdjOrTransAbsVec{T,V<:AbstractVector} = AdjOrTrans{T,V}
323+
const AdjOrTransAbsMat{T,M<:AbstractMatrix} = AdjOrTrans{T,M}
324324

325325
# for internal use below
326326
wrapperop(_) = identity

src/bidiag.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ julia> Bidiagonal(A, :L) # contains the main diagonal and first subdiagonal of A
109109
⋅ ⋅ 4 4
110110
```
111111
"""
112-
function Bidiagonal(A::AbstractMatrix, uplo::Symbol)
113-
Bidiagonal(diag(A, 0), diag(A, uplo === :U ? 1 : -1), uplo)
112+
function (::Type{Bi})(A::AbstractMatrix, uplo::Symbol) where {Bi<:Bidiagonal}
113+
Bi(diag(A, 0), diag(A, uplo === :U ? 1 : -1), uplo)
114114
end
115115

116116

@@ -161,7 +161,7 @@ end
161161
# we explicitly compare the possible bands as b.band may be constant-propagated
162162
return @inbounds A.ev[b.index]
163163
else
164-
return diagzero(A, Tuple(_cartinds(b))...)
164+
return diagzero(A, b)
165165
end
166166
end
167167

@@ -220,7 +220,12 @@ promote_rule(::Type{<:Tridiagonal}, ::Type{<:Bidiagonal}) = Tridiagonal
220220
AbstractMatrix{T}(A::Bidiagonal) where {T} = Bidiagonal{T}(A)
221221
AbstractMatrix{T}(A::Bidiagonal{T}) where {T} = copy(A)
222222

223-
convert(::Type{T}, m::AbstractMatrix) where {T<:Bidiagonal} = m isa T ? m : T(m)::T
223+
function convert(::Type{T}, A::AbstractMatrix) where T<:Bidiagonal
224+
checksquare(A)
225+
isbanded(A, -1, 1) || throw(InexactError(:convert, T, A))
226+
iszero(diagview(A, 1)) ? T(A, :L) :
227+
iszero(diagview(A, -1)) ? T(A, :U) : throw(InexactError(:convert, T, A))
228+
end
224229

225230
similar(B::Bidiagonal, ::Type{T}) where {T} = Bidiagonal(similar(B.dv, T), similar(B.ev, T), B.uplo)
226231
similar(B::Bidiagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = similar(B.dv, T, dims)
@@ -405,14 +410,15 @@ end
405410
function diag(M::Bidiagonal, n::Integer=0)
406411
# every branch call similar(..., ::Int) to make sure the
407412
# same vector type is returned independent of n
408-
v = similar(M.dv, max(0, length(M.dv)-abs(n)))
413+
dinds = diagind(M, n, IndexStyle(M))
414+
v = similar(M.dv, length(dinds))
409415
if n == 0
410416
copyto!(v, M.dv)
411417
elseif (n == 1 && M.uplo == 'U') || (n == -1 && M.uplo == 'L')
412418
copyto!(v, M.ev)
413419
elseif -size(M,1) <= n <= size(M,1)
414-
for i in eachindex(v)
415-
v[i] = M[BandIndex(n,i)]
420+
for i in eachindex(v, dinds)
421+
@inbounds v[i] = M[BandIndex(n,i)]
416422
end
417423
end
418424
return v

src/blas.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export
8484
trsm!,
8585
trsm
8686

87-
using ..LinearAlgebra: libblastrampoline, BlasReal, BlasComplex, BlasFloat, BlasInt, DimensionMismatch, checksquare, chkstride1
87+
using ..LinearAlgebra: libblastrampoline, BlasReal, BlasComplex, BlasFloat, BlasInt,
88+
DimensionMismatch, checksquare, chkstride1, SingularException
8889

8990
include("lbt.jl")
9091

@@ -128,6 +129,10 @@ Set the number of threads the BLAS library should use equal to `n::Integer`.
128129
129130
Also accepts `nothing`, in which case julia tries to guess the default number of threads.
130131
Passing `nothing` is discouraged and mainly exists for historical reasons.
132+
133+
!!! note
134+
Some BLAS libraries, such as Apple Accelerate, cannot be configured to use a fixed number of threads.
135+
For these backends, `set_num_threads()` is a no-op. See also [`get_num_threads`](@ref).
131136
"""
132137
set_num_threads(nt::Integer)::Nothing = lbt_set_num_threads(Int32(nt))
133138
function set_num_threads(::Nothing)
@@ -147,6 +152,10 @@ Get the number of threads the BLAS library is using.
147152
148153
!!! compat "Julia 1.6"
149154
`get_num_threads` requires at least Julia 1.6.
155+
156+
!!! note
157+
Some BLAS libraries, such as Apple Accelerate, cannot be configured to use a fixed number of threads.
158+
For these backends, `get_num_threads()` always returns `1`. See also [`set_num_threads`](@ref).
150159
"""
151160
get_num_threads()::Int = lbt_get_num_threads()
152161

@@ -1369,6 +1378,11 @@ for (fname, elty) in ((:dtrsv_,:Float64),
13691378
throw(DimensionMismatch(lazy"size of A is $n != length(x) = $(length(x))"))
13701379
end
13711380
chkstride1(A)
1381+
if diag == 'N'
1382+
for i in 1:n
1383+
iszero(A[i,i]) && throw(SingularException(i))
1384+
end
1385+
end
13721386
px, stx = vec_pointer_stride(x, ArgumentError("input vector with 0 stride is not allowed"))
13731387
GC.@preserve x ccall((@blasfunc($fname), libblastrampoline), Cvoid,
13741388
(Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt},
@@ -2217,6 +2231,11 @@ for (mmname, smname, elty) in
22172231
end
22182232
chkstride1(A)
22192233
chkstride1(B)
2234+
if diag == 'N'
2235+
for i in 1:k
2236+
iszero(A[i,i]) && throw(SingularException(i))
2237+
end
2238+
end
22202239
ccall((@blasfunc($smname), libblastrampoline), Cvoid,
22212240
(Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{UInt8},
22222241
Ref{BlasInt}, Ref{BlasInt}, Ref{$elty}, Ptr{$elty},

src/cholesky.jl

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ julia> C.U
6565
⋅ ⋅ 3.0
6666
6767
julia> C.L
68-
3×3 LowerTriangular{Float64, Matrix{Float64}}:
68+
3×3 LowerTriangular{Float64, Adjoint{Float64, Matrix{Float64}}}:
6969
2.0 ⋅ ⋅
7070
6.0 1.0 ⋅
7171
-8.0 5.0 3.0
@@ -305,7 +305,7 @@ function _cholpivoted!(A::AbstractMatrix, ::Type{UpperTriangular}, tol::Real, ch
305305
rTA = real(eltype(A))
306306
# checks
307307
Base.require_one_based_indexing(A)
308-
n = LinearAlgebra.checksquare(A)
308+
n = checksquare(A)
309309
# initialization
310310
piv = collect(1:n)
311311
dots = zeros(rTA, n)
@@ -354,7 +354,7 @@ function _cholpivoted!(A::AbstractMatrix, ::Type{LowerTriangular}, tol::Real, ch
354354
rTA = real(eltype(A))
355355
# checks
356356
Base.require_one_based_indexing(A)
357-
n = LinearAlgebra.checksquare(A)
357+
n = checksquare(A)
358358
# initialization
359359
piv = collect(1:n)
360360
dots = zeros(rTA, n)
@@ -530,7 +530,7 @@ julia> C.U
530530
⋅ ⋅ 3.0
531531
532532
julia> C.L
533-
3×3 LowerTriangular{Float64, Matrix{Float64}}:
533+
3×3 LowerTriangular{Float64, Adjoint{Float64, Matrix{Float64}}}:
534534
2.0 ⋅ ⋅
535535
6.0 1.0 ⋅
536536
-8.0 5.0 3.0
@@ -664,30 +664,15 @@ copy(C::CholeskyPivoted) = CholeskyPivoted(copy(C.factors), C.uplo, C.piv, C.ran
664664
size(C::Union{Cholesky, CholeskyPivoted}) = size(C.factors)
665665
size(C::Union{Cholesky, CholeskyPivoted}, d::Integer) = size(C.factors, d)
666666

667-
function _choleskyUfactor(Cfactors, Cuplo)
668-
if Cuplo === 'U'
669-
return UpperTriangular(Cfactors)
670-
else
671-
return copy(LowerTriangular(Cfactors)')
672-
end
673-
end
674-
function _choleskyLfactor(Cfactors, Cuplo)
675-
if Cuplo === 'L'
676-
return LowerTriangular(Cfactors)
677-
else
678-
return copy(UpperTriangular(Cfactors)')
679-
end
680-
end
681-
682667
function getproperty(C::Cholesky, d::Symbol)
683668
Cfactors = getfield(C, :factors)
684669
Cuplo = getfield(C, :uplo)
685670
if d === :U
686-
_choleskyUfactor(Cfactors, Cuplo)
671+
UpperTriangular(Cuplo == 'U' ? Cfactors : Cfactors')
687672
elseif d === :L
688-
_choleskyLfactor(Cfactors, Cuplo)
673+
LowerTriangular(Cuplo == 'L' ? Cfactors : Cfactors')
689674
elseif d === :UL
690-
return (Cuplo === 'U' ? UpperTriangular(Cfactors) : LowerTriangular(Cfactors))
675+
return (Cuplo == 'U' ? UpperTriangular(Cfactors) : LowerTriangular(Cfactors))
691676
else
692677
return getfield(C, d)
693678
end
@@ -704,9 +689,9 @@ function getproperty(C::CholeskyPivoted{T}, d::Symbol) where {T}
704689
Cfactors = getfield(C, :factors)
705690
Cuplo = getfield(C, :uplo)
706691
if d === :U
707-
_choleskyUfactor(Cfactors, Cuplo)
692+
UpperTriangular(Cuplo == 'U' ? Cfactors : Cfactors')
708693
elseif d === :L
709-
_choleskyLfactor(Cfactors, Cuplo)
694+
LowerTriangular(Cuplo == 'L' ? Cfactors : Cfactors')
710695
elseif d === :p
711696
return getfield(C, :piv)
712697
elseif d === :P
@@ -813,7 +798,7 @@ function rdiv!(B::AbstractMatrix, C::Cholesky)
813798
end
814799
end
815800

816-
function LinearAlgebra.rdiv!(B::AbstractMatrix, C::CholeskyPivoted)
801+
function rdiv!(B::AbstractMatrix, C::CholeskyPivoted)
817802
n = size(C, 2)
818803
for i in 1:size(B, 1)
819804
permute!(view(B, i, 1:n), C.piv)
@@ -965,7 +950,7 @@ function lowrankdowndate!(C::Cholesky, v::AbstractVector)
965950
s = conj(v[i]/Aii)
966951
s2 = abs2(s)
967952
if s2 > 1
968-
throw(LinearAlgebra.PosDefException(i))
953+
throw(PosDefException(i))
969954
end
970955
c = sqrt(1 - abs2(s))
971956

0 commit comments

Comments
 (0)