Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/common/view.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See also [`diagonal`](@ref).
""" diagview

diagview(D::Diagonal) = D.diag
diagview(D::AbstractVector) = throw(MethodError(diagview, (typeof(D),))) # here for JET
diagview(D::AbstractMatrix) = view(D, diagind(D))

@doc """
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/batched_svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function initialize_output(::typeof(batched_svd_vals!), A::AbstractArray{T, 3},
end

for f! in (:gesdd_batched!, :gesvd_batched!, :gesvdj_batched!, :gesvdx_batched!)
@eval $f!(driver::Driver, args...) = throw(ArgumentError("$driver does not provide $($(f!))"))
@eval $f!(driver::Driver, args...; kwargs...) = throw(ArgumentError("$driver does not provide $($(f!))"))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/eigh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end
# ==========================

for f! in (:heevr!, :heevd!, :heev!, :heevx!, :heevj!)
@eval $f!(driver::Driver, args...) = throw(ArgumentError("$driver does not provide $($(f!))"))
@eval $f!(driver::Driver, args...; kwargs...) = throw(ArgumentError("$driver does not provide $($(f!))"))
end

# LAPACK implementations
Expand Down
4 changes: 2 additions & 2 deletions src/implementations/polar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function left_polar_newton!(A::AbstractMatrix, W, P = similar(A, (0, 0)); tol =
Rc .= R
Rᴴinv = ldiv!(UpperTriangular(Rc)', one!(Rᴴinv))
else # m == n
R = A
Q, R = nothing, A
Rc = view(W, 1:n, 1:n)
Rc .= R
Rᴴinv = ldiv!(lu!(Rc)', one!(Rᴴinv))
Expand Down Expand Up @@ -174,7 +174,7 @@ function right_polar_newton!(A::AbstractMatrix, Wᴴ, P = similar(A, (0, 0)); to
copy!(Lc, L)
Lᴴinv = ldiv!(LowerTriangular(Lc)', one!(Lᴴinv))
else # m == n
L = A
L, Q = A, nothing
Lc = view(Wᴴ, 1:m, 1:m)
Lc .= L
Lᴴinv = ldiv!(lu!(Lc)', one!(Lᴴinv))
Expand Down
2 changes: 1 addition & 1 deletion src/implementations/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end
# ==========================

for f! in (:gesdd!, :gesvd!, :gesvdj!, :gesvdp!, :gesvdx!, :gesvdr!, :gesdvd!)
@eval $f!(driver::Driver, args...) = throw(ArgumentError("$driver does not provide $($(f!))"))
@eval $f!(driver::Driver, args...; kwargs...) = throw(ArgumentError("$driver does not provide $($(f!))"))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/pullbacks/eig.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function check_and_prepare_eig_cotangents(
D, V, ViG, ΔDmat, ΔV, ind = Colon();
degeneracy_atol::Real = default_pullback_rank_atol(S),
degeneracy_atol::Real = default_pullback_rank_atol(D),
gauge_atol::Real = default_pullback_gauge_atol(ΔDmat, ΔV)
)

Expand Down
2 changes: 1 addition & 1 deletion src/pullbacks/eigh.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function check_and_prepare_eigh_cotangents(
D, V, ΔDmat, ΔV, ind = Colon();
degeneracy_atol::Real = default_pullback_rank_atol(S),
degeneracy_atol::Real = default_pullback_rank_atol(D),
gauge_atol::Real = default_pullback_gauge_atol(ΔDmat, ΔV)
)

Expand Down
8 changes: 4 additions & 4 deletions src/pullbacks/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ function check_and_prepare_lq_cotangents(
# operating on a view-of-view, which doesn't work
# for GPU arrays
I = lowertriangularind(ΔL₂₂)
lower_inds = view(LinearIndices(ΔL), (p + 1):m, (p + 1):minmn)[I]
lower_inds = view(LinearIndices(axes(ΔL)), (p + 1):m, (p + 1):minmn)[I]
ΔL₂₂lower = view(ΔL, lower_inds)
Δgauge_L = maximum(abs, ΔL₂₂lower; init = abs(zero(eltype(ΔL))))
Δgauge_L = max(Δgauge_L, maximum(abs, view(ΔL₂₂, diagind(ΔL₂₂)); init = zero(Δgauge_L)))
Δgauge = max(Δgauge, Δgauge_L)
end
else
ΔL₁₁ = nothing
ΔL₂₁ = nothing
ΔL₁₁ = L
ΔL₂₁ = L
end
Δgauge ≤ gauge_atol ||
@warn "`lq` cotangents sensitive to gauge choice: (|Δgauge| = $Δgauge)"
Expand Down Expand Up @@ -182,7 +182,7 @@ function remove_lq_gauge_dependence!(ΔL, ΔQ, A, L, Q; rank_atol = MatrixAlgebr
# operating on a view-of-view, which doesn't work
# for GPU arrays
I = lowertriangularind(ΔL₂₂)
lower_inds = view(LinearIndices(ΔL), (r + 1):m, (r + 1):minmn)[I]
lower_inds = view(LinearIndices(axes(ΔL)), (r + 1):m, (r + 1):minmn)[I]
ΔL₂₂lower = view(ΔL, lower_inds)
zero!(ΔL₂₂lower)
end
Expand Down
8 changes: 4 additions & 4 deletions src/pullbacks/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function check_and_prepare_qr_cotangents(
# operating on a view-of-view, which doesn't work
# for GPU arrays
I = uppertriangularind(ΔR₂₂)
upper_inds = view(LinearIndices(ΔR), (p + 1):minmn, (p + 1):n)[I]
upper_inds = view(LinearIndices(axes(ΔR)), (p + 1):minmn, (p + 1):n)[I]
ΔR₂₂upper = view(ΔR, upper_inds)
Δgauge_R = maximum(abs, ΔR₂₂upper; init = abs(zero(eltype(ΔR))))
Δgauge_R = max(Δgauge_R, maximum(abs, view(ΔR₂₂, diagind(ΔR₂₂)); init = zero(Δgauge_R)))
Δgauge = max(Δgauge, Δgauge_R)
end
else
ΔR₁₁ = nothing
ΔR₁₂ = nothing
Comment thread
kshyatt marked this conversation as resolved.
Resolved
ΔR₁₁ = R
ΔR₁₂ = R
end
Δgauge ≤ gauge_atol ||
@warn "`qr` cotangents sensitive to gauge choice: (|Δgauge| = $Δgauge)"
Expand Down Expand Up @@ -184,7 +184,7 @@ function remove_qr_gauge_dependence!(ΔQ, ΔR, A, Q, R; rank_atol = MatrixAlgebr
# operating on a view-of-view, which doesn't work
# for GPU arrays
I = uppertriangularind(ΔR₂₂)
upper_inds = view(LinearIndices(ΔR), (r + 1):minmn, (r + 1):n)[I]
upper_inds = view(LinearIndices(axes(ΔR)), (r + 1):minmn, (r + 1):n)[I]
ΔR₂₂upper = view(ΔR, upper_inds)
zero!(ΔR₂₂upper)
end
Expand Down
2 changes: 2 additions & 0 deletions src/pushforwards/svd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function svd_pushforward!(
end
end
if eltype(U) <: Complex && !iszerotangent(ΔU) && !iszerotangent(ΔVᴴ) # fix gauge for `gaugefix!` compatibility
ΔU₁ = view(ΔU, :, 1:r)
ΔV₁ᴴ = view(ΔVᴴ, 1:r, :)
_, I = findmax(abs, U₁; dims = 1)
infinitesimal_phases = imag.(ΔU₁[I] .* inv_safe.(U₁[I]))
ΔU₁ .-= im .* U₁ .* infinitesimal_phases
Expand Down
6 changes: 4 additions & 2 deletions src/yalapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,7 @@ for (gesvd, gesdd, gesvdx, gejsv, gesvj, elty, relty) in
ldu = max(1, stride(U, 2))
ldv = max(1, stride(Vᴴ, 2))
lwork = BlasInt(-1)
rwork_ = isnothing(rwork) ? C_NULL : rwork
info = Ref{BlasInt}()
for i in 1:2 # first call returns lwork as work[1]
#! format: off
Expand All @@ -2040,7 +2041,7 @@ for (gesvd, gesdd, gesvdx, gejsv, gesvj, elty, relty) in
Ptr{BlasInt}, Clong, Clong),
jobu, jobvt, m, n, A, lda,
S, U, ldu, Vᴴ, ldv,
work, lwork, rwork,
work, lwork, rwork_,
info, 1, 1)
else
ccall((@blasfunc($gesvd), libblastrampoline), Cvoid,
Expand Down Expand Up @@ -2131,6 +2132,7 @@ for (gesvd, gesdd, gesvdx, gejsv, gesvj, elty, relty) in
ldv = max(1, stride(Vᴴ, 2))
lwork = BlasInt(-1)
iwork = Vector{BlasInt}(undef, 8 * minmn)
rwork_ = isnothing(rwork) ? C_NULL : rwork
info = Ref{BlasInt}()
for i in 1:2 # first call returns lwork as work[1]
#! format: off
Expand All @@ -2142,7 +2144,7 @@ for (gesvd, gesdd, gesvdx, gejsv, gesvj, elty, relty) in
Ptr{BlasInt}, Clong),
job, m, n, A, lda,
S, U, ldu, Vᴴ, ldv,
work, lwork, rwork, iwork,
work, lwork, rwork_, iwork,
info, 1)
else
ccall((@blasfunc($gesdd), libblastrampoline), Cvoid,
Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
EnzymeTestUtils = "12d8515a-0907-448a-8884-5fe00fdf1c5a"
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
GenericSchur = "c145ed77-6b09-5dd9-b285-bf645a82121e"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
Expand All @@ -27,6 +28,7 @@ MatrixAlgebraKit = {path = ".."}
Aqua = "0.6, 0.7, 0.8"
ChainRulesTestUtils = "1"
EnzymeTestUtils = "0.2.5"
JET = "0.9, 0.12"
ParallelTestRunner = "2.9"
Random = "1"
StableRNGs = "1"
Expand Down
4 changes: 0 additions & 4 deletions test/common/codequality.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@ using MatrixAlgebraKit

using Aqua
Aqua.test_all(MatrixAlgebraKit)

# using JET
# JET.test_package(MatrixAlgebraKit; target_defined_modules = true)
# disable for now (see https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/188#pullrequestreview-3953586976)
2 changes: 2 additions & 0 deletions test/common/jet.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
using MatrixAlgebraKit, JET
JET.test_package(MatrixAlgebraKit; target_modules = (MatrixAlgebraKit,))
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,25 @@ if filter_tests!(testsuite, args)
if is_buildkite
delete!(testsuite, "common/algorithms")
delete!(testsuite, "common/codequality")
delete!(testsuite, "common/jet")
delete!(testsuite, "common/truncate")
delete!(testsuite, "decompositions/gen_eig")
filter!(p -> !startswith(first(p), "chainrules/"), testsuite)
end
end

# JET tests: JET ≥ 0.12 (Julia 1.12+) signals through `JET_AVAILABLE` whether it is functional,
# and loads empty stubs when it is not. Older JET versions, still needed on Julia < 1.12, do not
# define it, hence the `isdefined` check instead of `using JET: JET_AVAILABLE`.
Comment thread
kshyatt marked this conversation as resolved.
Resolved
using JET: JET
const jet_new_generation = isdefined(JET, :JET_AVAILABLE)
const jet_available = !jet_new_generation || JET.JET_AVAILABLE
# whole-package analysis is pinned to the JET 0.12 generation, so its reports need not be curated for several JET/Julia combinations
if !(jet_new_generation && jet_available)
@info "Full JET functionality is unavailable on Julia $VERSION; skipping JET analysis"
delete!(testsuite, "common/jet")
end

# Enzyme test workers peak at 5-7 GB (qr, lq, orthnull on Julia 1.10), so the default
# assumption of 2 GiB per worker oversubscribes memory on CI runners and makes them swap
memory_per_worker = any(startswith("enzyme/") ∘ first, testsuite) ? 6 * 2^30 : 2 * 2^30
Expand Down
Loading