Skip to content

Commit 44d5096

Browse files
committed
traits only get applied and defined on instances
minor tweaks fix test
1 parent b460b71 commit 44d5096

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

docs/src/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ target appears in training (is supervised) or whether the model generalizes to n
112112
observations (learns) or not.
113113

114114
The target and the kind of predicted proxy are crucial features of ML/statistics
115-
performance measures and LearnAPI.jl provides a detailed list of proxy dispatch types (see
116-
[Target proxies](@ref)), as well as algorithm traits to articulate target type /scitype.
115+
performance measures (not provided by this package) and LearnAPI.jl provides a detailed
116+
list of proxy dispatch types (see [Target proxies](@ref)), as well as algorithm traits to
117+
articulate target type /scitype.
117118

118119

119120
## Optional data interface

src/tools.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ macro trait(algorithm_ex, exs...)
2121
end
2222

2323
"""
24+
typename(x)
2425
25-
typename(T::Type)
26+
Return a symbolic representation of the name of `type(x)`, stripped of any type-parameters
27+
and module qualifications. For example, if
2628
27-
Return a symbol corresponding to the name of the type `T`, stripped of
28-
any type-parameters and module qualifications. For example:
29+
typeof(x) = MLJBase.Machine{MLJAlgorithms.ConstantRegressor,true}
2930
30-
_typename(MLJBase.Machine{MLJAlgorithms.ConstantRegressor,true})
31-
32-
returns `:Machine`. Where this does not make sense (eg, instances of
33-
`Union`) `Symbol(string(M))` is returned.
31+
Then `typename(x)` returns `:Machine`.
3432
3533
"""
36-
function typename(M)
34+
function typename(x)
35+
M = typeof(x)
3736
if isdefined(M, :name)
3837
return M.name.name
3938
elseif isdefined(M, :body)

test/tools.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ import .Fruit
1919
## HELPERS
2020

2121
@testset "typename" begin
22-
@test LearnAPI.typename(Fruit.RedApple) == :RedApple
23-
@test LearnAPI.typename(Fruit.RedApple{Int}) == :RedApple
24-
@test LearnAPI.typename(Nothing) == :Nothing
25-
@test LearnAPI.typename(UnionAll) == :UnionAll
26-
@test LearnAPI.typename(Union{Char,Int}) ==
27-
Symbol("Union{Char, Int64}")
28-
T = SparseArrays.sparse([1,2], [1,3], [0.5, 0.6]) |> typeof
29-
@test LearnAPI.typename(T) == :SparseMatrixCSC
22+
@test LearnAPI.typename(Fruit.RedApple(1)) == :RedApple
23+
@test LearnAPI.typename(nothing) == :Nothing
24+
m = SparseArrays.sparse([1,2], [1,3], [0.5, 0.6])
25+
@test LearnAPI.typename(m) == :SparseMatrixCSC
3026
end
3127

3228
@testset "snakecase" begin

0 commit comments

Comments
 (0)