-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add similar
and setindex!
#6
Comments
@darsnack what are your thoughts on how Edit: I think I follow now actually from the thread |
Yeah it should check that the one hot property is preserved or error. So if the first index isn't |
I've been having a play around with this, and I have something that works as you'd expect for cases like hcat/vcat, but I'm not sure whether I have the right approach. I have something like the following: function Base.similar(::OneHotArray{T, L}, ::Type{Bool}, dims::Dims) where {T, L}
if first(dims) == L
indices = ones(T, Base.tail(dims))
return OneHotArray(indices, first(dims))
else
return BitArray(undef, dims)
end
end
function Base.setindex!(x::OneHotArray{<:Any, <:Any, N}, v::Bool, i::Integer, I::Vararg{Integer, N}) where N
@boundscheck checkbounds(x, i, I...)
if v
x.indices[I...] = i
elseif x.indices[I...] == i
x.indices[I...] = 0
end
end where I take the viewpoint that if The problem stems from the fact that not all I think that these are the options on how to proceed, but maybe I'm missing an obviously better way; I'd be keen to hear your thoughts:
What do you think? |
I was thinking that When the first index is not a I think your view on |
See the original Flux issue and part of the solution here.
The text was updated successfully, but these errors were encountered: