EllipsisNotation.jl

EllipsisNotation.jl implements the notation .. for indexing arrays. It's similar to the Python ... in that it means 'all the columns before (or after)'.

.. slurps dimensions greedily, meaning that the first occurrence of .. in an index expression creates as many slices as possible. Other instances of .. afterward are treated simply as slices. Usually, you should only use one instance of .. in an indexing expression to avoid possible confusion.

Installation

using Pkg
Pkg.add("EllipsisNotation")
using EllipsisNotation

Example Usage

julia> A = Array{Int}(undef, 2, 4, 2)

julia> A[.., 1] = [2 1 4 5
           2 2 3 6]

julia> A[.., 2] = [3 2 6 5
           3 2 6 6]

julia> A[:, :, 1] == [2 1 4 5
           2 2 3 6]
true

julia> A[1, ..] = reshape([3 4
               5 6
               4 5
               6 7], 1, 4, 2) # drops singleton dimension

julia> B = [3 4
           5 6
           4 5
           6 7]

julia> B == reshape(A[1, ..], 4, 2)
true

julia> A[.., 1, 2] # Can do as many integers as you want on the end!

For avoiding squeezing dimensions from slicing.

julia> C = ones(3, 3, 3, 3, 3);

julia> size(C[1:1, .., 1:1])
(1, 3, 3, 3, 1)

Note: .. slurps dimensions greedily, meaning that the first occurrence of .. in an index expression creates as many slices as possible. Other instances of .. afterwards are treated simply as slices. Usually, you should only use one instance of .. in an indexing expression to avoid possible confusion.

Warning: .. does not work when indexing also with end or begin. For example, A = randn(2,3,4); A[.., 1:end] will not give the intended result. This is a known limitation, and is not likely to be fixed until some necessary changes in the Julia language itself are implemented. See https://github.com/ChrisRackauckas/EllipsisNotation.jl/issues/19 for more details.

Contributing

Acknowledgements

I would like to acknowledge M. Schauer for the .. notation implementation. He had the original idea, I just extended it and put it into a package because of how useful it has been to me.

Reproducibility

The documentation of this SciML package was built using these direct dependencies,
Status `~/.julia/packages/EllipsisNotation/duIu5/docs/Project.toml`
  [e30172f5] Documenter v1.1.2
  [da5c29d0] EllipsisNotation v1.8.0 `~/.julia/packages/EllipsisNotation/duIu5`
and using this machine and Julia version.
Julia Version 1.9.2
Commit e4ee485e909 (2023-07-05 09:39 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, icelake-server)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_CPU_TARGET = generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)
  JULIA_GPG = 3673DF529D9049477F76B37566E3C7DC03D6E495
  JULIA_PKG_UNPACK_REGISTRY = true
  JULIA_VERSION = 1.9.2
  JULIA_PATH = /usr/local/julia
  JULIA_PKG_SERVER =
A more complete overview of all dependencies and their versions is also provided.
Status `~/.julia/packages/EllipsisNotation/duIu5/docs/Manifest.toml`
  [a4c015fc] ANSIColoredPrinters v0.0.1
  [1520ce14] AbstractTrees v0.4.4
  [79e6a3ab] Adapt v3.7.1
  [4fba245c] ArrayInterface v7.5.1
  [34da2185] Compat v4.10.0
  [ffbed154] DocStringExtensions v0.9.3
  [e30172f5] Documenter v1.1.2
  [da5c29d0] EllipsisNotation v1.8.0 `~/.julia/packages/EllipsisNotation/duIu5`
  [b5f81e59] IOCapture v0.2.3
  [615f187c] IfElse v0.1.1
  [682c06a0] JSON v0.21.4
  [0e77f7df] LazilyInitializedFields v1.2.1
  [d0879d2d] MarkdownAST v0.1.2
  [69de0a69] Parsers v2.7.2
  [aea7be01] PrecompileTools v1.2.0
  [21216c6a] Preferences v1.4.1
  [2792f1a3] RegistryInstances v0.1.0
  [ae029012] Requires v1.3.0
  [aedffcd0] Static v0.8.8
  [0d7ed370] StaticArrayInterface v1.4.1
  [0dad84c5] ArgTools v1.1.1
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [f43a241f] Downloads v1.6.0
  [7b1f6079] FileWatching
  [b77e0a4c] InteractiveUtils
  [b27032c2] LibCURL v0.6.3
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [ca575930] NetworkOptions v1.2.0
  [44cfe95a] Pkg v1.9.2
  [de0858da] Printf
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA v0.7.0
  [9e88b42a] Serialization
  [6462fe0b] Sockets
  [2f01184e] SparseArrays
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML v1.0.3
  [a4e569a6] Tar v1.10.0
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll v1.0.5+0
  [deac9b47] LibCURL_jll v7.84.0+0
  [29816b5a] LibSSH2_jll v1.10.2+0
  [c8ffd9c3] MbedTLS_jll v2.28.2+0
  [14a3606d] MozillaCACerts_jll v2022.10.11
  [4536629a] OpenBLAS_jll v0.3.21+4
  [bea87d4a] SuiteSparse_jll v5.10.1+6
  [83775a58] Zlib_jll v1.2.13+0
  [8e850b90] libblastrampoline_jll v5.8.0+0
  [8e850ede] nghttp2_jll v1.48.0+0
  [3f19e933] p7zip_jll v17.4.0+0

You can also download the manifest file and the project file.