Skip to content

Commit ef7e8b2

Browse files
authored
add some docs (#26)
closes #2
1 parent 6a386ba commit ef7e8b2

7 files changed

Lines changed: 90 additions & 16 deletions

File tree

docs/Manifest.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ uuid = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
7474
version = "0.4.7"
7575

7676
[[deps.AztecDiamonds]]
77-
deps = ["Adapt", "Colors", "ImageIO", "ImageShow", "KernelAbstractions", "OffsetArrays", "Transducers"]
77+
deps = ["Adapt", "Base64", "Colors", "ImageIO", "ImageShow", "KernelAbstractions", "OffsetArrays", "Transducers"]
7878
path = ".."
7979
uuid = "8762d9c5-fcab-4007-8fd1-c6de73397726"
80-
version = "0.2.3"
80+
version = "0.2.4"
8181

8282
[deps.AztecDiamonds.extensions]
8383
MakieExtension = ["Makie", "GeometryBasics"]
@@ -358,9 +358,9 @@ version = "0.7.10"
358358
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
359359

360360
[[deps.InverseFunctions]]
361-
git-tree-sha1 = "2787db24f4e03daf859c6509ff87764e4182f7d1"
361+
git-tree-sha1 = "a779299d77cd080bf77b97535acecd73e1c5e5cb"
362362
uuid = "3587e190-3f89-42d0-90ee-14403ec27112"
363-
version = "0.1.16"
363+
version = "0.1.17"
364364
weakdeps = ["Dates", "Test"]
365365

366366
[deps.InverseFunctions.extensions]

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DocMeta.setdocmeta!(AztecDiamonds, :DocTestSetup, :(using AztecDiamonds); recurs
66
makedocs(;
77
modules = [AztecDiamonds],
88
authors = "Simeon David Schaub <schaub@mit.edu> and contributors",
9-
repo = "https://github.com/JuliaLabs/AztecDiamonds.jl/blob/{commit}{path}#{line}",
9+
repo = Remotes.GitHub("JuliaLabs", "AztecDiamonds.jl"),
1010
sitename = "AztecDiamonds.jl",
1111
format = Documenter.HTML(;
1212
prettyurls = get(ENV, "CI", "false") == "true",
@@ -25,4 +25,5 @@ makedocs(;
2525
deploydocs(;
2626
repo = "github.com/JuliaLabs/AztecDiamonds.jl",
2727
devbranch = "main",
28+
push_preview = true,
2829
)

docs/src/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ CurrentModule = AztecDiamonds
66

77
Documentation for [AztecDiamonds](https://github.com/JuliaLabs/AztecDiamonds.jl).
88

9+
For an example notebook using this package, see [here](https://julia.mit.edu/AztecDiamonds.jl/examples/stable/notebook.html).
10+
11+
Here's a random diamond:
12+
13+
```@example
14+
using AztecDiamonds
15+
show(stdout, MIME("text/plain"), diamond(10))
16+
```
17+
918
```@index
1019
```
1120

src/AztecDiamonds.jl

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,41 @@ export Tiling, diamond, ka_diamond, dr_path
99

1010
inds(N) = ((1 - N):N, (1 - N):N)
1111

12+
"""
13+
Tiling(N::Int[, x::OffsetMatrix{AztecDiamonds.Edge}]; sizehint::Int = N)
14+
15+
Represents an order N diamond-shaped tiling. If `x` is not provided, it is initialized with `NONE`
16+
representing an empty tiling. The `sizehint` keyword argument may be used to preallocate a larger
17+
matrix for `x` fitting a tiling of order `sizehint` to avoid reallocations when the tiling grows.
18+
19+
The indices of `x` represent the coordinates of the diamond-shaped tiling and run from 1-N to N
20+
(though `x` is allowed to be larger as long as it contains these indices).
21+
The edges it contains can either be `UP`, `RIGHT`, or `NONE`, where `UP` represents a vertical tile
22+
covering one more tile to the top, `RIGHT` represents a horizontal tile covering one more tile to
23+
the right. `NONE` means the edge is either already covered by another tile to the bottom or left or
24+
the tiling is not fully filled yet.
25+
26+
```jldoctest
27+
julia> t = Tiling(1)
28+
1-order Tiling{Matrix{AztecDiamonds.Edge}}
29+
30+
31+
32+
julia> t[0, 0] = t[1, 0] = AztecDiamonds.RIGHT;
33+
34+
julia> t
35+
1-order Tiling{Matrix{AztecDiamonds.Edge}}
36+
🬇🬋🬋🬃
37+
🬇🬋🬋🬃
38+
```
39+
40+
See [`diamond`](@ref) and [`ka_diamond`](@ref) for constructing a filled tiling.
41+
"""
1242
struct Tiling{M <: AbstractMatrix{Edge}}
1343
N::Int
1444
x::OffsetMatrix{Edge, M}
1545
end
16-
Tiling(N::Int; sizehint = N) = Tiling(N, fill(NONE, inds(sizehint)))
46+
Tiling(N::Int; sizehint::Int = N) = Tiling(N, fill(NONE, inds(sizehint)))
1747

1848
in_diamond(N, i, j) = abs(2i - 1) + abs(2j - 1) 2N
1949
Base.checkbounds(::Type{Bool}, (; N)::Tiling, i, j) = in_diamond(N, i, j)
@@ -145,7 +175,32 @@ function diamond!(t, t′, N)
145175
return t
146176
end
147177

148-
function diamond(N)
178+
"""
179+
diamond(N::Int) -> Tiling{Matrix{AztecDiamonds.Edge}}
180+
181+
Generates a uniformally random order N diamond tiling.
182+
183+
```jldoctest
184+
julia> using Random; Random.seed!(1);
185+
186+
julia> diamond(4)
187+
4-order Tiling{Matrix{AztecDiamonds.Edge}}
188+
🬇🬋🬋🬃
189+
🬇🬋🬋🬃🬇🬋🬋🬃
190+
🬦🬓🬦🬓🬦🬓🬦🬓🬇🬋🬋🬃
191+
🬦🬓🬉🬄🬉🬄🬉🬄🬉🬄🬇🬋🬋🬃🬦🬓
192+
🬉🬄🬦🬓🬦🬓🬇🬋🬋🬃🬦🬓🬦🬓🬉🬄
193+
🬉🬄🬉🬄🬇🬋🬋🬃🬉🬄🬉🬄
194+
🬇🬋🬋🬃🬇🬋🬋🬃
195+
🬇🬋🬋🬃
196+
```
197+
198+
See [`ka_diamond`](@ref) for a version that can take advantage of GPU acceleration.
199+
`ka_diamond(N, Array)` may also be faster for large N.
200+
201+
Ref [`Tiling`](@ref)
202+
"""
203+
function diamond(N::Int)
149204
t, t′ = Tiling(0; sizehint = N), Tiling(0; sizehint = N)
150205
return diamond!(t, t′, N)
151206
end

src/ka.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,15 @@ function ka_diamond!(t, t′, N; backend)
113113
return t
114114
end
115115

116-
function ka_diamond(N, ArrayT)
116+
"""
117+
ka_diamond(N::Int, ArrayT::Type{<:AbstractArray}) -> Tiling{ArrayT{Edge}}
118+
119+
Generate a uniformly random diamond tiling just like [`diamond`](@ref), but using `KernelAbstractions.jl`
120+
to be able to take advantage of (GPU) parallelism. `ArrayT` can either be `Array` or any GPU array type.
121+
122+
Ref [`Tiling`](@ref)
123+
"""
124+
function ka_diamond(N::Int, ArrayT::Type{<:AbstractArray})
117125
mem = ntuple(_ -> fill!(ArrayT{Edge}(undef, 2N, 2N), NONE), 2)
118126
t, t′ = map(x -> Tiling(0, OffsetMatrix(x, inds(N))), mem)
119127
return ka_diamond!(t, t′, N; backend = KernelAbstractions.get_backend(mem[1]))

src/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Tiling)
7070
elseif get(t, (i, j - 1), NONE) == RIGHT
7171
color = !isdotted ? :yellow : :blue
7272
printstyled(io, "🬋🬃"; color)
73-
else
73+
elseif j < 0 || in_diamond(N, i, j) # don't produce trailing spaces
7474
print(io, " ")
7575
end
7676
end

test/show.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
N = 20
2020
D = diamond(N)
2121
r = repr(MIME("text/plain"), D)
22-
@test length(r) > 2(2N)^2
22+
@test length(r) == 2537
2323
r_color = repr(MIME("text/plain"), D; context = :color => true)
2424
@test length(r_color) == length(r) + 10length(AztecDiamonds.faces(D))
2525

@@ -46,17 +46,18 @@ end
4646
t[2, -1] = RIGHT
4747
t[2, 0] = RIGHT
4848

49+
# TODO: should
4950
expected = replace(
5051
"""
5152
4-order $Tiling{Matrix{AztecDiamonds.Edge}}
52-
🬦🬓 \\
53-
UU \\
54-
🬉🬄 \\
53+
🬦🬓 \\
54+
UU \\
55+
🬉🬄 \\
5556
🬇🬋UR 🬦🬓🬦🬓 \\
5657
🬉🬄🬇🬋NRRU🬋🬃 \\
57-
🬇🬋RR🬋🬃 \\
58-
\\
59-
""",
58+
🬇🬋RR🬋🬃 \\
59+
\\
60+
""",
6061
"\\" => ""
6162
)
6263
@test repr(MIME("text/plain"), t) == expected

0 commit comments

Comments
 (0)