Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MPSKitModels"
uuid = "ca635005-6f8c-4cd1-b51d-8491250ef2ab"
authors = ["Maarten Van Damme", "Lukas Devos", "Gertian Roose", "Klaas Gunst"]
version = "0.4.2"
version = "0.4.3"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
13 changes: 11 additions & 2 deletions src/lattices/snakepattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@

SnakePattern(lattice) = SnakePattern(lattice, identity)

Base.axes(lattice::SnakePattern) = axes(lattice.lattice)
Base.isfinite(::Type{SnakePattern{N,G}}) where {N,G} = isfinite(G)

Check warning on line 14 in src/lattices/snakepattern.jl

View check run for this annotation

Codecov / codecov/patch

src/lattices/snakepattern.jl#L14

Added line #L14 was not covered by tests

function linearize_index(snake::SnakePattern, i...)
return snake.pattern(linearize_index(snake.lattice, i...))
end

vertices(snake::SnakePattern) = vertices(snake.lattice)
nearest_neighbours(snake::SnakePattern) = nearest_neighbours(snake.lattice)
function vertices(snake::SnakePattern)
return map(x -> LatticePoint(x.coordinates, snake), vertices(snake.lattice))
end
function nearest_neighbours(snake::SnakePattern)
return map(nearest_neighbours(snake.lattice)) do (x, y)
return LatticePoint(x.coordinates, snake), LatticePoint(y.coordinates, snake)
end
end
bipartition(snake::SnakePattern) = bipartition(snake.lattice)

"""
Expand Down
40 changes: 40 additions & 0 deletions test/lattices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,43 @@ end
@test allunique(NNN)
end
end

@testset "SnakePattern" begin
base_lattice = FiniteCylinder(4, 16)
base_V = vertices(base_lattice)
base_NN = nearest_neighbours(base_lattice)

lattice = SnakePattern(base_lattice, identity)

V = vertices(lattice)
@test all(zip(V, base_V)) do (x, y)
return linearize_index(x) == linearize_index(y)
end

@test length(base_lattice) == length(lattice)
@test lattice[1, 1] == first(V)

NN = nearest_neighbours(lattice)
@test all(zip(NN, base_NN)) do (x, y)
return linearize_index.(Tuple(x)) ==
linearize_index.(Tuple(y))
end

pattern(i) = length(lattice) - i + 1
lattice = SnakePattern(base_lattice, pattern)

V = vertices(lattice)
@test all(zip(V, base_V)) do (x, y)
return linearize_index(x) == pattern(linearize_index(y))
end

@test length(base_lattice) == length(lattice)
@test lattice[1, 1] == first(V)

base_NN = nearest_neighbours(base_lattice)
NN = nearest_neighbours(lattice)
@test all(zip(NN, base_NN)) do (x, y)
return linearize_index.(Tuple(x)) ==
pattern.(linearize_index.(Tuple(y)))
end
end
Loading