In IntervalArithmetic.jl we need a way to choose between different versions of a function (e.g. the power function) that have different performance / accuracy tradeoffs.
Is there a standard way to have an API for that? Maybe something along the lines of
abstract type APIChoice end
abstract type PowerAPIChoice <: APIChoice end
struct AccuratePowers <: PowerAPIChoice end
struct FastPowers <: PowerAPIChoice end
IntervalArithmetic.specify!(AccuratePowers())
IntervalArithmetic.specify!(FastPowers())
The implementation would be, for the moment, to redefine all the corresponding functions appropriately. Strictly speaking this should be some kind of contextual dispatch, however.
“contextual dispatch” sounds like “trait-based dispatch” where the trait selects over chosen-behavior appropriate algorithms rather than utilized-data-type appropriate algorithms.
Yes pretty much. It’s a phrase that I learnt from the Cassette.jl world.
Basically you want to do a whole calculation inside a scope where you choose “accurate powers” or “fast powers”. For e.g. testing you may want to be able to run in either of those two situations and record the respective results and compare them.