Skip to content

Commit

Permalink
Merge pull request #572 from JuliaSparse/backports-release-1.10
Browse files Browse the repository at this point in the history
Backports to v1.10.7
  • Loading branch information
dkarrasch authored Nov 3, 2024
2 parents 5c37298 + ec38631 commit 8c84b8c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 38 deletions.
24 changes: 8 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,27 @@ jobs:
fail-fast: false
matrix:
version:
- '~1.10'
- '1.10'
os:
- ubuntu-latest
- windows-latest
arch:
- x64
- x86
include:
- os: macOS-latest
arch: aarch64
version: '~1.10'
- os: ubuntu-latest
arch: x86
version: '~1.10'
version: '1.10'
- os: macOS-13
arch: x64
version: '1.10'
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-${{ matrix.os }}
${{ runner.os }}-
- uses: julia-actions/cache@v2
- run: julia --color=yes .ci/test_and_change_uuid.jl
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
Expand All @@ -65,7 +57,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1.10'
Expand Down
9 changes: 7 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DocTestSetup = :(using SparseArrays, LinearAlgebra)
Julia has support for sparse vectors and [sparse matrices](https://en.wikipedia.org/wiki/Sparse_matrix)
in the `SparseArrays` stdlib module. Sparse arrays are arrays that contain enough zeros that storing them in a special data structure leads to savings in space and execution time, compared to dense arrays.

External packages which implement different sparse storage types, multidimensional sparse arrays, and more can be found in [Noteworthy external packages](@ref man-csc)
External packages which implement different sparse storage types, multidimensional sparse arrays, and more can be found in [Noteworthy External Sparse Packages](@ref)

## [Compressed Sparse Column (CSC) Sparse Matrix Storage](@id man-csc)

Expand Down Expand Up @@ -202,6 +202,11 @@ section of the standard library reference.
| [`sprandn(m,n,d)`](@ref) | [`randn(m,n)`](@ref) | Creates a *m*-by-*n* random matrix (of density *d*) with iid non-zero elements distributed according to the standard normal (Gaussian) distribution. |
| [`sprandn(rng,m,n,d)`](@ref) | [`randn(rng,m,n)`](@ref) | Creates a *m*-by-*n* random matrix (of density *d*) with iid non-zero elements generated with the `rng` random number generator |


```@meta
DocTestSetup = nothing
```

# [SparseArrays API](@id stdlib-sparse-arrays)

```@docs
Expand Down Expand Up @@ -241,7 +246,7 @@ SparseArrays.ftranspose!
```@meta
DocTestSetup = nothing
```
# Noteworthy external packages
# Noteworthy External Sparse Packages

Several other Julia packages provide sparse matrix implementations that should be mentioned:

Expand Down
23 changes: 15 additions & 8 deletions docs/src/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
DocTestSetup = :(using LinearAlgebra, SparseArrays)
```

Sparse matrix solvers call functions from [SuiteSparse](http://suitesparse.com). The following factorizations are available:
## [Sparse Linear Algebra](@id stdlib-sparse-linalg)

Sparse matrix solvers call functions from [SuiteSparse](http://suitesparse.com).

The following factorizations are available:

1. [`cholesky`](@ref SparseArrays.CHOLMOD.cholesky)
2. [`ldlt`](@ref SparseArrays.CHOLMOD.ldlt)
3. [`lu`](@ref SparseArrays.UMFPACK.lu)
4. [`qr`](@ref SparseArrays.SPQR.qr)

| Type | Description |
|:--------------------------------- |:--------------------------------------------- |
| `CHOLMOD.Factor` | Cholesky factorization |
| `UMFPACK.UmfpackLU` | LU factorization |
| `SPQR.QRSparse` | QR factorization |

Other solvers such as [Pardiso.jl](https://github.com/JuliaSparse/Pardiso.jl/) are available as external packages. [Arpack.jl](https://julialinearalgebra.github.io/Arpack.jl/stable/) provides `eigs` and `svds` for iterative solution of eigensystems and singular value decompositions.
Other solvers such as [Pardiso.jl](https://github.com/JuliaSparse/Pardiso.jl/) are available
as external packages. [Arpack.jl](https://julialinearalgebra.github.io/Arpack.jl/stable/)
provides `eigs` and `svds` for iterative solution of eigensystems and singular value
decompositions.

These factorizations are described in more detail in the
[`Linear Algebra`](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/)
section of the manual:

1. [`cholesky`](@ref SparseArrays.CHOLMOD.cholesky)
2. [`ldlt`](@ref SparseArrays.CHOLMOD.ldlt)
3. [`lu`](@ref SparseArrays.UMFPACK.lu)
4. [`qr`](@ref SparseArrays.SPQR.qr)

```@docs
```@docs; canonical=false
SparseArrays.CHOLMOD.cholesky
SparseArrays.CHOLMOD.cholesky!
SparseArrays.CHOLMOD.ldlt
Expand Down
6 changes: 3 additions & 3 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ for op ∈ (:+, :-)
end
end

LinearAlgebra.generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion, B::DenseMatrixUnion, _add::MulAddMul) =
@inline LinearAlgebra.generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion, B::DenseMatrixUnion, _add::MulAddMul) =
spdensemul!(C, tA, tB, A, B, _add)
LinearAlgebra.generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion, B::AbstractTriangular, _add::MulAddMul) =
@inline LinearAlgebra.generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion, B::AbstractTriangular, _add::MulAddMul) =
spdensemul!(C, tA, tB, A, B, _add)
LinearAlgebra.generic_matvecmul!(C::StridedVecOrMat, tA, A::SparseMatrixCSCUnion, B::DenseInputVector, _add::MulAddMul) =
@inline LinearAlgebra.generic_matvecmul!(C::StridedVecOrMat, tA, A::SparseMatrixCSCUnion, B::DenseInputVector, _add::MulAddMul) =
spdensemul!(C, tA, 'N', A, B, _add)

Base.@constprop :aggressive function spdensemul!(C, tA, tB, A, B, _add)
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/spqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Matrix{T}(Q::QRSparseQ) where {T} = lmul!(Q, Matrix{T}(I, size(Q, 1), min(size(Q

# From SPQR manual p. 6
_default_tol(A::AbstractSparseMatrixCSC) =
20*sum(size(A))*eps(real(eltype(A)))*maximum(norm(view(A, :, i)) for i in 1:size(A, 2))
20*sum(size(A))*eps()*maximum(norm(view(A, :, i)) for i in 1:size(A, 2))

"""
qr(A::SparseMatrixCSC; tol=_default_tol(A), ordering=ORDERING_DEFAULT) -> QRSparse
Expand Down
2 changes: 2 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ SparseMatrixCSC(m, n, colptr::ReadOnly, rowval::ReadOnly, nzval::Vector) =

"""
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, m::Integer, n::Integer)
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, (m,n)::NTuple{2,Integer})
Creates an empty sparse matrix with element type `Tv` and integer type `Ti` of size `m × n`.
"""
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, m::Integer, n::Integer) where {Tv, Ti} = spzeros(Tv, Ti, m, n)
SparseMatrixCSC{Tv,Ti}(::UndefInitializer, mn::NTuple{2,Integer}) where {Tv, Ti} = spzeros(Tv, Ti, mn...)

"""
`FixedSparseCSC{Tv,Ti<:Integer} <: AbstractSparseMatrixCSC{Tv,Ti}`
Expand Down
1 change: 1 addition & 0 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SparseVector(n::Integer, nzind::Vector{Ti}, nzval::Vector{Tv}) where {Tv,Ti} =
SparseVector{Tv,Ti}(n, nzind, nzval)

SparseVector{Tv, Ti}(::UndefInitializer, n::Integer) where {Tv, Ti} = SparseVector{Tv, Ti}(n, Ti[], Tv[])
SparseVector{Tv, Ti}(::UndefInitializer, (n,)::Tuple{Integer}) where {Tv, Ti} = SparseVector{Tv, Ti}(n, Ti[], Tv[])

"""
`FixedSparseVector{Tv,Ti<:Integer} <: AbstractCompressedVector{Tv,Ti}`
Expand Down
4 changes: 4 additions & 0 deletions test/ambiguous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
original_depot_path = copy(Base.DEPOT_PATH)
original_load_path = copy(Base.LOAD_PATH)
original_env = copy(ENV)
original_project = Base.active_project()
###

import Pkg
Expand All @@ -13,6 +14,7 @@ import Pkg
if Base.find_package("Aqua") === nothing
@debug "Installing Aqua.jl for SparseArrays.jl tests"
iob = IOBuffer()
Pkg.activate(; temp = true)
try
# TODO: make this version tie to compat in Project.toml
# or do this another safer way
Expand Down Expand Up @@ -103,4 +105,6 @@ end
for (k, v) in pairs(original_env)
ENV[k] = v
end

Base.set_active_project(original_project)
###
11 changes: 7 additions & 4 deletions test/sparsematrix_constructors_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ end
@test sparse([1, 1, 2, 2, 2], [1, 2, 1, 2, 2], -1.0, 2, 2, *) == sparse([1, 1, 2, 2], [1, 2, 1, 2], [-1.0, -1.0, -1.0, 1.0], 2, 2)
@test sparse(sparse(Int32.(1:5), Int32.(1:5), trues(5))') isa SparseMatrixCSC{Bool,Int32}
# undef initializer
m = SparseMatrixCSC{Float32, Int16}(undef, 3, 4)
@test size(m) == (3, 4)
@test eltype(m) === Float32
@test m == spzeros(3, 4)
sz = (3, 4)
for m in (SparseMatrixCSC{Float32, Int16}(undef, sz...), SparseMatrixCSC{Float32, Int16}(undef, sz),
similar(SparseMatrixCSC{Float32, Int16}, sz))
@test size(m) == sz
@test eltype(m) === Float32
@test m == spzeros(sz...)
end
end

@testset "spzeros for pattern creation (structural zeros)" begin
Expand Down
12 changes: 8 additions & 4 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ end
end

@testset "Undef initializer" begin
v = SparseVector{Float32, Int16}(undef, 4)
@test size(v) == (4, )
@test eltype(v) === Float32
@test v == spzeros(Float32, 4)
sz = (4,)
for v in (SparseVector{Float32, Int16}(undef, sz),
SparseVector{Float32, Int16}(undef, sz...),
similar(SparseVector{Float32, Int16}, sz))
@test size(v) == sz
@test eltype(v) === Float32
@test v == spzeros(Float32, sz...)
end
end
end
### Element access
Expand Down

0 comments on commit 8c84b8c

Please sign in to comment.