Skip to content

Commit e19feec

Browse files
committed
simple setindex
1 parent 0b49d1b commit e19feec

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/array.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ end
8080
Base.getindex(x::OneHotArray, ::Colon) = BitVector(reshape(x, :))
8181
Base.getindex(x::OneHotArray{<:Any, N}, ::Colon, ::Vararg{Colon, N}) where N = x
8282

83+
@inline function Base.setindex!(x::OneHotArray{<:Any, N}, v, i::Integer, I::Vararg{Integer, N}) where N
84+
@boundscheck checkbounds(x, i, I...)
85+
if Bool(v)
86+
@inbounds x.indices[I...] = i
87+
elseif x.indices[I...] == i
88+
@inbounds x.indices[I...] = 0
89+
end
90+
x
91+
end
92+
8393
function Base.showarg(io::IO, x::OneHotArray, toplevel)
8494
print(io, ndims(x) == 1 ? "OneHotVector(" : ndims(x) == 2 ? "OneHotMatrix(" : "OneHotArray(")
8595
Base.showarg(io, x.indices, false)

0 commit comments

Comments
 (0)