@@ -292,7 +292,26 @@ function select_null_truncation(trunc)
292292 elseif trunc isa TruncationStrategy
293293 return trunc
294294 else
295- return throw (ArgumentError (" Unknown truncation strategy: $trunc " ))
295+ throw (ArgumentError (" Unknown truncation strategy: $trunc " ))
296+ end
297+ end
298+
299+ @doc """
300+ MatrixAlgebraKit.select_sketching(A, sketch)
301+
302+ Construct a [`SketchingStrategy`](@ref) for `A` from the given `NamedTuple` of keywords or input strategy `sketch`.
303+ """ select_sketching
304+
305+ @inline select_sketching (A, sketch) = select_sketching (typeof (A), sketch)
306+ @inline function select_sketching (:: Type{A} , sketch) where {A}
307+ if isnothing (sketch)
308+ return nothing
309+ elseif sketch isa SketchingStrategy
310+ return sketch
311+ elseif sketch isa NamedTuple
312+ return select_algorithm (left_sketch!, A; sketch... )
313+ else
314+ throw (ArgumentError (" Unknown sketching strategy: $sketch " ))
296315 end
297316end
298317
@@ -331,7 +350,7 @@ function truncate end
331350Generic wrapper type for algorithms that consist of first using `alg`, followed by a
332351truncation through `trunc`.
333352"""
334- struct TruncatedAlgorithm{A, T} <: AbstractAlgorithm
353+ struct TruncatedAlgorithm{A <: AbstractAlgorithm , T <: TruncationStrategy } <: AbstractAlgorithm
335354 alg:: A
336355 trunc:: T
337356end
@@ -356,10 +375,9 @@ TruncatedAlgorithm(alg::SketchedAlgorithm) = TruncatedAlgorithm(alg.alg, alg.tru
356375does_truncate (:: TruncatedAlgorithm ) = true
357376does_truncate (:: SketchedAlgorithm ) = true
358377
359- truncated_algorithm (alg:: AbstractAlgorithm , trunc:: TruncationStrategy ) =
360- TruncatedAlgorithm (alg, trunc)
361- truncated_algorithm (alg:: AbstractAlgorithm , sketch:: SketchingStrategy ) =
362- SketchedAlgorithm (sketch, alg, DefaultDriver ())
378+ truncated_algorithm (alg:: AbstractAlgorithm , trunc:: TruncationStrategy , sketch = nothing ) =
379+ isnothing (sketch) ? TruncatedAlgorithm (alg, trunc) : SketchedAlgorithm (; alg, sketch, trunc)
380+
363381
364382# Utility macros
365383# --------------
0 commit comments