-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
505 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,99 @@ | ||
module SpinGlassNetworks | ||
using LabelledGraphs | ||
using LightGraphs | ||
using MetaGraphs # TODO: remove that | ||
using CSV | ||
using DocStringExtensions | ||
using LinearAlgebra | ||
using Base.Cartesian | ||
using LabelledGraphs | ||
using LightGraphs | ||
using MetaGraphs # TODO: remove that | ||
using CSV | ||
using DocStringExtensions | ||
using LinearAlgebra | ||
using Base.Cartesian | ||
|
||
import Base.Prehashed | ||
import Base.Prehashed | ||
|
||
export unique_neighbors | ||
export unique_neighbors | ||
|
||
|
||
unique_neighbors(ig::LabelledGraph, i::Int) = filter(j -> j > i, neighbors(ig, i)) | ||
unique_neighbors(ig::LabelledGraph, i::Int) = filter(j -> j > i, neighbors(ig, i)) | ||
|
||
@generated function unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} | ||
quote | ||
1 <= dim <= $N || return copy(A) | ||
hashes = zeros(UInt, axes(A, dim)) | ||
@generated function unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N} | ||
quote | ||
1 <= dim <= $N || return copy(A) | ||
hashes = zeros(UInt, axes(A, dim)) | ||
|
||
# Compute hash for each row | ||
k = 0 | ||
@nloops $N i A d->(if d == dim; k = i_d; end) begin | ||
@inbounds hashes[k] = hash(hashes[k], hash((@nref $N A i))) | ||
# Compute hash for each row | ||
k = 0 | ||
@nloops $N i A d -> ( | ||
if d == dim | ||
k = i_d | ||
end | ||
) begin | ||
@inbounds hashes[k] = hash(hashes[k], hash((@nref $N A i))) | ||
end | ||
|
||
# Collect index of first row for each hash | ||
uniquerow = similar(Array{Int}, axes(A, dim)) | ||
firstrow = Dict{Prehashed,Int}() | ||
for k = axes(A, dim) | ||
uniquerow[k] = get!(firstrow, Prehashed(hashes[k]), k) | ||
end | ||
uniquerows = collect(values(firstrow)) | ||
# Collect index of first row for each hash | ||
uniquerow = similar(Array{Int}, axes(A, dim)) | ||
firstrow = Dict{Prehashed,Int}() | ||
for k in axes(A, dim) | ||
uniquerow[k] = get!(firstrow, Prehashed(hashes[k]), k) | ||
end | ||
uniquerows = collect(values(firstrow)) | ||
|
||
# Check for collisions | ||
collided = falses(axes(A, dim)) | ||
@inbounds begin | ||
@nloops $N i A d->(if d == dim | ||
# Check for collisions | ||
collided = falses(axes(A, dim)) | ||
@inbounds begin | ||
@nloops $N i A d -> ( | ||
if d == dim | ||
k = i_d | ||
j_d = uniquerow[k] | ||
else | ||
j_d = i_d | ||
end) begin | ||
if (@nref $N A j) != (@nref $N A i) | ||
collided[k] = true | ||
end | ||
end | ||
) begin | ||
if (@nref $N A j) != (@nref $N A i) | ||
collided[k] = true | ||
end | ||
end | ||
end | ||
|
||
if any(collided) | ||
nowcollided = similar(BitArray, axes(A, dim)) | ||
while any(collided) | ||
# Collect index of first row for each collided hash | ||
empty!(firstrow) | ||
for j = axes(A, dim) | ||
collided[j] || continue | ||
uniquerow[j] = get!(firstrow, Prehashed(hashes[j]), j) | ||
end | ||
for v ∈ values(firstrow) | ||
push!(uniquerows, v) | ||
end | ||
if any(collided) | ||
nowcollided = similar(BitArray, axes(A, dim)) | ||
while any(collided) | ||
# Collect index of first row for each collided hash | ||
empty!(firstrow) | ||
for j in axes(A, dim) | ||
collided[j] || continue | ||
uniquerow[j] = get!(firstrow, Prehashed(hashes[j]), j) | ||
end | ||
for v ∈ values(firstrow) | ||
push!(uniquerows, v) | ||
end | ||
|
||
# Check for collisions | ||
fill!(nowcollided, false) | ||
@nloops $N i A d->begin | ||
if d == dim | ||
k = i_d | ||
j_d = uniquerow[k] | ||
(!collided[k] || j_d == k) && continue | ||
else | ||
j_d = i_d | ||
end | ||
end begin | ||
if (@nref $N A j) != (@nref $N A i) | ||
nowcollided[k] = true | ||
end | ||
# Check for collisions | ||
fill!(nowcollided, false) | ||
@nloops $N i A d -> begin | ||
if d == dim | ||
k = i_d | ||
j_d = uniquerow[k] | ||
(!collided[k] || j_d == k) && continue | ||
else | ||
j_d = i_d | ||
end | ||
end begin | ||
if (@nref $N A j) != (@nref $N A i) | ||
nowcollided[k] = true | ||
end | ||
(collided, nowcollided) = (nowcollided, collided) | ||
end | ||
(collided, nowcollided) = (nowcollided, collided) | ||
end | ||
|
||
(@nref $N A d->d == dim ? sort!(uniquerows) : (axes(A, d))), indexin(uniquerow, uniquerows) | ||
end | ||
|
||
(@nref $N A d -> d == dim ? sort!(uniquerows) : (axes(A, d))), | ||
indexin(uniquerow, uniquerows) | ||
end | ||
end | ||
|
||
include("states.jl") | ||
include("ising.jl") | ||
include("spectrum.jl") | ||
include("lattice.jl") | ||
include("factor.jl") | ||
include("states.jl") | ||
include("ising.jl") | ||
include("spectrum.jl") | ||
include("lattice.jl") | ||
include("factor.jl") | ||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.