Skip to content

Commit 8d5e1d4

Browse files
committed
Merge branch 'main' into export_abstractmatrixcsc
2 parents 348dad9 + 4fd3aad commit 8d5e1d4

File tree

16 files changed

+135
-94
lines changed

16 files changed

+135
-94
lines changed

.ci/test_and_change_uuid.jl

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,27 @@ jobs:
2323
os:
2424
- ubuntu-latest
2525
- windows-latest
26-
- macOS-13 # intel
2726
julia-arch:
2827
- x64
2928
- x86
30-
exclude:
31-
- os: macOS-13
32-
julia-arch: x86
3329
include:
3430
- os: macOS-latest
3531
julia-arch: aarch64
3632
julia-version: 'nightly'
37-
33+
- os: macOS-13
34+
julia-arch: x64
35+
julia-version: 'nightly'
3836
steps:
3937
- uses: actions/checkout@v4
4038
- uses: julia-actions/setup-julia@v2
4139
with:
4240
version: ${{ matrix.julia-version }}
4341
arch: ${{ matrix.julia-arch }}
44-
- uses: actions/cache@v4
45-
env:
46-
cache-name: cache-artifacts
47-
with:
48-
path: ~/.julia/artifacts
49-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
50-
restore-keys: |
51-
${{ runner.os }}-test-${{ env.cache-name }}-
52-
${{ runner.os }}-test-${{ matrix.os }}
53-
${{ runner.os }}-
54-
- run: julia --color=yes .ci/test_and_change_uuid.jl
42+
- uses: julia-actions/cache@v2
5543
- uses: julia-actions/julia-buildpkg@v1
5644
- uses: julia-actions/julia-runtest@v1
5745
- uses: julia-actions/julia-processcoverage@v1
58-
- uses: codecov/codecov-action@v4
46+
- uses: codecov/codecov-action@v5
5947
with:
6048
file: lcov.info
6149
token: ${{ secrets.CODECOV_TOKEN }}
@@ -80,7 +68,6 @@ jobs:
8068
version: ${{ matrix.julia-version }}
8169
arch: ${{ matrix.julia-arch }}
8270
- uses: julia-actions/cache@v2
83-
- run: julia --color=yes .ci/test_and_change_uuid.jl
8471
- uses: julia-actions/julia-buildpkg@v1
8572
- uses: julia-actions/julia-runtest@v1
8673
env:
@@ -91,12 +78,10 @@ jobs:
9178
- uses: actions/checkout@v4
9279
- uses: julia-actions/setup-julia@v2
9380
with:
94-
# version: '1.6'
9581
version: 'nightly'
9682
- name: Generate docs
9783
run: |
98-
julia --color=yes -e 'write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"3f01184e-e22b-5df5-ae63-d93ebab69eaf\"\n"));'
99-
julia --project --color=yes -e 'using Pkg; Pkg.activate("docs"); Pkg.instantiate(); Pkg.develop(PackageSpec(path = pwd()))'
84+
julia --project --color=yes -e 'using Pkg; Pkg.activate("docs"); Pkg.develop(PackageSpec(path = pwd()))'
10085
julia --project=docs --color=yes docs/make.jl pdf
10186
env:
10287
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

LICENSE.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1-
The code in this repository is part of the Julia project. See the LICENSE file in the Julia project:
1+
MIT License
22

3-
https://github.com/JuliaLang/julia/blob/master/LICENSE.md
3+
Copyright (c) 2018-2024 SparseArrays.jl contributors:
4+
https://github.com/JuliaSparse/SparseArrays.jl/contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ This package ships as part of the Julia stdlib.
2020

2121
SparseArrays.jl provides functionality for working with sparse arrays in Julia.
2222

23-
## Using development versions of this package
24-
25-
To use a newer version of this package, you need to build Julia from scratch. The build process is the same as any other build except that you need to change the commit used in `stdlib/SparseArrays.version`.
26-
27-
It's also possible to load a development version of the package using [the trick used in the Section named "Using the development version of Pkg.jl" in the `Pkg.jl` repo](https://github.com/JuliaLang/Pkg.jl#using-the-development-version-of-pkgjl), but the capabilities are limited as all other packages will depend on the stdlib version of the package and will not work with the modified package.
28-
29-
The main environment may become inconsistent so you might need to run `Pkg.instantiate()` and/or `Pkg.resolve()` in the main or project environments if Julia complains about missing `Serialization.jl` in this package's dependencies.
30-
31-
For older (1.8 and before) `SuiteSparse.jl` needs to be bumped too.
32-
3323
## Updating SuiteSparse
3424

3525
In order to upgrade SparseArrays.jl to use a new release of SuiteSparse, the following steps are necessary:

docs/src/index.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,6 @@ section of the standard library reference.
206206
| [`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. |
207207
| [`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 |
208208

209-
## [Sparse Linear Algebra](@id stdlib-sparse-linalg)
210-
211-
Sparse matrix solvers call functions from [SuiteSparse](http://suitesparse.com). The following factorizations are available:
212-
213-
1. [`cholesky`](@ref SparseArrays.CHOLMOD.cholesky)
214-
2. [`ldlt`](@ref SparseArrays.CHOLMOD.ldlt)
215-
3. [`lu`](@ref SparseArrays.UMFPACK.lu)
216-
4. [`qr`](@ref SparseArrays.SPQR.qr)
217-
218-
| Type | Description |
219-
|:----------------------|:--------------------------------------------- |
220-
| `CHOLMOD.Factor` | Cholesky and LDLt factorizations |
221-
| `UMFPACK.UmfpackLU` | LU factorization |
222-
| `SPQR.QRSparse` | QR factorization |
223209

224210
```@meta
225211
DocTestSetup = nothing

docs/src/solvers.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
DocTestSetup = :(using LinearAlgebra, SparseArrays)
55
```
66

7+
## [Sparse Linear Algebra](@id stdlib-sparse-linalg)
8+
9+
Sparse matrix solvers call functions from [SuiteSparse](http://suitesparse.com).
10+
11+
The following factorizations are available:
12+
13+
1. [`cholesky`](@ref SparseArrays.CHOLMOD.cholesky)
14+
2. [`ldlt`](@ref SparseArrays.CHOLMOD.ldlt)
15+
3. [`lu`](@ref SparseArrays.UMFPACK.lu)
16+
4. [`qr`](@ref SparseArrays.SPQR.qr)
17+
18+
| Type | Description |
19+
|:----------------------|:--------------------------------------------- |
20+
| `CHOLMOD.Factor` | Cholesky and LDLt factorizations |
21+
| `UMFPACK.UmfpackLU` | LU factorization |
22+
| `SPQR.QRSparse` | QR factorization |
23+
24+
725
```@docs; canonical=false
826
SparseArrays.CHOLMOD.cholesky
927
SparseArrays.CHOLMOD.cholesky!

src/abstractsparse.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ else
186186
end
187187
end
188188

189+
macro allowscalar(p)
190+
quote
191+
$(allowscalar)($(esc(p)))
192+
@Core.latestworld
193+
end
194+
end
195+
189196
@inline _is_fixed(::AbstractArray) = false
190197
@inline _is_fixed(A::AbstractArray, Bs::Vararg{Any,N}) where N = _is_fixed(A) || (N > 0 && _is_fixed(Bs...))
191198
macro if_move_fixed(a...)

src/linalg.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ for op ∈ (:+, :-)
4747
end
4848
end
4949

50-
generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion2, B::DenseMatrixUnion, alpha::Number, beta::Number) =
50+
@inline generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion2, B::DenseMatrixUnion, alpha::Number, beta::Number) =
5151
spdensemul!(C, tA, tB, A, B, alpha, beta)
52-
generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion2, B::AbstractTriangular, alpha::Number, beta::Number) =
52+
@inline generic_matmatmul!(C::StridedMatrix, tA, tB, A::SparseMatrixCSCUnion2, B::AbstractTriangular, alpha::Number, beta::Number) =
5353
spdensemul!(C, tA, tB, A, B, alpha, beta)
54-
generic_matvecmul!(C::StridedVecOrMat, tA, A::SparseMatrixCSCUnion2, B::DenseInputVector, alpha::Number, beta::Number) =
54+
@inline generic_matvecmul!(C::StridedVecOrMat, tA, A::SparseMatrixCSCUnion2, B::DenseInputVector, alpha::Number, beta::Number) =
5555
spdensemul!(C, tA, 'N', A, B, alpha, beta)
5656

5757
Base.@constprop :aggressive function spdensemul!(C, tA, tB, A, B, alpha, beta)
@@ -188,6 +188,23 @@ function _A_mul_Bt_or_Bc!(tfun::Function, C::StridedMatrix, A::AbstractMatrix, B
188188
C
189189
end
190190

191+
function *(A::Diagonal, b::AbstractSparseVector)
192+
if size(A, 2) != length(b)
193+
throw(
194+
DimensionMismatch(lazy"The dimension of the matrix A $(size(A)) and of the vector b $(length(b))")
195+
)
196+
end
197+
T = promote_eltype(A, b)
198+
res = similar(b, T)
199+
nzind_b = nonzeroinds(b)
200+
nzval_b = nonzeros(b)
201+
nzval_res = nonzeros(res)
202+
for idx in eachindex(nzind_b)
203+
nzval_res[idx] = A.diag[nzind_b[idx]] * nzval_b[idx]
204+
end
205+
return res
206+
end
207+
191208
# Sparse matrix multiplication as described in [Gustavson, 1978]:
192209
# http://dl.acm.org/citation.cfm?id=355796
193210

src/solvers/cholmod.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,15 @@ Dense(A::StridedVecOrMatInclAdjAndTrans{T}) where
901901

902902
Dense(A::Sparse) = sparse_to_dense(A)
903903

904+
function Dense(ptr::Ptr{cholmod_dense})
905+
if ptr == C_NULL
906+
throw(ArgumentError("dense matrix construction failed for " *
907+
"unknown reasons. Please submit a bug report."))
908+
end
909+
s = unsafe_load(ptr)
910+
return Dense{jlxtype(s.xtype, s.dtype)}(ptr)
911+
end
912+
904913
function Base.convert(::Type{Dense{Tnew}}, A::Dense{T}) where {Tnew, T}
905914
GC.@preserve A begin
906915
Ap = unsafe_load(pointer(A))

src/solvers/spqr.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ function LinearAlgebra.qr(A::SparseMatrixCSC{Tv, Ti}; tol=_default_tol(A), order
204204
C_NULL, C_NULL, C_NULL, C_NULL,
205205
R, E, H, HPinv, HTau)
206206

207-
R_ = SparseMatrixCSC(Sparse(R[]))
208-
return QRSparse(SparseMatrixCSC(Sparse(H[])),
209-
vec(Array(CHOLMOD.Dense{Tv}(HTau[]))),
210-
SparseMatrixCSC(min(size(A)...),
207+
R_ = SparseMatrixCSC{Tv, Ti}(Sparse(R[]))
208+
return QRSparse(SparseMatrixCSC{Tv, Ti}(Sparse(H[])),
209+
vec(Array{Tv}(CHOLMOD.Dense(HTau[]))),
210+
SparseMatrixCSC{Tv, Ti}(min(size(A)...),
211211
size(R_, 2),
212212
getcolptr(R_),
213213
rowvals(R_),

0 commit comments

Comments
 (0)