diff --git a/Project.toml b/Project.toml index 254377c9..53bac9a5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MatrixAlgebraKit" uuid = "6c742aac-3347-4629-af66-fc926824e5e4" authors = ["Jutho and contributors"] -version = "0.1.2" +version = "0.2.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/implementations/truncation.jl b/src/implementations/truncation.jl index ac091787..95a5c002 100644 --- a/src/implementations/truncation.jl +++ b/src/implementations/truncation.jl @@ -69,11 +69,11 @@ TruncationKeepBelow(atol::Real, rtol::Real) = TruncationKeepBelow(promote(atol, # TODO: better names for these functions of the above types """ - truncrank(howmany::Int, by=abs, rev=true) + truncrank(howmany::Int; by=abs, rev=true) Truncation strategy to keep the first `howmany` values when sorted according to `by` or the last `howmany` if `rev` is true. """ -truncrank(howmany::Int, by=abs, rev=true) = TruncationKeepSorted(howmany, by, rev) +truncrank(howmany::Int; by=abs, rev=true) = TruncationKeepSorted(howmany, by, rev) """ trunctol(atol::Real) diff --git a/test/truncate.jl b/test/truncate.jl index 5004a39d..2e67b894 100644 --- a/test/truncate.jl +++ b/test/truncate.jl @@ -2,7 +2,7 @@ using MatrixAlgebraKit using Test using TestExtras using MatrixAlgebraKit: NoTruncation, TruncationIntersection, TruncationKeepAbove, - TruncationStrategy + TruncationStrategy, findtruncated @testset "truncate" begin trunc = @constinferred TruncationStrategy() @@ -26,4 +26,9 @@ using MatrixAlgebraKit: NoTruncation, TruncationIntersection, TruncationKeepAbov @test trunc == truncrank(10) & TruncationKeepAbove(1e-2, 1e-3) @test trunc.components[1] == truncrank(10) @test trunc.components[2] == TruncationKeepAbove(1e-2, 1e-3) + + values = [1, 0.9, 0.5, 0.3, 0.01] + @test @constinferred(findtruncated(values, truncrank(2))) == [1, 2] + @test @constinferred(findtruncated(values, truncrank(2; rev=false))) == [5, 4] + @test @constinferred(findtruncated(values, truncrank(2; by=-))) == [5, 4] end