Skip to content

Commit 5a7e683

Browse files
authored
Merge pull request #331 from abhro/docs
Update documentation
2 parents 4ad50d5 + 62fd112 commit 5a7e683

File tree

10 files changed

+70
-61
lines changed

10 files changed

+70
-61
lines changed

.github/workflows/Documenter.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ on:
99
tags: '*'
1010
jobs:
1111
docs:
12+
name: Documentation
1213
permissions:
1314
contents: write
1415
statuses: write
15-
name: Documentation
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v6
1919
- uses: julia-actions/setup-julia@v2
2020
with:
21-
version: '1'
21+
version: '1.10'
22+
- uses: julia-actions/cache@v2
2223
- name: Install dependencies
23-
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
24+
shell: julia --color=yes --project=docs {0}
25+
run: 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
2426
- name: Build and deploy
27+
run: julia --color=yes --project=docs docs/make.jl
2528
env:
2629
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2730
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
28-
run: julia --project=docs/ docs/make.jl

docs/Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
44
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
5+
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
6+
7+
[sources]
8+
StructArrays = {path = ".."}
59

610
[compat]
7-
Documenter = "0.27"
11+
Documenter = "1"
812
PooledArrays = "1"
13+
StaticArrays = "1"

docs/make.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
push!(LOAD_PATH, dirname(@__DIR__))
2-
31
using Documenter
42
using StructArrays
53

@@ -13,7 +11,8 @@ makedocs(
1311
"Some counterintuitive behaviors"=>"counterintuitive.md",
1412
"Advanced techniques"=>"advanced.md",
1513
"Index"=>"reference.md",
16-
]
14+
],
15+
warnonly = [:missing_docs],
1716
)
1817

1918
# Documenter can also automatically deploy documentation to gh-pages.

docs/src/advanced.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ StructArrays provides a function `StructArrays.append!!(dest, src)` (unexported)
6666

6767
`StructArrays.append!!` works like `append!(dest, src)` if `dest` can contain all element types in `src` iterator; i.e., it _mutates_ `dest` in-place:
6868

69-
```julia
69+
```julia-repl
7070
julia> dest = StructVector((a=[1], b=[2]))
71-
1-element StructArray(::Array{Int64,1}, ::Array{Int64,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,Int64}}:
71+
1-element StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype NamedTuple{(:a, :b),Tuple{Int64,Int64}}:
7272
(a = 1, b = 2)
7373
7474
julia> StructArrays.append!!(dest, [(a = 3, b = 4)])
75-
2-element StructArray(::Array{Int64,1}, ::Array{Int64,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,Int64}}:
75+
2-element StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype NamedTuple{(:a, :b),Tuple{Int64,Int64}}:
7676
(a = 1, b = 2)
7777
(a = 3, b = 4)
7878
@@ -82,9 +82,9 @@ true
8282

8383
Unlike `append!`, `append!!` can also _widen_ element type of `dest` array:
8484

85-
```julia
85+
```julia-repl
8686
julia> StructArrays.append!!(dest, [(a = missing, b = 6)])
87-
3-element StructArray(::Array{Union{Missing, Int64},1}, ::Array{Int64,1}) with eltype NamedTuple{(:a, :b),Tuple{Union{Missing, Int64},Int64}}:
87+
3-element StructArray(::Vector{Union{Missing, Int64}}, ::Vector{Int64}) with eltype NamedTuple{(:a, :b),Tuple{Union{Missing, Int64},Int64}}:
8888
NamedTuple{(:a, :b),Tuple{Union{Missing, Int64},Int64}}((1, 2))
8989
NamedTuple{(:a, :b),Tuple{Union{Missing, Int64},Int64}}((3, 4))
9090
NamedTuple{(:a, :b),Tuple{Union{Missing, Int64},Int64}}((missing, 6))

docs/src/counterintuitive.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
```@meta
2+
DocTestSetup = :(using StructArrays)
3+
```
14
# Some counterintuitive behaviors
25

36
When created from parent arrays representing each field of the final `struct`, StructArrays creates a "view" which
@@ -13,7 +16,7 @@ These issues are elucidated below.
1316

1417
For this demonstration, throughout we'll use this mutable struct:
1518

16-
```jldoctest counter1; setup=:(using StructArrays)
19+
```jldoctest counter1
1720
julia> mutable struct Foo{T}
1821
a::T
1922
b::T
@@ -181,7 +184,7 @@ None of the changes to `soa` "propagated" to `aos`. This is because a StructArra
181184
## Broadcasted assignment for array entries
182185

183186
Broadcasted in-place assignment can also behave counterintuitively for StructArrays.
184-
```jldoctest; setup=:(using StructArrays)
187+
```jldoctest
185188
julia> using StaticArrays # for FieldVector
186189
187190
julia> mutable struct Bar{T} <: FieldVector{2,T}

docs/src/examples.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
## Example usage to store complex numbers
22

3-
```julia
3+
```julia-repl
44
julia> using StructArrays, Random
55
66
julia> Random.seed!(4);
77
88
julia> s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
9-
2×2 StructArray(::Array{Float64,2}, ::Array{Float64,2}) with eltype Complex{Float64}:
9+
2×2 StructArray(::Matrix{Float64}, ::Matrix{Float64}) with eltype Complex{Float64}:
1010
0.680079+0.625239im 0.92407+0.267358im
1111
0.874437+0.737254im 0.929336+0.804478im
1212
1313
julia> s[1, 1]
1414
0.680079235935741 + 0.6252391193298537im
1515
1616
julia> s.re
17-
2×2 Array{Float64,2}:
17+
2×2 Matrix{Float64}:
1818
0.680079 0.92407
1919
0.874437 0.929336
2020
@@ -24,39 +24,39 @@ julia> StructArrays.components(s) # obtain all field arrays as a named tuple
2424

2525
Note that the same approach can be used directly from an `Array` of complex numbers:
2626

27-
```julia
27+
```julia-repl
2828
julia> StructArray([1+im, 3-2im])
29-
2-element StructArray(::Array{Int64,1}, ::Array{Int64,1}) with eltype Complex{Int64}:
29+
2-element StructArray(::Vector{Int64}, ::Vector{Int64}) with eltype Complex{Int64}:
3030
1 + 1im
3131
3 - 2im
3232
```
3333

3434
## Example usage to store a data table
3535

36-
```julia
36+
```julia-repl
3737
julia> t = StructArray((a = [1, 2], b = ["x", "y"]))
38-
2-element StructArray(::Array{Int64,1}, ::Array{String,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
38+
2-element StructArray(::Vector{Int64}, ::Vector{String}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
3939
(a = 1, b = "x")
4040
(a = 2, b = "y")
4141
4242
julia> t[1]
4343
(a = 1, b = "x")
4444
4545
julia> t.a
46-
2-element Array{Int64,1}:
46+
2-element Vector{Int64}:
4747
1
4848
2
4949
5050
julia> push!(t, (a = 3, b = "z"))
51-
3-element StructArray(::Array{Int64,1}, ::Array{String,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
51+
3-element StructArray(::Vector{Int64}, ::Vector{String}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
5252
(a = 1, b = "x")
5353
(a = 2, b = "y")
5454
(a = 3, b = "z")
5555
```
5656

5757
## Example usage with StaticArray elements
5858

59-
```julia
59+
```julia-repl
6060
julia> using StructArrays, StaticArrays
6161
6262
julia> x = StructArray([SVector{2}(1,2) for i = 1:5])
@@ -84,4 +84,4 @@ julia> B = StructArray([SArray{Tuple{2,2,2}}(reshape(1:8,2,2,2)) for i = 1:5]);
8484
[:, :, 2] =
8585
5 7
8686
6 8
87-
```
87+
```

docs/src/index.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ StructArray(log(j+2.0*im) for j in 1:10)
4646

4747
Another option is to create an uninitialized `StructArray` and then fill it with data. Just like in normal arrays, this is done with the `undef` syntax:
4848

49-
```julia
49+
```julia-repl
5050
julia> s = StructArray{ComplexF64}(undef, 2, 2)
51-
2×2 StructArray(::Array{Float64,2}, ::Array{Float64,2}) with eltype Complex{Float64}:
51+
2×2 StructArray(::Matrix{Float64}, ::Matrix{Float64}) with eltype Complex{Float64}:
5252
6.91646e-310+6.91646e-310im 6.91646e-310+6.91646e-310im
5353
6.91646e-310+6.91646e-310im 6.91646e-310+6.91646e-310im
5454
5555
julia> rand!(s)
56-
2×2 StructArray(::Array{Float64,2}, ::Array{Float64,2}) with eltype Complex{Float64}:
56+
2×2 StructArray(::Matrix{Float64}, ::Matrix{Float64}) with eltype Complex{Float64}:
5757
0.680079+0.874437im 0.625239+0.737254im
5858
0.92407+0.929336im 0.267358+0.804478im
5959
```
@@ -88,7 +88,7 @@ julia> soa.re
8888

8989
`StructArray`s supports using custom array types. It is always possible to pass field arrays of a custom type. The "custom array of `struct`s to `struct` of custom arrays" transformation will use the `similar` method of the custom array type. This can be useful when working on the GPU for example:
9090

91-
```julia
91+
```julia-repl
9292
julia> using StructArrays, CuArrays
9393
9494
julia> a = CuArray(rand(Float32, 10));
@@ -111,7 +111,7 @@ julia> StructArray{ComplexF32}((a, b))
111111
julia> c = CuArray(rand(ComplexF32, 10));
112112
113113
julia> StructArray(c)
114-
10-element StructArray(::Array{Float32,1}, ::Array{Float32,1}) with eltype Complex{Float32}:
114+
10-element StructArray(::Vector{Float32}, ::Vector{Float32}) with eltype Complex{Float32}:
115115
0.7176411f0 + 0.864058f0im
116116
0.252609f0 + 0.14824867f0im
117117
0.26842773f0 + 0.9084332f0im
@@ -126,9 +126,9 @@ julia> StructArray(c)
126126

127127
If you already have your data in a `StructArray` with field arrays of a given format (say plain `Array`) you can change them with `replace_storage`:
128128

129-
```julia
129+
```julia-repl
130130
julia> s = StructArray([1.0+im, 2.0-im])
131-
2-element StructArray(::Array{Float64,1}, ::Array{Float64,1}) with eltype Complex{Float64}:
131+
2-element StructArray(::Vector{Float64}, ::Vector{Float64}) with eltype Complex{Float64}:
132132
1.0 + 1.0im
133133
2.0 - 1.0im
134134
@@ -142,7 +142,7 @@ julia> replace_storage(CuArray, s)
142142

143143
`StructArray`s also provides a `LazyRow` wrapper for lazy row iteration. `LazyRow(t, i)` does not materialize the i-th row but returns a lazy wrapper around it on which `getproperty` does the correct thing. This is useful when the row has many fields only some of which are necessary. It also allows changing columns in place.
144144

145-
```julia
145+
```julia-repl
146146
julia> t = StructArray((a = [1, 2], b = ["x", "y"]));
147147
148148
julia> LazyRow(t, 2).a
@@ -152,26 +152,26 @@ julia> LazyRow(t, 2).a = 123
152152
123
153153
154154
julia> t
155-
2-element StructArray(::Array{Int64,1}, ::Array{String,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
155+
2-element StructArray(::Vector{Int64}, ::Vector{String}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
156156
(a = 1, b = "x")
157157
(a = 123, b = "y")
158158
```
159159

160160
To iterate in a lazy way one can simply iterate `LazyRows`:
161161

162-
```julia
162+
```julia-repl
163163
julia> map(t -> t.b ^ t.a, LazyRows(t))
164-
2-element Array{String,1}:
164+
2-element Vector{String}:
165165
"x"
166166
"yy"
167167
```
168168

169169
## Applying a function on each field array
170170

171-
```julia
171+
```julia-repl
172172
julia> struct Foo
173-
a::Int
174-
b::String
173+
a::Int
174+
b::String
175175
end
176176
177177
julia> s = StructArray([Foo(11, "a"), Foo(22, "b"), Foo(33, "c"), Foo(44, "d"), Foo(55, "e")]);

src/interface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ this will have fields with the same names and types as `T`.
1919
This can be overloaded for custom types if required, in which case
2020
[`StructArrays.component`](@ref) and [`StructArrays.createinstance`](@ref)
2121
should also be defined.
22-
22+
2323
```julia-repl
2424
julia> StructArrays.staticschema(Complex{Float64})
2525
NamedTuple{(:re, :im),Tuple{Float64,Float64}}

src/lazy.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ julia> LazyRow(t, 2).a = 123
2020
123
2121
2222
julia> t
23-
2-element StructArray(::Array{Int64,1}, ::Array{String,1}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
23+
2-element StructArray(::Vector{Int64}, ::Vector{String}) with eltype NamedTuple{(:a, :b),Tuple{Int64,String}}:
2424
(a = 1, b = "x")
2525
(a = 123, b = "y")
2626
```
@@ -68,7 +68,7 @@ An iterator of [`LazyRow`](@ref)s of `s`.
6868
6969
```julia-repl
7070
julia> map(t -> t.b ^ t.a, LazyRows(t))
71-
2-element Array{String,1}:
71+
2-element Vector{String}:
7272
"x"
7373
"yy"
7474
```

0 commit comments

Comments
 (0)