Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,6 @@ zero(a::AbstractSparseArray{Tv,Ti}) where {Tv,Ti} = spzeros(Tv, Ti, size(a)...)
LinearAlgebra.diagzero(D::Diagonal{<:AbstractSparseMatrix{T}},i,j) where {T} =
spzeros(T, size(D.diag[i], 1), size(D.diag[j], 2))

include("precompile.jl")

end
24 changes: 24 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# Runs the common operations on Float64 arrays while the package image is built, so that their
# native code is cached; `show` and the `\` polyalgorithm otherwise take seconds on first call.
if Base.generating_output()
let
A = sparse([1, 2, 3, 1, 3], [1, 2, 3, 3, 1], [4.0, 5.0, 6.0, 1.0, 1.0])
x = [1.0, 2.0, 3.0]
v = sparsevec([1, 3], [1.0, 2.0], 3)
A[1, 2]; A[1:2, 2:3]; A[:, 2]; A[2, 2] = 5.0
A * x; A * A; A' * x; A * v; A + A; A - A; 2 * A
A .* 2; A .+ A; A .* A
copy(A'); sum(A); findnz(A); dropzeros(A); diag(A); kron(A, A)
hcat(A, A); vcat(A, A); [A A; A A]
v + v; dot(v, v)
sprint(show, MIME"text/plain"(), A); sprint(show, A)
sprint(show, MIME"text/plain"(), v); sprint(show, v)
@static if Base.USE_GPL_LIBS
A \ x; lu(A) \ x; qr(A) \ x
H = Hermitian(A' * A + 10 * LinearAlgebra.I)
cholesky(H) \ x; ldlt(H) \ x
end
end
end
18 changes: 18 additions & 0 deletions test/solvers/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ end
end
end

@static if COMPREHENSIVE
@testset "the package image holds native code for `show` and `\\`" begin
script = """
using LinearAlgebra
function cached(f, types)
mi = Base.method_instance(f, types)
return mi !== nothing && isdefined(mi, :cache) && mi.cache.invoke != C_NULL
end
S = SparseMatrixCSC{Float64,Int}
if Base.JLOptions().use_pkgimages != 0
@test cached(show, (typeof(IOBuffer()), MIME"text/plain", S))
@test cached(\\, (S, Vector{Float64}))
end
"""
@test success(pipeline(testprocess(script); stdout, stderr))
end
end

@testset "SuiteSparse library directory override (#250)" begin
L = SparseArrays.LibSuiteSparse
original_dir = L.libdir()
Expand Down
Loading