Created
April 5, 2017 17:07
-
-
Save gabrielgellner/9f2984b92bcc4b0d547b8d3f6b4417dc to your computer and use it in GitHub Desktop.
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
# So that we ensure that dimensions do not drop (Taken from Matt Bauman, the man the legend) | |
make_reals_one_vectors(x::Real) = x:x | |
make_reals_one_vectors(x) = x | |
@Base.propagate_inbounds fullindex(x, I...) = getindex(x, map(make_reals_one_vectors, I)...) | |
# This code is just taken from Base, where I replace view -> fullindex | |
macro nodrop(ex) | |
if Meta.isexpr(ex, :ref) | |
ex = Base.replace_ref_end!(ex) | |
if Meta.isexpr(ex, :ref) | |
ex = Expr(:call, fullindex, ex.args...) | |
else # ex replaced by let ...; foo[...]; end | |
assert(Meta.isexpr(ex, :let) && Meta.isexpr(ex.args[1], :ref)) | |
ex.args[1] = Expr(:call, fullindex, ex.args[1].args...) | |
end | |
Expr(:&&, true, esc(ex)) | |
else | |
throw(ArgumentError("Invalid use of @nodrop macro: argument must be a reference expression A[...].")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment