Ah okay, my package is a quite a bit more lightweight, and geared towards ill-conditioned problems, as an example:
using FixedPointAcceleration, FixedPoint
func(x) = [1+tanh((1-x[1])*1000)]
Inputs = [10.0]
a = FixedPointAcceleration.fixed_point(func, Inputs; Algorithm = :Anderson,Dampening=0.4)
# a = did not converge, I also tried :Aitken, :Newton and :Simple algorithm, nothing seems to work out...
# while my package works ootb
b = FixedPoint.afps(func, Inputs, ep=0.0005,vel=0.96)
# b = (x = [1.0000000000000004], error = 4.445332990599127e-13, iters = 347)
performance tests:
using BenchmarkTools
@time using FixedPointAcceleration
# 0.530836 seconds (1.87 M allocations: 117.636 MiB, 1.58% gc time, 9.45% compilation time)
func(x) = [0.5*sqrt(abs(x[1] + x[2])), 1.5*x[1] + 0.5*x[2]]
Inputs = [0.3,900.0]
@benchmark fixed_point($func, Inputs; Algorithm = :Anderson)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 53.458 μs … 4.539 ms ┊ GC (min … max): 0.00% … 97.13%
Time (median): 55.750 μs ┊ GC (median): 0.00%
Time (mean ± σ): 63.202 μs ± 159.641 μs ┊ GC (mean ± σ): 9.93% ± 3.88%
=#
@benchmark fixed_point($func, Inputs; Algorithm = :Anderson, Dampening = 0.4)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 317.292 μs … 5.559 ms ┊ GC (min … max): 0.00% … 91.14%
Time (median): 326.709 μs ┊ GC (median): 0.00%
Time (mean ± σ): 371.684 μs ± 389.399 μs ┊ GC (mean ± σ): 10.79% ± 9.38%
=#
@time using FixedPoint
# 0.000480 seconds (960 allocations: 92.016 KiB)
@benchmark afps($func, Inputs, ep=1.0,vel=0.5)
#=
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 10.833 μs … 2.616 ms ┊ GC (min … max): 0.00% … 98.62%
Time (median): 11.417 μs ┊ GC (median): 0.00%
Time (mean ± σ): 13.309 μs ± 62.082 μs ┊ GC (mean ± σ): 11.31% ± 2.41%
=#
my package is also more type generic, for example it gets even faster by leveraging StaticVectors
using BenchmarkTools, StaticArrays
@time using FixedPointAcceleration
# 0.530836 seconds (1.87 M allocations: 117.636 MiB, 1.58% gc time, 9.45% compilation time)
func(x) = @SVector [0.5*sqrt(abs(x[1] + x[2])), 1.5*x[1] + 0.5*x[2]]
Inputs = @SVector [0.3,900.0]
fixed_point(func, Inputs; Algorithm = :Anderson)
#=
ERROR: MethodError: no method matching fixed_point(::typeof(func), ::SVector{2, Float64}; Algorithm=:Anderson)
Closest candidates are:
=#
@benchmark afps($func, Inputs, ep=1.0,vel=0.5)
#=
BenchmarkTools.Trial: 10000 samples with 81 evaluations.
Range (min … max): 823.556 ns … 1.468 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 826.136 ns ┊ GC (median): 0.00%
Time (mean ± σ): 839.262 ns ± 31.526 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
=#
my package also allows tensor (or matrix or scalar) inputs and functions.