Skip to content

Commit 02af766

Browse files
committed
tweak
1 parent 2312c1d commit 02af766

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/traits.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ named_properties = NamedTuple{properties}(getproperty.(Ref(algorithm), propertie
5454
@assert algorithm == LearnAPI.constructor(algorithm)(; named_properties...)
5555
```
5656
57+
which can be tested with `@assert LearnAPI.clone(algorithm) == algorithm`.
58+
5759
The keyword constructor provided by `LearnAPI.constructor` must provide default values for
5860
all properties, with the exception of those that can take other LearnAPI.jl algorithms as
59-
values.
61+
values. These can be provided with the default `nothing`, with the constructor throwing an
62+
error if the default value persists.
6063
6164
"""
6265
function constructor end

test/integration/iterative_algorithms.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Instantiate a bagged ensemble of `n` regressors, with base regressor `atom`, etc
3636
Ensemble(atom; rng=Random.default_rng(), n=10) =
3737
Ensemble(atom, rng, n) # `LearnAPI.constructor` defined later
3838

39+
# pure keyword argument constructor:
40+
function Ensemble(; atom=nothing, kwargs...)
41+
isnothing(atom) && error("You must specify `atom=...` ")
42+
Ensemble(atom; kwargs...)
43+
end
44+
3945
struct EnsembleFitted
4046
algorithm::Ensemble
4147
atom::Ridge

0 commit comments

Comments
 (0)