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 pull request adds a
@view
macro, which translatesA[a:b, c:d]
syntax toview(A, a:b, c:d)
.Any
symbol("end")
s found in square brackets (unless they occur in nested square brackets) are converted to eithersize(A, d)
or, if only one indexing object,length(A)
. The special case of1:end
is replaced by:
instead of1:size(A, d)
. For example:@view(A[5:end-2])
=>view(A, 5:length(A)-2)
@view(A[5:end, 3:b])
=>view(A, 5:size(A,1), 3:b)
@view(A[1:end, 3:b])
=>view(A, :, 3:b)
@view(A[c[3:end]])
=>view(A, :, c[3:end])
@view
only works on named arrays.@view(rand(10,10)[1:5, :])
will throw an error, because I don't think you'd want a view of an array that wasn't a named object very often.I'm making some assumptions that I'm not 100% sure of, so please let me know if they could cause an issue:
symbol("end")
can only occur in an expression or subexpression of an expression with head:ref
symbol("end")
with either a call tosize
orlength
symbol("end")
in a:ref
expression that is a subexpression of another:ref
, thesymbol("end")
applies to the innermost:ref
expression.I also have a bunch of tests but I imagine they wouldn't be considered good practice for testing macros, so any feedback on that would be appreciated!