Skip to content

Commit dda39e4

Browse files
authored
Add axes support for SnakePattern (#55)
* Add `axes` for `SnakePattern` * Bump version * More fixes * SnakePattern tests
1 parent d5b3804 commit dda39e4

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MPSKitModels"
22
uuid = "ca635005-6f8c-4cd1-b51d-8491250ef2ab"
33
authors = ["Maarten Van Damme", "Lukas Devos", "Gertian Roose", "Klaas Gunst"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/lattices/snakepattern.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ end
1010

1111
SnakePattern(lattice) = SnakePattern(lattice, identity)
1212

13+
Base.axes(lattice::SnakePattern) = axes(lattice.lattice)
14+
Base.isfinite(::Type{SnakePattern{N,G}}) where {N,G} = isfinite(G)
15+
1316
function linearize_index(snake::SnakePattern, i...)
1417
return snake.pattern(linearize_index(snake.lattice, i...))
1518
end
1619

17-
vertices(snake::SnakePattern) = vertices(snake.lattice)
18-
nearest_neighbours(snake::SnakePattern) = nearest_neighbours(snake.lattice)
20+
function vertices(snake::SnakePattern)
21+
return map(x -> LatticePoint(x.coordinates, snake), vertices(snake.lattice))
22+
end
23+
function nearest_neighbours(snake::SnakePattern)
24+
return map(nearest_neighbours(snake.lattice)) do (x, y)
25+
return LatticePoint(x.coordinates, snake), LatticePoint(y.coordinates, snake)
26+
end
27+
end
1928
bipartition(snake::SnakePattern) = bipartition(snake.lattice)
2029

2130
"""

test/lattices.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,43 @@ end
201201
@test allunique(NNN)
202202
end
203203
end
204+
205+
@testset "SnakePattern" begin
206+
base_lattice = FiniteCylinder(4, 16)
207+
base_V = vertices(base_lattice)
208+
base_NN = nearest_neighbours(base_lattice)
209+
210+
lattice = SnakePattern(base_lattice, identity)
211+
212+
V = vertices(lattice)
213+
@test all(zip(V, base_V)) do (x, y)
214+
return linearize_index(x) == linearize_index(y)
215+
end
216+
217+
@test length(base_lattice) == length(lattice)
218+
@test lattice[1, 1] == first(V)
219+
220+
NN = nearest_neighbours(lattice)
221+
@test all(zip(NN, base_NN)) do (x, y)
222+
return linearize_index.(Tuple(x)) ==
223+
linearize_index.(Tuple(y))
224+
end
225+
226+
pattern(i) = length(lattice) - i + 1
227+
lattice = SnakePattern(base_lattice, pattern)
228+
229+
V = vertices(lattice)
230+
@test all(zip(V, base_V)) do (x, y)
231+
return linearize_index(x) == pattern(linearize_index(y))
232+
end
233+
234+
@test length(base_lattice) == length(lattice)
235+
@test lattice[1, 1] == first(V)
236+
237+
base_NN = nearest_neighbours(base_lattice)
238+
NN = nearest_neighbours(lattice)
239+
@test all(zip(NN, base_NN)) do (x, y)
240+
return linearize_index.(Tuple(x)) ==
241+
pattern.(linearize_index.(Tuple(y)))
242+
end
243+
end

0 commit comments

Comments
 (0)