-
Notifications
You must be signed in to change notification settings - Fork 40
General out indices #511
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
Open
FelixBenning
wants to merge
10
commits into
JuliaGaussianProcesses:master
Choose a base branch
from
FelixBenning:general_out_indices
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
General out indices #511
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
497db8e
allow arbitrary out indices
FelixBenning fc1cbfc
green tests
FelixBenning bc7e553
formatter
FelixBenning 133599e
implement most review comments
FelixBenning 913ed38
actually ensure @inbounds
FelixBenning d6fd996
missed suggestion
FelixBenning be23f44
fix typo
FelixBenning bdee782
formatter
FelixBenning 1e79045
ensure offset arrays work with tests
FelixBenning 12a1e05
fix jldoctest
FelixBenning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,17 @@ The first `out_dim` elements represent all outputs for the first input, the seco | |
|
||
See [Inputs for Multiple Outputs](@ref) in the docs for more info. | ||
""" | ||
struct MOInputIsotopicByFeatures{S,T<:AbstractVector{S},Tout_dim<:Integer} <: | ||
AbstractVector{Tuple{S,Int}} | ||
struct MOInputIsotopicByFeatures{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the type parameters is a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. really? :/ |
||
S,T<:AbstractVector{S},IdxType,ToutIndices<:AbstractVector{IdxType} | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} <: AbstractVector{Tuple{S,IdxType}} | ||
x::T | ||
out_dim::Tout_dim | ||
outIndices::ToutIndices | ||
end | ||
|
||
function MOInputIsotopicByFeatures( | ||
x::T, out_dim::Tout_dim | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) where {S,T<:AbstractVector{S},Tout_dim<:Integer} | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return MOInputIsotopicByFeatures{S,T,Int,Base.OneTo{Tout_dim}}(x, Base.OneTo(out_dim)) | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
""" | ||
|
@@ -54,10 +61,17 @@ As shown above, an `MOInputIsotopicByOutputs` represents a vector of tuples. | |
The first `length(x)` elements represent the inputs for the first output, the second | ||
`length(x)` elements represent the inputs for the second output, etc. | ||
""" | ||
struct MOInputIsotopicByOutputs{S,T<:AbstractVector{S},Tout_dim<:Integer} <: | ||
AbstractVector{Tuple{S,Int}} | ||
struct MOInputIsotopicByOutputs{ | ||
S,T<:AbstractVector{S},IdxType,ToutIndices<:AbstractVector{IdxType} | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} <: AbstractVector{Tuple{S,IdxType}} | ||
x::T | ||
out_dim::Tout_dim | ||
outIndices::ToutIndices | ||
end | ||
|
||
function MOInputIsotopicByOutputs( | ||
x::T, out_dim::Tout_dim | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) where {S,T<:AbstractVector{S},Tout_dim<:Integer} | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return MOInputIsotopicByOutputs{S,T,Int,Base.OneTo{Tout_dim}}(x, Base.OneTo(out_dim)) | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
const IsotopicMOInputsUnion = Union{MOInputIsotopicByFeatures,MOInputIsotopicByOutputs} | ||
|
@@ -66,26 +80,26 @@ function Base.getindex(inp::MOInputIsotopicByOutputs, ind::Integer) | |
@boundscheck checkbounds(inp, ind) | ||
output_index, feature_index = fldmod1(ind, length(inp.x)) | ||
feature = @inbounds inp.x[feature_index] | ||
return feature, output_index | ||
return feature, @inbounds inp.outIndices[output_index] | ||
FelixBenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
function Base.getindex(inp::MOInputIsotopicByFeatures, ind::Integer) | ||
@boundscheck checkbounds(inp, ind) | ||
feature_index, output_index = fldmod1(ind, inp.out_dim) | ||
feature_index, output_index = fldmod1(ind, length(inp.outIndices)) | ||
feature = @inbounds inp.x[feature_index] | ||
return feature, output_index | ||
return feature, @inbounds inp.outIndices[output_index] | ||
end | ||
|
||
Base.size(inp::IsotopicMOInputsUnion) = (inp.out_dim * length(inp.x),) | ||
Base.size(inp::IsotopicMOInputsUnion) = (length(inp.outIndices) * length(inp.x),) | ||
|
||
function Base.vcat(x::MOInputIsotopicByFeatures, y::MOInputIsotopicByFeatures) | ||
x.out_dim == y.out_dim || throw(DimensionMismatch("out_dim mismatch")) | ||
return MOInputIsotopicByFeatures(vcat(x.x, y.x), x.out_dim) | ||
x.outIndices == y.outIndices || throw(DimensionMismatch("outIndices mismatch")) | ||
return MOInputIsotopicByFeatures(vcat(x.x, y.x), x.outIndices) | ||
end | ||
|
||
function Base.vcat(x::MOInputIsotopicByOutputs, y::MOInputIsotopicByOutputs) | ||
x.out_dim == y.out_dim || throw(DimensionMismatch("out_dim mismatch")) | ||
return MOInputIsotopicByOutputs(vcat(x.x, y.x), x.out_dim) | ||
x.outIndices == y.outIndices || throw(DimensionMismatch("outIndices mismatch")) | ||
return MOInputIsotopicByOutputs(vcat(x.x, y.x), x.outIndices) | ||
end | ||
|
||
""" | ||
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.