Skip to content

Commit 331545e

Browse files
authored
Merge pull request #145 from JuliaArrays/jc/docs
update and add more docs
2 parents b2fd31a + e20c45d commit 331545e

File tree

10 files changed

+204
-121
lines changed

10 files changed

+204
-121
lines changed

.github/workflows/docs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Documentation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'master'
8+
- 'release-'
9+
tags: '*'
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: [1]
17+
os: [ubuntu-latest]
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
- name: Cache artifacts
24+
uses: actions/cache@v1
25+
env:
26+
cache-name: cache-artifacts
27+
with:
28+
path: ~/.julia/artifacts
29+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
30+
restore-keys: |
31+
${{ runner.os }}-test-${{ env.cache-name }}-
32+
${{ runner.os }}-test-
33+
${{ runner.os }}-
34+
- name: Install dependencies
35+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
36+
- name: Build and deploy
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: julia --project=docs/ docs/make.jl

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Manifest.toml
2+
/docs/Manifest.toml

.travis.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,3 @@ notifications:
1515
after_success:
1616
# push coverage results to Codecov
1717
- julia -e 'using Pkg, OffsetArrays; cd(joinpath(dirname(pathof(OffsetArrays)), "..")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
18-
19-
jobs:
20-
include:
21-
- stage: "Documentation"
22-
julia: 1
23-
os: linux
24-
script:
25-
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
26-
Pkg.instantiate()'
27-
- julia --project=docs/ docs/make.jl
28-
after_success: skip

README.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,24 @@ fall within these axis ranges. Example:
2323

2424
```julia
2525
using OffsetArrays
26-
A = reshape(1:15, 3, 5)
27-
println("here is A:")
28-
display(A)
29-
OA = OffsetArray(A, -1:1, 0:4) # OA will have axes (-1:1, 0:4)
30-
println("here is OA:")
31-
display(OA)
32-
@show OA[-1,0] OA[1,4]
33-
```
34-
35-
which prints out
36-
37-
```
38-
here is A:
39-
3×5 reshape(::UnitRange{Int64}, 3, 5) with eltype Int64:
40-
1 4 7 10 13
41-
2 5 8 11 14
42-
3 6 9 12 15
43-
here is OA:
44-
OffsetArray(reshape(::UnitRange{Int64}, 3, 5), -1:1, 0:4) with eltype Int64 with indices -1:1×0:4:
45-
1 4 7 10 13
46-
2 5 8 11 14
47-
3 6 9 12 15
48-
OA[-1, 0] = 1
49-
OA[1, 4] = 15
26+
julia> A = Float64.(reshape(1:15, 3, 5))
27+
3×5 Matrix{Float64}:
28+
1.0 4.0 7.0 10.0 13.0
29+
2.0 5.0 8.0 11.0 14.0
30+
3.0 6.0 9.0 12.0 15.0
31+
32+
julia> OA = OffsetArray(A, -1:1, 0:4) # OA will have axes (-1:1, 0:4)
33+
3×5 OffsetArray(::Matrix{Float64}, -1:1, 0:4) with eltype Float64 with indices -1:1×0:4:
34+
1.0 4.0 7.0 10.0 13.0
35+
2.0 5.0 8.0 11.0 14.0
36+
3.0 6.0 9.0 12.0 15.0
37+
38+
julia> OA = OffsetArray(A, CartesianIndex(-1, 0):CartesianIndex(1, 4))
39+
3×5 OffsetArray(::Matrix{Float64}, -1:1, 0:4) with eltype Float64 with indices -1:1×0:4:
40+
[...]
41+
42+
julia> OA[-1,0], OA[1,4]
43+
(1.0, 15.0)
5044
```
5145

5246
[pkgeval-img]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/O/OffsetArrays.svg

docs/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
4+
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
35

46
[compat]
5-
Documenter = "0.24"
7+
Documenter = "0.25"

docs/make.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Documenter
1+
using Documenter, JSON
22
using OffsetArrays
33

44
makedocs(
@@ -9,6 +9,17 @@ makedocs(
99
doctestfilters = [r"at \./.*", r"at /home.*", r"top-level scope.*", r"\[\d*\]\s*$"], # for backtraces
1010
)
1111

12+
# a workdaround to github action that only push preview when PR has "push_preview" labels
13+
# issue: https://github.com/JuliaDocs/Documenter.jl/issues/1225
14+
function should_push_preview(event_path = get(ENV, "GITHUB_EVENT_PATH", nothing))
15+
event_path === nothing && return false
16+
event = JSON.parsefile(event_path)
17+
haskey(event, "pull_request") || return false
18+
labels = [x["name"] for x in event["pull_request"]["labels"]]
19+
return "push_preview" in labels
20+
end
21+
1222
deploydocs(
13-
repo = "github.com:JuliaArrays/OffsetArrays.jl.git"
23+
repo = "github.com:JuliaArrays/OffsetArrays.jl.git",
24+
push_preview = should_push_preview()
1425
)

docs/src/index.md

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,54 @@ OA = OffsetArray(A, axis1, axis2, ...)
1616
```
1717

1818
where you want `OA` to have axes `(axis1, axis2, ...)` and be indexed by values that
19-
fall within these axis ranges. Example:
19+
fall within these axis ranges.
2020

21-
```julia
21+
```@repl index
2222
using OffsetArrays
23+
2324
A = Float64.(reshape(1:15, 3, 5))
24-
println("Here is A:")
25-
display(A)
26-
OA = OffsetArray(A, -1:1, 0:4) # OA will have axes (-1:1, 0:4)
27-
println("Here is OA:")
28-
display(OA)
29-
@show OA[-1,0] OA[1,4]
25+
26+
OA = OffsetArray(A, -1:1, 0:4) # OA will have axes (-1:1, 0:4)
27+
28+
OA = OffsetArray(A, CartesianIndex(-1, 0):CartesianIndex(1, 4))
29+
30+
OA[-1,0], OA[1,4]
3031
```
3132

32-
gives the output
33+
You could also pass integers as offsets, where `0` means no offsets are applied:
3334

34-
```julia
35-
here is A:
36-
3×5 Array{Float64,2}:
37-
1.0 4.0 7.0 10.0 13.0
38-
2.0 5.0 8.0 11.0 14.0
39-
3.0 6.0 9.0 12.0 15.0
40-
here is OA:
41-
3×5 OffsetArray(::Array{Float64,2}, -1:1, 0:4) with eltype Float64 with indices -1:1×0:4:
42-
1.0 4.0 7.0 10.0 13.0
43-
2.0 5.0 8.0 11.0 14.0
44-
3.0 6.0 9.0 12.0 15.0
45-
OA[-1, 0] = 1.0
46-
OA[1, 4] = 15.0
35+
```@repl index
36+
OA = OffsetArray(A, -2, -1)
4737
```
4838

49-
OffsetArrays works for arbitrary dimensionality:
39+
When you create a new `OffsetArray` on the top of another `OffsetArray`, the offsets are
40+
accumulated:
5041

51-
```julia
52-
julia> using OffsetArrays
42+
```@repl index
43+
OOA = OffsetArray(OA, 2, 1)
44+
```
5345

54-
julia> y = OffsetArray{Float64}(undef, -1:1, -7:7, -128:512, -5:5, -1:1, -3:3, -2:2, -1:1);
46+
For the special cases that you want to compensate the offset back to the ordinary 1-based array, you
47+
can use [`OffsetArrays.no_offset_view(A)`](@ref). Furthermore, you could use
48+
`Base.require_one_based_indexing` if you want to ensure the array does not have offsets.
5549

56-
julia> summary(y)
57-
"OffsetArrays.OffsetArray{Float64,8,Array{Float64,8}} with indices -1:1×-7:7×-128:512×-5:5×-1:1×-3:3×-2:2×-1:1"
50+
```@repl index
51+
OffsetArrays.no_offset_view(OA)
5852
59-
julia> y[-1,-7,-128,-5,-1,-3,-2,-1] = 14
60-
14
53+
Base.require_one_based_indexing(ans)
6154
62-
julia> y[-1,-7,-128,-5,-1,-3,-2,-1] += 5
63-
19.0
55+
Base.require_one_based_indexing(OA)
6456
```
6557

66-
You can use `OffsetArrays.no_offset_view(A)` if you want to return a view of the data in `A` but where indexing starts at 1.
67-
6858
## Example: Relativistic Notation
6959

7060
Suppose we have a position vector `r = [:x, :y, :z]` which is naturally one-based, ie. `r[1] == :x`, `r[2] == :y`, `r[3] == :z` and we also want to construct a relativistic position vector which includes time as the 0th component. This can be done with OffsetArrays like
7161

72-
```jldoctest
73-
julia> using OffsetArrays
74-
62+
```jldoctest; setup = :(using OffsetArrays)
7563
julia> r = [:x, :y, :z];
7664
7765
julia> x = OffsetVector([:t, r...], 0:3)
78-
4-element OffsetArray(::Array{Symbol,1}, 0:3) with eltype Symbol with indices 0:3:
66+
4-element OffsetArray(::Vector{Symbol}, 0:3) with eltype Symbol with indices 0:3:
7967
:t
8068
:x
8169
:y
@@ -85,7 +73,7 @@ julia> x[0]
8573
:t
8674
8775
julia> x[1:3]
88-
3-element Array{Symbol,1}:
76+
3-element Vector{Symbol}:
8977
:x
9078
:y
9179
:z
@@ -94,17 +82,17 @@ julia> x[1:3]
9482
## Example: Polynomials
9583

9684
Suppose one wants to represent the Laurent polynomial
97-
```
85+
86+
```math
9887
6/x + 5 - 2*x + 3*x^2 + x^3
9988
```
100-
in julia. The coefficients of this polynomial are a naturally `-1` based list, since the `n`th element of the list
101-
(counting from `-1`) `6, 5, -2, 3, 1` is the coefficient corresponding to the `n`th power of `x`. This Laurent polynomial can be evaluated at say `x = 2` as follows.
10289

103-
```jldoctest
104-
julia> using OffsetArrays
90+
The coefficients of this polynomial are a naturally `-1` based list, since the `n`th element of the list
91+
(counting from `-1`) `6, 5, -2, 3, 1` is the coefficient corresponding to the `n`th power of `x`. This Laurent polynomial can be evaluated at say `x = 2` as follows.
10592

93+
```jldoctest; setup = :(using OffsetArrays)
10694
julia> coeffs = OffsetVector([6, 5, -2, 3, 1], -1:3)
107-
5-element OffsetArray(::Array{Int64,1}, -1:3) with eltype Int64 with indices -1:3:
95+
5-element OffsetArray(::Vector{Int64}, -1:3) with eltype Int64 with indices -1:3:
10896
6
10997
5
11098
-2

0 commit comments

Comments
 (0)