Skip to content

Commit

Permalink
Fix Feature hashes for wrapped functions
Browse files Browse the repository at this point in the history
  • Loading branch information
giopaglia committed Aug 8, 2023
1 parent 314b8d4 commit 9cb0eef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/logisets/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function Base.show(io::IO, f::AbstractFeature)
# print(io, "$(syntaxstring(f))")
end

# TODO check whether this is this necessary or wanted, and remove Base.hash(a::VarFeature) maybe?
Base.isequal(a::AbstractFeature, b::AbstractFeature) = syntaxstring(a) == syntaxstring(b)
Base.hash(a::AbstractFeature) = Base.hash(syntaxstring(a))

Expand Down
8 changes: 5 additions & 3 deletions src/logisets/scalar/var-features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ See also [`AbstractWorld`](@ref).
featvaltype(::Type{<:VarFeature{U}}) where {U} = U
featvaltype(::VarFeature{U}) where {U} = U

# # TODO Necessary?
# Base.isequal(a::FT, b::FT) where {FT<:VarFeature} = Base.isequal(map(x->getfield(a, x), fieldnames(typeof(a))), map(x->getfield(b, x), fieldnames(typeof(b))))
# Base.hash(a::VarFeature) = Base.hash(map(x->getfield(a, x), fieldnames(typeof(a)))) + Base.hash("")
# Note this is necessary when wrapping lambda functions or closures:
# f = [UnivariateFeature{Float64}(1, x->[1.,2.,3.][i]) for i in 1:3] |> unique
# map(x->SoleModels.computefeature(x, rand(1,2)), f)
Base.isequal(a::FT, b::FT) where {FT<:VarFeature} = Base.isequal(map(x->getfield(a, x), fieldnames(typeof(a))), map(x->getfield(b, x), fieldnames(typeof(b))))
Base.hash(a::VarFeature) = Base.hash(map(x->getfield(a, x), fieldnames(typeof(a)))) + Base.hash(typeof(a))

"""
computefeature(f::VarFeature{U}, featchannel; kwargs...)::U where {U}
Expand Down

0 comments on commit 9cb0eef

Please sign in to comment.