-
Notifications
You must be signed in to change notification settings - Fork 47
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
Breaking: split set
into unsafe_set
and set
#926
Open
rafaqz
wants to merge
13
commits into
main
Choose a base branch
from
better_set
base: main
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
96d4b57
tweaks
rafaqz 4d430c8
some ambiguities
rafaqz a97bc8d
Merge branch 'main' into better_set
rafaqz f2a8bdd
more set
rafaqz 3a18e8b
Update src/Dimensions/set.jl
felixcremer f2b04a7
Update src/set.jl
felixcremer 364e3ae
Update src/set.jl
felixcremer 7a4ea43
Update src/Dimensions/set.jl
felixcremer e6a1aff
Add a few test cases
felixcremer 1f311e0
Try to fix some ambiguities and some wrong variable names
felixcremer 081d606
Fix ambiguities
felixcremer b75f7c2
Reimport _astuple
felixcremer 8ba22e4
Add roundtrip tests
felixcremer 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 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 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 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 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 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 |
---|---|---|
@@ -1,52 +1,66 @@ | ||
const DimSetters = Union{LookupSetters,Type,UnionAll,Dimension,Symbol} | ||
|
||
set(dim::Dimension, ::Type{T}) where T = set(dim, T()) | ||
set(dims::DimTuple, ::Type{T}) where T = set(dims, T()) | ||
set(dim::Dimension, x::DimSetters) = _set(dim, x) | ||
set(dims_::DimTuple, args::Union{Dimension,DimTuple,Pair}...; kw...) = | ||
|
||
_set(dims_, args...; kw...) | ||
set(dims::DimTuple, l::Lookup) = set(dims, map(d -> basedims(d) => l, dims)...) | ||
set(dims::DimTuple, l::LookupTrait) = set(dims, map(d -> basedims(d) => l, dims)...) | ||
# Convert args/kw to dims and set | ||
_set(dims_::DimTuple, args::Dimension...; kw...) = _set(dims_, (args..., kw2dims(kw)...)) | ||
const DimSetters = Union{Lookup,LookupSetters,Tuple,Dimension,Symbol} | ||
|
||
set(dim::Dimension, x::DimSetters) = _set(Safe(), dim, x) | ||
set(dims::DimTuple, x::DimSetters) = _set(Safe(), dims, x) | ||
set(dims::DimTuple, p::Pair) = _set(Safe(), dims, p) | ||
set(dims::DimTuple, a1::Union{Dimension,Pair}, a2::Union{Dimension,Pair}, args::Union{Dimension,Pair}...) = | ||
_set(Safe(), dims, a1, a2, args...) | ||
|
||
unsafe_set(dim::Dimension, x::DimSetters) = _set(Unsafe(), dim, x) | ||
unsafe_set(dims::DimTuple, x::DimSetters) = _set(Unsafe(), dims, x) | ||
unsafe_set(dims::DimTuple, p::Pair) = _set(Unsafe(), dims, p) | ||
unsafe_set(dims::DimTuple, a1::Union{Dimension,Pair}, a2::Union{Dimension,Pair}, args::Union{Dimension,Pair}...) = | ||
_set(Unsafe(), dims, a1, a2, args...) | ||
|
||
_set(s::Safety, dims::DimTuple, l::LookupSetters) = | ||
_set(s, dims, map(d -> basedims(d) => l, dims)...) | ||
|
||
# Convert pairs to wrapped dims and set | ||
_set(dims_::DimTuple, p::Pair, ps::Vararg{Pair}) = _set(dims_, (p, ps...)) | ||
_set(dims_::DimTuple, ps::Tuple{Vararg{Pair}}) = _set(dims_, pairs2dims(ps...)) | ||
_set(dims_::DimTuple, ::Tuple{}) = dims_ | ||
_set(s::Safety, dims::DimTuple, p::Pair, ps::Pair...) = | ||
_set(s, dims, (p, ps...)) | ||
_set(s::Safety, dims::DimTuple, ps::Tuple{Vararg{Pair}}) = | ||
_set(s, dims, pairs2dims(ps...)) | ||
_set(s::Safety, dims::DimTuple, ::Tuple{}) = dims | ||
_set(s::Safety, dims::DimTuple, newdims::Dimension...) = | ||
_set(s, dims, newdims) | ||
# Set dims with (possibly unsorted) wrapper vals | ||
_set(dims::DimTuple, wrappers::DimTuple) = begin | ||
_set(s::Safety, dims::DimTuple, wrappers::DimTuple) = begin | ||
# Check the dimension types match | ||
map(wrappers) do w | ||
hasdim(dims, w) || _wrongdimserr(dims, w) | ||
end | ||
# Missing dims return `nothing` from sortdims | ||
newdims = map(_set, dims, sortdims(wrappers, dims)) | ||
newdims = map(dims, sortdims(wrappers, dims)) do d, w | ||
_set(s, d, w) | ||
end | ||
# Swaps existing dims with non-nothing new dims | ||
swapdims(dims, newdims) | ||
end | ||
|
||
# Set things wrapped in dims | ||
_set(dim::Dimension, wrapper::Dimension{<:DimSetters}) = | ||
_set(_set(dim, basetypeof(wrapper)), val(wrapper)) | ||
_set(s::Safety, dim::Dimension, wrapper::Dimension{<:DimSetters}) = begin | ||
rewrapped = _set(s, dim, basetypeof(wrapper)) | ||
x = _set(s, rewrapped, val(wrapper)) | ||
x | ||
end | ||
# Set the dim, checking the lookup | ||
_set(dim::Dimension, newdim::Dimension) = _set(newdim, _set(val(dim), val(newdim))) | ||
# Construct types | ||
_set(dim::Dimension, ::Type{T}) where T = _set(dim, T()) | ||
_set(dim::Dimension, key::Symbol) = _set(dim, name2dim(key)) | ||
_set(dim::Dimension, dt::DimType) = basetypeof(dt)(val(dim)) | ||
_set(dim::Dimension, x) = rebuild(dim; val=_set(val(dim), x)) | ||
# Set the lookup | ||
# Otherwise pass this on to set fields on the lookup | ||
_set(dim::Dimension, x::LookupTrait) = rebuild(dim, _set(lookup(dim), x)) | ||
_set(s::Safety, dim::Dimension, newdim::Dimension) = | ||
_set(s, newdim, _set(s, val(dim), val(newdim))) | ||
_set(s::Safety, dim::Dimension, newdim::Dimension{<:Type}) = | ||
_set(s, dim, val(newdim)()) | ||
_set(s::Safety, dim::Dimension, key::Symbol) = _set(s, dim, name2dim(key)) | ||
_set(s::Safety, dim::Dimension, x) = rebuild(dim, _set(s, val(dim), x)) | ||
_set(s::Safety, dim::Dimension, ::Type{T}) where T = _set(s, dim, T()) | ||
|
||
# Metadata | ||
_set(dim::Dimension, newmetadata::AllMetadata) = rebuild(dim, _set(lookup(dim), newmetadata)) | ||
_set(s::Safety, dim::Dimension, newmetadata::AllMetadata) = | ||
rebuild(dim, _set(s, lookup(dim), newmetadata)) | ||
|
||
_set(x::Dimension, ::Nothing) = x | ||
_set(::Nothing, x::Dimension) = x | ||
_set(::Nothing, ::Nothing) = nothing | ||
_set(x, ::Nothing) = x | ||
_set(::Nothing, x) = x | ||
_set(::Safety, x::Dimension, ::Nothing) = x | ||
_set(::Safety, ::Nothing, x::Dimension) = x | ||
_set(::Safety, ::Nothing, ::Nothing) = nothing | ||
_set(::Safety, x, ::Nothing) = x | ||
_set(::Safety, ::Nothing, x) = x | ||
|
||
@noinline _wrongdimserr(dims, w) = throw(ArgumentError("dim $(basetypeof(w))) not in $(map(basetypeof, dims))")) | ||
@noinline _wrongdimserr(dims, w) = | ||
throw(ArgumentError("dim $(basetypeof(w))) not in $(map(basetypeof, dims))")) |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be the
checkaxis
function? From what I understand they are doing conceptually the same on different input. I find it quite confusing to have two different functions with such a similar name.