Skip to content

Commit 22e7672

Browse files
committed
More type widening for robustness
1 parent 28f7be9 commit 22e7672

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/minimization.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function find_transformation_matrix(t::SVector{D,T}) where {D,T}
316316
elseif D == 2
317317
push!(images, SA[one(T), zero(T)], SA[zero(T), one(T)])
318318
n += 2
319-
transformation2 = zero(MMatrix{2,2,T,4})
319+
transformation2 = zero(T == Rational{BigInt} ? SizedMatrix{2,2,T,2,Matrix{T}} : MMatrix{2,2,T,4})
320320
mindet2 = (typemax(Int)-1)//1
321321
best2 = (0,0)
322322
for i in 1:(n-1)
@@ -336,7 +336,7 @@ function find_transformation_matrix(t::SVector{D,T}) where {D,T}
336336
oT = one(T); zT = zero(T)
337337
push!(images, SA[oT, zT, zT], SA[zT, oT, zT], SA[zT, zT, oT])
338338
n += 3
339-
transformation3 = zero(MMatrix{3,3,T,9})
339+
transformation3 = zero(T == Rational{BigInt} ? SizedMatrix{3,3,T,2,Matrix{T}} : MMatrix{3,3,T,9})
340340
mindet3 = (typemax(Int)-1)//1
341341
best3 = (0,0,0)
342342
for i in 1:(n-1)
@@ -872,13 +872,13 @@ function reduce_with_matrix(c::Crystal{Nothing}, _mat)
872872
cell = Cell(c.pge.cell, c.pge.cell.mat * mat)
873873

874874
imat = round.(Int, inv(mat)) # The inverse should only have integer coefficients
875-
poscol = (imat,) .* c.pge.pos # position in the new reference, will be in [0,1)
875+
poscol = [imat * round.(x; digits=12) for x in c.pge.pos] # position in the new reference, will be in [0,1)
876876
n = length(poscol)
877877
offset = Vector{SVector{D,Int}}(undef, n) # offsets in the new reference
878878
for (i, pos) in enumerate(poscol)
879879
ofs = floor.(Int, pos)
880880
offset[i] = ofs
881-
poscol[i] = pos .- ofs
881+
poscol[i] = round.(pos .- ofs; digits=12)
882882
end
883883
I_sort = sort(1:n; by=i->(poscol[i], hash_position(offset[i])))
884884
_i = popfirst!(I_sort)

src/stability.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ function candidate_key_unstable(net::CrystalNet{D,T}, shrunk_candidate, u_s, bas
320320
n = nv(net.pge.g)
321321
newpos_s, offsets_s, vmap_s = shrunk_candidate
322322

323-
newpos = Vector{SVector{D,T}}(undef, n) # positions of the kept representatives
323+
newpos = Vector{SVector{D,widen(T)}}(undef, n) # positions of the kept representatives
324324
offsets = Vector{SVector{D,Int32}}(undef, n) # offsets of the new representatives w.r.t. the original one, in the original basis
325325
vmap = Vector{Int}(undef, n) # bijection from the old to the new node number
326326
rev_vmap = Vector{Int}(undef, n)
@@ -346,9 +346,9 @@ function candidate_key_unstable(net::CrystalNet{D,T}, shrunk_candidate, u_s, bas
346346

347347
u = u_s first_collision_m1 ? u_s : first(collision_ranges[u_s - first_collision_m1])
348348
origin = net.pge.pos[u]
349-
edgs = Tuple{Int,Int,SVector{D,T}}[]
349+
edgs = Tuple{Int,Int,SVector{D,widen(T)}}[]
350350
bigbasis = T == Rational{BigInt} ? basis : widen(T).(basis)
351-
mat = T == Rational{BigInt} ? inv(bigbasis) : T.(inv(bigbasis))
351+
mat = T == Rational{BigInt} ? inv(bigbasis) : widen(T).(inv(bigbasis))
352352
for t in 1:n # t is the node being processed
353353
neighs = neighbors(net.pge.g, vmap[t])
354354
ofst = offsets[t]

0 commit comments

Comments
 (0)