diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 3283f9de..f949504f 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -24,6 +24,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec ### Changed +- The default behavior of SVD-based nullspaces now includes some small tolerance ([#172](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/170)). - The Mooncake rules for truncated decompositions with `TruncatedAlgorithm` now use the pullbacks that make use of the full decomposition. ([#171](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/171)) ### Deprecated diff --git a/src/algorithms.jl b/src/algorithms.jl index b70e6911..07685f6a 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -243,14 +243,17 @@ function select_truncation(trunc) end @doc """ - MatrixAlgebraKit.select_null_truncation(trunc) + MatrixAlgebraKit.select_null_truncation(A, trunc) -Construct a [`TruncationStrategy`](@ref) from the given `NamedTuple` of keywords or input strategy, to implement a nullspace selection. +Construct a [`TruncationStrategy`](@ref) for `A` from the given `NamedTuple` of keywords or input strategy, to implement a nullspace selection. """ select_null_truncation +select_null_truncation(A, trunc) = select_null_truncation(typeof(A), trunc) +select_null_truncation(A::Type, trunc) = + isnothing(trunc) ? select_null_truncation((; rtol = defaulttol(eltype(A)))) : select_null_truncation(trunc) function select_null_truncation(trunc) if isnothing(trunc) - return NoTruncation() + return null_truncation_strategy() elseif trunc isa NamedTuple return null_truncation_strategy(; trunc...) elseif trunc isa TruncationStrategy diff --git a/src/interface/orthnull.jl b/src/interface/orthnull.jl index 669613f5..afd1c2f2 100644 --- a/src/interface/orthnull.jl +++ b/src/interface/orthnull.jl @@ -378,7 +378,7 @@ end end @inline function select_algorithm(::typeof(left_null!), A, ::Val{:svd}; trunc = nothing, kwargs...) alg_svd = select_algorithm(svd_full!, A, get(kwargs, :svd, nothing)) - alg = TruncatedAlgorithm(alg_svd, select_null_truncation(trunc)) + alg = TruncatedAlgorithm(alg_svd, select_null_truncation(A, trunc)) return LeftNullViaSVD(alg) end @@ -390,7 +390,7 @@ end end @inline function select_algorithm(::typeof(right_null!), A, ::Val{:svd}; trunc = nothing, kwargs...) alg_svd = select_algorithm(svd_full!, A; kwargs...) - alg = TruncatedAlgorithm(alg_svd, select_null_truncation(trunc)) + alg = TruncatedAlgorithm(alg_svd, select_null_truncation(A, trunc)) return RightNullViaSVD(alg) end