Add similar/setindex!, update argmax/argmin#10
Closed
TLipede wants to merge 1 commit intoFluxML:mainfrom
Closed
Conversation
…ng conversion methods
mcabbott
reviewed
Mar 12, 2022
Comment on lines
+50
to
+55
| 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) |
Member
There was a problem hiding this comment.
Can you say what this similar method is for?
It seems surprising to me to return something which isn't writable. Elsewhere the pattern is that the method which takes a size returns a full matrix, but without the size, a structured one:
julia> similar(Diagonal(1:3), Float32)
3×3 Diagonal{Float32, Vector{Float32}}:
0.0 ⋅ ⋅
⋅ 0.0 ⋅
⋅ ⋅ 2.09389f-37
julia> similar(Diagonal(1:3), Float32, (3,3))
3×3 Matrix{Float32}:
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
Comment on lines
+100
to
+101
| function OneHotArray(x::AbstractVector) | ||
| !_onehot_compatible(x) && error("Array is not onehot compatible") |
Member
There was a problem hiding this comment.
What arrays do you want this to accept, which aren't AbstractVector{Bool}?
And could "not onehot compatible" explain a bit more what it means by compatible?
| cart_inds = CartesianIndex.(_indices(x), CartesianIndices(_indices(x))) | ||
| return reshape(cart_inds, (1, size(_indices(x))...)) | ||
| else | ||
| return argmax(BitArray(x); dims=dims) |
Member
There was a problem hiding this comment.
Is copying here better than invokeing the more generic method?
|
|
||
| _onehot_compatible(x::OneHotLike) = _isonehot(x) | ||
| _onehot_compatible(x::AbstractVector{Bool}) = count(x) == 1 | ||
| _onehot_compatible(x::AbstractArray{Bool}) = all(isone, reduce(+, x; dims=1)) |
Member
There was a problem hiding this comment.
Slightly tidier, maybe:
Suggested change
| _onehot_compatible(x::AbstractArray{Bool}) = all(isone, reduce(+, x; dims=1)) | |
| _onehot_compatible(x::AbstractArray{Bool}) = all(isone, count(x; dims=1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses #6. Also adds some conversion methods, and expands the arrays that the fast
hcatshould work with (as far as I can tell this should still be valid).