Skip to content

Commit 2e4e25d

Browse files
authored
Default tolerances for SVD-based nullspaces (#172)
* change default null truncation strategy * update changelog * Use relative instead of absolute tolerance
1 parent 8b76f2a commit 2e4e25d

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

docs/src/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ When releasing a new version, move the "Unreleased" changes to a new version sec
2424

2525
### Changed
2626

27+
- The default behavior of SVD-based nullspaces now includes some small tolerance ([#172](https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/pull/170)).
2728
- 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))
2829

2930
### Deprecated

src/algorithms.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,17 @@ function select_truncation(trunc)
243243
end
244244

245245
@doc """
246-
MatrixAlgebraKit.select_null_truncation(trunc)
246+
MatrixAlgebraKit.select_null_truncation(A, trunc)
247247
248-
Construct a [`TruncationStrategy`](@ref) from the given `NamedTuple` of keywords or input strategy, to implement a nullspace selection.
248+
Construct a [`TruncationStrategy`](@ref) for `A` from the given `NamedTuple` of keywords or input strategy, to implement a nullspace selection.
249249
""" select_null_truncation
250250

251+
select_null_truncation(A, trunc) = select_null_truncation(typeof(A), trunc)
252+
select_null_truncation(A::Type, trunc) =
253+
isnothing(trunc) ? select_null_truncation((; rtol = defaulttol(eltype(A)))) : select_null_truncation(trunc)
251254
function select_null_truncation(trunc)
252255
if isnothing(trunc)
253-
return NoTruncation()
256+
return null_truncation_strategy()
254257
elseif trunc isa NamedTuple
255258
return null_truncation_strategy(; trunc...)
256259
elseif trunc isa TruncationStrategy

src/interface/orthnull.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ end
378378
end
379379
@inline function select_algorithm(::typeof(left_null!), A, ::Val{:svd}; trunc = nothing, kwargs...)
380380
alg_svd = select_algorithm(svd_full!, A, get(kwargs, :svd, nothing))
381-
alg = TruncatedAlgorithm(alg_svd, select_null_truncation(trunc))
381+
alg = TruncatedAlgorithm(alg_svd, select_null_truncation(A, trunc))
382382
return LeftNullViaSVD(alg)
383383
end
384384

@@ -390,7 +390,7 @@ end
390390
end
391391
@inline function select_algorithm(::typeof(right_null!), A, ::Val{:svd}; trunc = nothing, kwargs...)
392392
alg_svd = select_algorithm(svd_full!, A; kwargs...)
393-
alg = TruncatedAlgorithm(alg_svd, select_null_truncation(trunc))
393+
alg = TruncatedAlgorithm(alg_svd, select_null_truncation(A, trunc))
394394
return RightNullViaSVD(alg)
395395
end
396396

0 commit comments

Comments
 (0)