Skip to content

Commit

Permalink
Merge branch 'update'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Apr 14, 2017
2 parents 843e92f + cb0a670 commit 1213352
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 49 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
[![Build Status](https://travis-ci.org/ChrisRackauckas/EllipsisNotation.jl.svg?branch=master)](https://travis-ci.org/ChrisRackauckas/EllipsisNotation.jl) [![Build status](https://ci.appveyor.com/api/projects/status/vg6bk8s3g7sr67uk?svg=true)](https://ci.appveyor.com/project/ChrisRackauckas/ellipsesnotation-jl)

This implements the notation `..` for indexing arrays. It's similar to the Python
`...` in that it means "all of the columns before (or after)". Due to its implementation
one can only use implementation indices at the beginning and end of the array (
i.e. `A[n,..]` or `A[..,n]`), and the array can only be up to 10 dimensional. However,
extending the implementation is easy (though a little tedious) and so if you need
more functionality, please submit a pull request.
`...` in that it means "all of the columns before (or after)".

# Installation

Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.4
julia 0.5
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
47 changes: 6 additions & 41 deletions src/EllipsisNotation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,14 @@ module EllipsisNotation
import Base.getindex, Base.setindex!
const .. = Val{:..}

setindex!{T}(A::AbstractArray{T,1}, x, ::Type{Val{:..}}, n::Int) = A[n] = x
setindex!{T}(A::AbstractArray{T,2}, x, ::Type{Val{:..}}, n::Int) = A[ :, n] = x
setindex!{T}(A::AbstractArray{T,3}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, n] =x
setindex!{T}(A::AbstractArray{T,4}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,5}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,6}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,7}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,8}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,9}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, :, n] =x
setindex!{T}(A::AbstractArray{T,10}, x, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, :, :, n] =x
setindex!{T,N,N2}(A::AbstractArray{T,N}, x, ::Type{Val{:..}}, n::Vararg{Int,N2}) = A[(Colon() for i in 1:N-N2)..., n...] = x
getindex{T,N,N2}(A::AbstractArray{T,N}, ::Type{Val{:..}}, n::Vararg{Int,N2}) = A[(Colon() for i in 1:N-N2)..., n...]

getindex{T}(A::AbstractArray{T,1}, ::Type{Val{:..}}, n::Int) = A[n]
getindex{T}(A::AbstractArray{T,2}, ::Type{Val{:..}}, n::Int) = A[ :, n]
getindex{T}(A::AbstractArray{T,3}, ::Type{Val{:..}}, n::Int) = A[ :, :, n]
getindex{T}(A::AbstractArray{T,4}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, n]
getindex{T}(A::AbstractArray{T,5}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, n]
getindex{T}(A::AbstractArray{T,6}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, n]
getindex{T}(A::AbstractArray{T,7}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, n]
getindex{T}(A::AbstractArray{T,8}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, n]
getindex{T}(A::AbstractArray{T,9}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, :, n]
getindex{T}(A::AbstractArray{T,10}, ::Type{Val{:..}}, n::Int) = A[ :, :, :, :, :, :, :, :, :, n]
setindex!{T,N}(A::AbstractArray{T,N}, x, n::Int, ::Type{Val{:..}}) = A[n, (Colon() for i in 1:N-1)...] = x
#setindex!{T,N,N2}(A::AbstractArray{T,N}, x, n::Vararg{Int,N2}, ::Type{Val{:..}}) = A[n, (Colon() for i in 1:N-N2-1)...] = x

setindex!{T}(A::AbstractArray{T,1}, x, n::Int, ::Type{Val{:..}}) = A[n] = x
setindex!{T}(A::AbstractArray{T,2}, x, n::Int, ::Type{Val{:..}}) = A[n, :] = x
setindex!{T}(A::AbstractArray{T,3}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :] = x
setindex!{T}(A::AbstractArray{T,4}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :] = x
setindex!{T}(A::AbstractArray{T,5}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :] = x
setindex!{T}(A::AbstractArray{T,6}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :] = x
setindex!{T}(A::AbstractArray{T,7}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :] = x
setindex!{T}(A::AbstractArray{T,8}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, :] = x
setindex!{T}(A::AbstractArray{T,9}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, :, :] = x
setindex!{T}(A::AbstractArray{T,10}, x, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, :, :, :] = x

getindex{T}(A::AbstractArray{T,1}, n::Int, ::Type{Val{:..}}) = A[n]
getindex{T}(A::AbstractArray{T,2}, n::Int, ::Type{Val{:..}}) = A[n, :]
getindex{T}(A::AbstractArray{T,3}, n::Int, ::Type{Val{:..}}) = A[n, :, :]
getindex{T}(A::AbstractArray{T,4}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :]
getindex{T}(A::AbstractArray{T,5}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :]
getindex{T}(A::AbstractArray{T,6}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :]
getindex{T}(A::AbstractArray{T,7}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :]
getindex{T}(A::AbstractArray{T,8}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, :]
getindex{T}(A::AbstractArray{T,9}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, :, :]
getindex{T}(A::AbstractArray{T,10}, n::Int, ::Type{Val{:..}}) = A[n, :, :, :, :, :, :, : ,: ,:]
getindex{T,N}(A::AbstractArray{T,N}, n::Int, ::Type{Val{:..}}) = A[n,(Colon() for i in 1:N-1)...]
#getindex{T,N,N2}(A::AbstractArray{T,N}, n::Vararg{Int,N2}, ::Type{Val{:..}}) = A[n,(Colon() for i in 1:N-N2-1)...]

export .., getindex, setindex!

Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ B = [3 4
6 7]

@test B == reshape(A[1,..],4,2)

@test A[:,1,2] == A[..,1,2]

0 comments on commit 1213352

Please sign in to comment.