Conversation
|
Second commit makes overwriting a 1 with a 0 increment the label. Then julia> x = onehotbatch(1:3, 0:4)
5×3 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
⋅ ⋅ ⋅
1 ⋅ ⋅
⋅ 1 ⋅
⋅ ⋅ 1
⋅ ⋅ ⋅
julia> x[2] = 0 # changes 2 values, now
0
julia> x
5×3 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
⋅ ⋅ ⋅
⋅ ⋅ ⋅
1 1 ⋅
⋅ ⋅ 1
⋅ ⋅ ⋅
julia> x .= 1
5×3 OneHotMatrix(::Vector{UInt32}) with eltype Bool:
⋅ ⋅ ⋅
⋅ ⋅ ⋅
⋅ ⋅ ⋅
⋅ ⋅ ⋅
1 1 1
julia> x .= 0
ERROR: ArgumentError: `setindex!` here would leave the `OneHotArray` without a hot one (in this column)
|
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@mcabbott thank you for the PR. What is pending to get it merged? |
|
Mostly we need to be convinced this is doing the right thing. There were many other behaviours proposed earlier. Are we OK with Are there other surprising cases I haven't thought of? Things which are now errors & will become silently wrong answers? This seems a bit like the question of whether julia> mul!(rand(Bool,3,3), rand(Bool,3,3), rand(Bool,3,3)) # problem for Symmetric
ERROR: InexactError: Bool(2)
julia> x = rand(Bool,4,2)
4×2 Matrix{Bool}:
0 1
1 1
1 0
1 1
julia> prod!(rand(Bool,4), x)
4-element Vector{Bool}:
0
1
0
1
julia> prod!(onehotbatch(3, 1:4), x) # with this PR, often an error, here silenty wrong
4-element OneHotVector(::Array{UInt32, 0}) with eltype Bool:
⋅
⋅
⋅
1 |
First commit has a version of the
setindex!method suggested at #6 (comment), which works like this:Allowing you to replace the only 1 by 0 is what makes the
copyto!example work, where this is a temporary state. But it also allowsx .= 0as in the last example, which leaves the array in a state we otherwise disallow:I forgot about #10, which instead makes writing
0always an error.This comment #6 (comment) suggested only allowing things like the following -- where a single
setindex!call can be sure never to leave the array in an illegal state:PR Checklist