generated from JuliaAI/MLJExampleInterface.jl
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtraits.jl
77 lines (62 loc) · 1.95 KB
/
traits.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Test
using LearnAPI
# A MINIMUM IMPLEMENTATION OF A LEARNER
# does nothing useful
struct SmallLearner end
LearnAPI.fit(learner::SmallLearner, data; verbosity=1) = learner
LearnAPI.learner(model::SmallLearner) = model
@trait(
SmallLearner,
constructor = SmallLearner,
functions = (
:(LearnAPI.fit),
:(LearnAPI.learner),
:(LearnAPI.clone),
:(LearnAPI.strip),
:(LearnAPI.obs),
:(LearnAPI.features),
),
)
######## END OF IMPLEMENTATION ##################
# ZERO ARGUMENT METHODS
@test :(LearnAPI.fit) in LearnAPI.functions()
@test Point() in LearnAPI.kinds_of_proxy()
@test "regression" in LearnAPI.tags()
# OVERLOADABLE TRAITS
small = SmallLearner()
@test LearnAPI.constructor(small) == SmallLearner
@test :(LearnAPI.learner) in LearnAPI.functions(small)
@test isempty(LearnAPI.kinds_of_proxy(small))
@test isempty(LearnAPI.tags(small))
@test !LearnAPI.is_pure_julia(small)
@test LearnAPI.pkg_name(small) == "unknown"
@test isempty(LearnAPI.nonlearners(small))
@test LearnAPI.pkg_license(small) == "unknown"
@test LearnAPI.doc_url(small) == "unknown"
@test LearnAPI.load_path(small) == "unknown"
@test LearnAPI.human_name(small) == "small learner"
@test isnothing(LearnAPI.iteration_parameter(small))
@test LearnAPI.data_interface(small) == LearnAPI.RandomAccess()
@test !(6 isa LearnAPI.fit_scitype(small))
@test 6 isa LearnAPI.target_observation_scitype(small)
@test !LearnAPI.is_static(small)
# DERIVED TRAITS
@test isempty(LearnAPI.learners(small))
@trait SmallLearner kinds_of_proxy=(Point(),)
@test LearnAPI.is_learner(small)
@test !LearnAPI.is_learner("junk")
@test !LearnAPI.target(small)
@test !LearnAPI.weights(small)
@test LearnAPI.preferred_kind_of_proxy(small) == Point()
module FruitSalad
import LearnAPI
struct RedApple{T}
x::T
end
LearnAPI.constructor(::RedApple) = RedApple
end
import .FruitSalad
@testset "name" begin
@test LearnAPI.name(FruitSalad.RedApple(1)) == "RedApple"
end
true