To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
begin
import Pkg
Pkg.activate(mktempdir())
end
❔
  Activating new project at `/tmp/jl_T3cvUz`
116 ms
👀 Reading hidden code
begin
Pkg.add("OffsetArrays")
using OffsetArrays
end
❔
    Updating registry at `~/.julia/registries/General.toml`
   Resolving package versions...
    Updating `/tmp/jl_T3cvUz/Project.toml`
  [6fe1bfb0] + OffsetArrays v1.17.0
    Updating `/tmp/jl_T3cvUz/Manifest.toml`
  [79e6a3ab] + Adapt v4.3.0
  [6fe1bfb0] + OffsetArrays v1.17.0
  [ae029012] + Requires v1.3.1
  [56f22d72] + Artifacts
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [cf7118a7] + UUIDs
  [e66e0078] + CompilerSupportLibraries_jll
  [4536629a] + OpenBLAS_jll
  [8e850b90] + libblastrampoline_jll
2.0 s
3×5 reshape(::UnitRange{Int64}, 3, 5) with eltype Int64:
 1  4  7  10  13
 2  5  8  11  14
 3  6  9  12  15
👀 Reading hidden code
A = reshape(1:15, 3, 5)
15.8 μs
3×5 OffsetArray(reshape(::UnitRange{Int64}, 3, 5), -1:1, 0:4) with eltype Int64 with indices -1:1×0:4:
 1  4  7  10  13
 2  5  8  11  14
 3  6  9  12  15
👀 Reading hidden code
OA = OffsetArray(A, -1:1, 0:4) # OA will have axes (-1:1, 0:4)
44.1 μs
👀 Reading hidden code
OffsetArray(rand(100),30)
16.3 μs
B = collect(rand(10))
👀 Reading hidden code
17.6 μs

👀 Reading hidden code
66.1 μs
OffsetArray(zeros(3), 20:22)
👀 Reading hidden code
18.1 μs
OB = OffsetArray(B, 5)
👀 Reading hidden code
15.0 μs
[
OB[i] for i in eachindex(OB)
] |> collect
👀 Reading hidden code
42.8 ms
enumerate(OB) |> collect
👀 Reading hidden code
19.7 ms
p = pairs(IndexLinear(), OB) |> collect
👀 Reading hidden code
42.1 ms
[(1,2),(3,[4,5])]
👀 Reading hidden code
25.4 ms
NamedTuple
NamedTuple
👀 Reading hidden code
9.8 μs
nt = (a=1,b=2)
👀 Reading hidden code
17.2 μs
NamedTuple{(:a, :b), Tuple{Int64, Int64}}
nt |> typeof
👀 Reading hidden code
83.1 μs
true
t isa Tuple
👀 Reading hidden code
14.5 μs
false
nt isa NTuple
👀 Reading hidden code
14.1 μs
"a"
sprint(print, :a)
👀 Reading hidden code
18.1 μs
t = (1,2,3)
👀 Reading hidden code
15.0 μs
zip(eachindex(t), t) |> collect
👀 Reading hidden code
90.1 ms
zip(eachindex(nt), nt) |> collect
👀 Reading hidden code
74.5 ms
let
a,b = (1,2)
end
👀 Reading hidden code
19.8 μs
collect(d)
👀 Reading hidden code
12.5 μs
1
2
1 => 2
👀 Reading hidden code
12.3 μs
r = Ref((1,2))
👀 Reading hidden code
16.1 μs
true
r isa Ref{Tuple{Int,Int}}
👀 Reading hidden code
19.4 μs
d=Dict([:a=>1,:b=>2])
👀 Reading hidden code
21.8 μs
Tuple(1:1000)
👀 Reading hidden code
109 μs
typename(Markdown.MD)
(md"" |> typeof).name
👀 Reading hidden code
3.0 ms
"AbstractDict"
sprint(print, nameof(AbstractDict))
👀 Reading hidden code
5.5 ms
show(io::IO, x::Type) in Base at show.jl:881
@which Base.show(stdout, p |> typeof)
👀 Reading hidden code
101 ms
Error message

BoundsError: attempt to access 10-element OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}} with indices 6:15 at index [1:3]

Stack trace

Here is what happened, the most recent locations are first:

  1. throw_boundserror(A::OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}, I::Tuple{UnitRange{Int64}})
  2. checkbounds
  3. getindex
  4. eachindex(OB)[1:3]
uhmmmmmm??!
eachindex(OB)[1:3]
👀 Reading hidden code
---
Error message

BoundsError: attempt to access 10-element LinearIndices{1, Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}} with indices 6:15 at index [1:3]

Stack trace

Here is what happened, the most recent locations are first:

  1. throw_boundserror(A::LinearIndices{1, Tuple{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}}}, I::Tuple{UnitRange{Int64}})
  2. checkbounds
  3. getindex
  4. LinearIndices(OB)[1:3]
Be patient :)
LinearIndices(OB)[1:3]
👀 Reading hidden code
---
OB
👀 Reading hidden code
8.8 μs
Error message

syntax: incomplete: "begin" at /home/runner/work/disorganised-mess/disorganised-mess/offsetarrays.jl#==#77d2f1b8-ed72-11ea-36c3-8d791b899b19:1 requires end

begin:begin+1
👀 Reading hidden code
---
zip(eachindex(OB)[begin:begin+3-1], OB[begin:begin+3-1]) |> collect
👀 Reading hidden code
94.5 ms
OB[end-3+1:end]
👀 Reading hidden code
3.6 ms