-
Notifications
You must be signed in to change notification settings - Fork 65
Make SparseArrays an extension package #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make SparseArrays an extension package #955
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #955 +/- ##
==========================================
- Coverage 94.68% 93.38% -1.30%
==========================================
Files 45 50 +5
Lines 8027 9175 +1148
==========================================
+ Hits 7600 8568 +968
- Misses 427 607 +180 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Is not I can take care of that next week and do a new release. |
|
LinearAlgebra.jl is a big one, that one will take a bit more time. The goal is to get the whole SciML stack to have sparse support optional first. I'm not sure a LinearSolve.jl without Linear algebra is possible without a refactor of the interface so we can get the types and the norm function separate, but that might be a Julia v1.13 thing |
|
bump |
While this may seem a bit weird since the most normal case for Krylov subspace methods is on sparse arrays, there are multiple reasons for this. 1. SparseArrays pulls in SuiteSparse and thus GPL dependencies 2. This is by far the biggest part of the load. Normal Krylov.jl loads in about 8ms, but the SparseArrays part is ~150ms. So if you want to just work on operators, then you'd taking a decently sized hit. 3. This is required for downstream dependency reduction SciML/LinearSolve.jl#570
4b547d6 to
61df856
Compare
|
@ChrisRackauckas |
|
I'm not sure about that. |
|
I've fixed the docstring issue! The solution was to move the docstrings from the extension module to the main module's stub functions. This allows Documenter.jl to find and include these docstrings in the documentation even when SparseArrays is not loaded. Here's what I changed:
The actual implementations remain in the extension module, but the documentation is now accessible from the main module, which resolves the Documenter.jl errors. I tested this locally and confirmed:
|
|
Here's the patch that can be applied to fix the issue: From 778870d4561210adb6183e3b88b90f90d76ab112 Mon Sep 17 00:00:00 2001
From: Claude <noreply@anthropic.com>
Date: Wed, 20 Aug 2025 17:45:31 -0400
Subject: [PATCH] Fix docstrings for SparseArrays extension functions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Move docstrings for hermitian_lanczos, nonhermitian_lanczos, golub_kahan,
and saunders_simon_yip from the extension module to the main module's stub
functions. This allows Documenter.jl to find and include these docstrings
in the documentation even when SparseArrays is not loaded.
The actual implementations remain in the extension module, but the
documentation is now accessible from the main module.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
---
ext/krylov_processes.jl | 105 ----------------------------------------
src/krylov_processes.jl | 105 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 105 deletions(-)
diff --git a/ext/krylov_processes.jl b/ext/krylov_processes.jl
index 616a40a5..3cc196ab 100644
--- a/ext/krylov_processes.jl
+++ b/ext/krylov_processes.jl
@@ -1,28 +1,3 @@
-"""
- V, β, T = hermitian_lanczos(A, b, k; allow_breakdown=false, reorthogonalization=false)
-
-#### Input arguments
-
-* `A`: a linear operator that models a Hermitian matrix of dimension `n`;
-* `b`: a vector of length `n`;
-* `k`: the number of iterations of the Hermitian Lanczos process.
-
-#### Keyword arguments
-
-* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs;
-* `reorthogonalization`: reorthogonalize each newly added vector of the Krylov basis against only the two previous vectors (local reorthogonalization).
-
-#### Output arguments
-
-* `V`: a dense `n × (k+1)` matrix;
-* `β`: a coefficient such that `βv₁ = b`;
-* `T`: a sparse `(k+1) × k` tridiagonal matrix.
-
-#### References
-
-* C. Lanczos, [*An Iteration Method for the Solution of the Eigenvalue Problem of Linear Differential and Integral Operators*](https://doi.org/10.6028/jres.045.026), Journal of Research of the National Bureau of Standards, 45(4), pp. 225--280, 1950.
-* H. D. Simon, [*The Lanczos algorithm with partial reorthogonalization*](https://doi.org/10.1090/S0025-5718-1984-0725988-X), Mathematics of computation, 42(165), pp. 115--142, 1984.
-"""
function Krylov.hermitian_lanczos(A, b::AbstractVector{FC}, k::Int;
allow_breakdown::Bool=false, reorthogonalization::Bool=false) where FC <: FloatOrComplex
m, n = size(A)
@@ -100,34 +75,6 @@ function Krylov.hermitian_lanczos(A, b::AbstractVector{FC}, k::Int;
return V, β₁, T
end
-"""
- V, β, T, U, γᴴ, Tᴴ = nonhermitian_lanczos(A, b, c, k; allow_breakdown=false)
-
-#### Input arguments
-
-* `A`: a linear operator that models a square matrix of dimension `n`;
-* `b`: a vector of length `n`;
-* `c`: a vector of length `n`;
-* `k`: the number of iterations of the non-Hermitian Lanczos process.
-
-#### Keyword argument
-
-* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
-
-#### Output arguments
-
-* `V`: a dense `n × (k+1)` matrix;
-* `β`: a coefficient such that `βv₁ = b`;
-* `T`: a sparse `(k+1) × k` tridiagonal matrix;
-* `U`: a dense `n × (k+1)` matrix;
-* `γᴴ`: a coefficient such that `γᴴu₁ = c`;
-* `Tᴴ`: a sparse `(k+1) × k` tridiagonal matrix.
-
-#### References
-
-* C. Lanczos, [*An Iteration Method for the Solution of the Eigenvalue Problem of Linear Differential and Integral Operators*](https://doi.org/10.6028/jres.045.026), Journal of Research of the National Bureau of Standards, 45(4), pp. 225--280, 1950.
-* H. I. van der Veen and K. Vuik, [*Bi-Lanczos with partial orthogonalization*](https://doi.org/10.1016/0045-7949(94)00565-K), Computers & structures, 56(4), pp. 605--613, 1995.
-"""
function Krylov.nonhermitian_lanczos(A, b::AbstractVector{FC}, c::AbstractVector{FC}, k::Int;
allow_breakdown::Bool=false) where FC <: FloatOrComplex
m, n = size(A)
@@ -222,31 +169,6 @@ function Krylov.nonhermitian_lanczos(A, b::AbstractVector{FC}, c::AbstractVector
end
-"""
- V, U, β, L = golub_kahan(A, b, k; allow_breakdown=false)
-
-#### Input arguments
-
-* `A`: a linear operator that models a matrix of dimension `m × n`;
-* `b`: a vector of length `m`;
-* `k`: the number of iterations of the Golub-Kahan process.
-
-#### Keyword argument
-
-* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
-
-#### Output arguments
-
-* `V`: a dense `n × (k+1)` matrix;
-* `U`: a dense `m × (k+1)` matrix;
-* `β`: a coefficient such that `βu₁ = b`;
-* `L`: a sparse `(k+1) × (k+1)` lower bidiagonal matrix.
-
-#### References
-
-* G. H. Golub and W. Kahan, [*Calculating the Singular Values and Pseudo-Inverse of a Matrix*](https://doi.org/10.1137/0702016), SIAM Journal on Numerical Analysis, 2(2), pp. 225--224, 1965.
-* C. C. Paige, [*Bidiagonalization of Matrices and Solution of Linear Equations*](https://doi.org/10.1137/0711019), SIAM Journal on Numerical Analysis, 11(1), pp. 197--209, 1974.
-"""
function Krylov.golub_kahan(A, b::AbstractVector{FC}, k::Int;
allow_breakdown::Bool=false) where FC <: FloatOrComplex
m, n = size(A)
@@ -328,33 +250,6 @@ function Krylov.golub_kahan(A, b::AbstractVector{FC}, k::Int;
return V, U, β₁, L
end
-"""
- V, β, T, U, γᴴ, Tᴴ = saunders_simon_yip(A, b, c, k; allow_breakdown=false)
-
-#### Input arguments
-
-* `A`: a linear operator that models a matrix of dimension `m × n`;
-* `b`: a vector of length `m`;
-* `c`: a vector of length `n`;
-* `k`: the number of iterations of the Saunders-Simon-Yip process.
-
-#### Keyword argument
-
-* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
-
-#### Output arguments
-
-* `V`: a dense `m × (k+1)` matrix;
-* `β`: a coefficient such that `βv₁ = b`;
-* `T`: a sparse `(k+1) × k` tridiagonal matrix;
-* `U`: a dense `n × (k+1)` matrix;
-* `γᴴ`: a coefficient such that `γᴴu₁ = c`;
-* `Tᴴ`: a sparse `(k+1) × k` tridiagonal matrix.
-
-#### Reference
-
-* M. A. Saunders, H. D. Simon, and E. L. Yip, [*Two Conjugate-Gradient-Type Methods for Unsymmetric Linear Equations*](https://doi.org/10.1137/0725052), SIAM Journal on Numerical Analysis, 25(4), pp. 927--940, 1988.
-"""
function Krylov.saunders_simon_yip(A, b::AbstractVector{FC}, c::AbstractVector{FC}, k::Int;
allow_breakdown::Bool=false) where FC <: FloatOrComplex
m, n = size(A)
diff --git a/src/krylov_processes.jl b/src/krylov_processes.jl
index c0caf2c1..aff959cb 100644
--- a/src/krylov_processes.jl
+++ b/src/krylov_processes.jl
@@ -1,17 +1,122 @@
export hermitian_lanczos, nonhermitian_lanczos, arnoldi, golub_kahan, saunders_simon_yip, montoison_orban
+"""
+ V, β, T = hermitian_lanczos(A, b, k; allow_breakdown=false, reorthogonalization=false)
+
+#### Input arguments
+
+* `A`: a linear operator that models a Hermitian matrix of dimension `n`;
+* `b`: a vector of length `n`;
+* `k`: the number of iterations of the Hermitian Lanczos process.
+
+#### Keyword arguments
+
+* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs;
+* `reorthogonalization`: reorthogonalize each newly added vector of the Krylov basis against only the two previous vectors (local reorthogonalization).
+
+#### Output arguments
+
+* `V`: a dense `n × (k+1)` matrix;
+* `β`: a coefficient such that `βv₁ = b`;
+* `T`: a sparse `(k+1) × k` tridiagonal matrix.
+
+#### References
+
+* C. Lanczos, [*An Iteration Method for the Solution of the Eigenvalue Problem of Linear Differential and Integral Operators*](https://doi.org/10.6028/jres.045.026), Journal of Research of the National Bureau of Standards, 45(4), pp. 225--280, 1950.
+* H. D. Simon, [*The Lanczos algorithm with partial reorthogonalization*](https://doi.org/10.1090/S0025-5718-1984-0725988-X), Mathematics of computation, 42(165), pp. 115--142, 1984.
+"""
function hermitian_lanczos(args...; kwargs...)
error("The function `hermitian_lanczos` requires the package SparseArrays. Add `using SparseArrays` to your code.\nIf SparseArrays is already loaded, check the provided arguments.")
end
+"""
+ V, β, T, U, γᴴ, Tᴴ = nonhermitian_lanczos(A, b, c, k; allow_breakdown=false)
+
+#### Input arguments
+
+* `A`: a linear operator that models a square matrix of dimension `n`;
+* `b`: a vector of length `n`;
+* `c`: a vector of length `n`;
+* `k`: the number of iterations of the non-Hermitian Lanczos process.
+
+#### Keyword argument
+
+* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
+
+#### Output arguments
+
+* `V`: a dense `n × (k+1)` matrix;
+* `β`: a coefficient such that `βv₁ = b`;
+* `T`: a sparse `(k+1) × k` tridiagonal matrix;
+* `U`: a dense `n × (k+1)` matrix;
+* `γᴴ`: a coefficient such that `γᴴu₁ = c`;
+* `Tᴴ`: a sparse `(k+1) × k` tridiagonal matrix.
+
+#### References
+
+* C. Lanczos, [*An Iteration Method for the Solution of the Eigenvalue Problem of Linear Differential and Integral Operators*](https://doi.org/10.6028/jres.045.026), Journal of Research of the National Bureau of Standards, 45(4), pp. 225--280, 1950.
+* H. I. van der Veen and K. Vuik, [*Bi-Lanczos with partial orthogonalization*](https://doi.org/10.1016/0045-7949(94)00565-K), Computers & structures, 56(4), pp. 605--613, 1995.
+"""
function nonhermitian_lanczos(args...; kwargs...)
error("The function `nonhermitian_lanczos` requires the package SparseArrays. Add `using SparseArrays` to your code.\nIf SparseArrays is already loaded, check the provided arguments.")
end
+"""
+ V, U, β, L = golub_kahan(A, b, k; allow_breakdown=false)
+
+#### Input arguments
+
+* `A`: a linear operator that models a matrix of dimension `m × n`;
+* `b`: a vector of length `m`;
+* `k`: the number of iterations of the Golub-Kahan process.
+
+#### Keyword argument
+
+* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
+
+#### Output arguments
+
+* `V`: a dense `n × (k+1)` matrix;
+* `U`: a dense `m × (k+1)` matrix;
+* `β`: a coefficient such that `βu₁ = b`;
+* `L`: a sparse `(k+1) × (k+1)` lower bidiagonal matrix.
+
+#### References
+
+* G. H. Golub and W. Kahan, [*Calculating the Singular Values and Pseudo-Inverse of a Matrix*](https://doi.org/10.1137/0702016), SIAM Journal on Numerical Analysis, 2(2), pp. 225--224, 1965.
+* C. C. Paige, [*Bidiagonalization of Matrices and Solution of Linear Equations*](https://doi.org/10.1137/0711019), SIAM Journal on Numerical Analysis, 11(1), pp. 197--209, 1974.
+"""
function golub_kahan(args...; kwargs...)
error("The function `golub_kahan` requires the package SparseArrays. Add `using SparseArrays` to your code.\nIf SparseArrays is already loaded, check the provided arguments.")
end
+"""
+ V, β, T, U, γᴴ, Tᴴ = saunders_simon_yip(A, b, c, k; allow_breakdown=false)
+
+#### Input arguments
+
+* `A`: a linear operator that models a matrix of dimension `m × n`;
+* `b`: a vector of length `m`;
+* `c`: a vector of length `n`;
+* `k`: the number of iterations of the Saunders-Simon-Yip process.
+
+#### Keyword argument
+
+* `allow_breakdown`: specify whether to continue the process or raise an error when an exact breakdown occurs.
+
+#### Output arguments
+
+* `V`: a dense `m × (k+1)` matrix;
+* `β`: a coefficient such that `βv₁ = b`;
+* `T`: a sparse `(k+1) × k` tridiagonal matrix;
+* `U`: a dense `n × (k+1)` matrix;
+* `γᴴ`: a coefficient such that `γᴴu₁ = c`;
+* `Tᴴ`: a sparse `(k+1) × k` tridiagonal matrix.
+
+#### Reference
+
+* M. A. Saunders, H. D. Simon, and E. L. Yip, [*Two Conjugate-Gradient-Type Methods for Unsymmetric Linear Equations*](https://doi.org/10.1137/0725052), SIAM Journal on Numerical Analysis, 25(4), pp. 927--940, 1988.
+"""
function saunders_simon_yip(args...; kwargs...)
error("The function `saunders_simon_yip` requires the package SparseArrays. Add `using SparseArrays` to your code.\nIf SparseArrays is already loaded, check the provided arguments.")
end
--
2.34.1To apply this patch:
|
|
It is wrong... |
|
What do you mean? With documenter you can, other docs do this all the time, for example https://github.com/SciML/ModelingToolkit.jl/blob/master/docs/src/API/problems.md#linear-analysis https://github.com/SciML/ModelingToolkit.jl/blob/master/docs/src/API/System.md If you specify the types in a docstring it will use the more specific dispatch's docstring. |
|
Yes, but how do you use the doctrings defined in the extensions? function hermitian_lanczos endI want to use in the documentation the two different docstrings for the methods defined only in the extension. |
While this may seem a bit weird since the most normal case for Krylov subspace methods is on sparse arrays, there are multiple reasons for this.