Skip to content

Commit ae22dfc

Browse files
author
gabe-rbo
committed
fixes fixes fixes
1 parent 379c8c3 commit ae22dfc

24 files changed

Lines changed: 377 additions & 64 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/structure_set.py
2+
# hypothesis_version: 6.151.10
3+
4+
['0', '1', 'Z', 'Z_2']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/core/fundamental_group.py
2+
# hypothesis_version: 6.151.10
3+
4+
[', ']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/integrations/gudhi_bridge.py
2+
# hypothesis_version: 6.151.10
3+
4+
[1e-10, 1e-08, 0.5, 2.0, 'SM', 'birth', 'death', 'dimension', 'f', 'inf', 'recommendation']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/core/k_theory.py
2+
# hypothesis_version: 6.151.10
3+
4+
[]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/wall_groups.py
2+
# hypothesis_version: 6.151.10
3+
4+
['0', '1', 'Z', 'Z_', 'Z_2', '_']
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/core/complexes.py
2+
# hypothesis_version: 6.151.10
3+
4+
[]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: /home/gabriel/Desktop/SurgeryTheory/pysurgery/homeomorphism.py
2+
# hypothesis_version: 6.151.10
3+
4+
[]

fix_assembly_map.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
with open("pysurgery/algebraic_surgery.py", "r") as f:
2+
content = f.read()
3+
4+
new_content = content.replace("return WallGroupL(dimension=self.domain.dimension, pi=pi_1_group).compute_obstruction(self.domain.chain_complex)",
5+
"return WallGroupL(dimension=self.domain.dimension, pi=pi_1_group).compute_obstruction(None)")
6+
7+
with open("pysurgery/algebraic_surgery.py", "w") as f:
8+
f.write(new_content)

fix_julia_ends.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
with open("pysurgery/bridge/surgery_backend.jl", "r") as f:
2+
lines = f.readlines()
3+
4+
out = []
5+
keep = True
6+
for i, line in enumerate(lines):
7+
if "end # module" in line or (line.strip() == "end" and i > 170 and "s_vals =" in lines[i-5:i]):
8+
if "end" in line and "end # module" not in line:
9+
out.append(line)
10+
break
11+
out.append(line)
12+
13+
# Let's be safer: just find the end of abelianize_group, which should be the last function.
14+
out = []
15+
in_abelianize = False
16+
found_end = False
17+
for line in lines:
18+
if "function abelianize_group" in line:
19+
in_abelianize = True
20+
if in_abelianize and line.strip() == "end":
21+
out.append(line)
22+
out.append("\nend # module SurgeryBackend\n")
23+
break
24+
out.append(line)
25+
26+
with open("pysurgery/bridge/surgery_backend.jl", "w") as f:
27+
f.writelines(out)

pysurgery/bridge/surgery_backend.jl

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,41 @@ function exact_sparse_cohomology_basis(
7878
end
7979

8080
dn_mat = sparse(d_n_cols, d_n_rows, d_n_vals, d_n_n, d_n_m)
81-
dense_dn = Matrix{Float64}(dn_mat)
8281

8382
quotient_basis = Vector{Vector{Int64}}()
84-
if size(dense_dn, 2) > 0
83+
if size(dn_mat, 2) > 0
84+
dense_dn = Matrix{Float64}(dn_mat)
8585
curr_rank = rank(dense_dn)
86+
8687
for vec in basis
8788
test_mat = hcat(dense_dn, Float64.(vec))
8889
new_rank = rank(test_mat)
90+
91+
# Additional rigorous integer check
92+
# We append vec to Im(d_n). If it adds no rank, it's a coboundary.
93+
is_indep = false
8994
if new_rank > curr_rank
95+
try
96+
import AbstractAlgebra
97+
ZZ = AbstractAlgebra.ZZ
98+
int_test = AbstractAlgebra.matrix(ZZ, Matrix{Int}(hcat(Matrix(dn_mat), vec)))
99+
snf_test = AbstractAlgebra.snf(int_test)
100+
new_rank_int = count(x -> x != 0, [snf_test[i, i] for i in 1:min(size(int_test)...)])
101+
102+
int_base = AbstractAlgebra.matrix(ZZ, Matrix{Int}(Matrix(dn_mat)))
103+
snf_base = AbstractAlgebra.snf(int_base)
104+
base_rank_int = count(x -> x != 0, [snf_base[i, i] for i in 1:min(size(int_base)...)])
105+
106+
if new_rank_int > base_rank_int
107+
is_indep = true
108+
end
109+
catch
110+
# Fallback to float rank if AbstractAlgebra throws
111+
is_indep = true
112+
end
113+
end
114+
115+
if is_indep
90116
push!(quotient_basis, vec)
91117
dense_dn = test_mat
92118
curr_rank = new_rank
@@ -106,9 +132,12 @@ function group_ring_multiply(k1::Vector{String}, v1::Vector{Int}, k2::Vector{Str
106132
if g_str == "e" || g_str == "1"
107133
return 0
108134
end
135+
m = match(r"g_?(\d+)(?:\^-1)?", g_str)
136+
if m === nothing
137+
throw(ArgumentError("Invalid generator format: " * g_str))
138+
end
139+
val = parse(Int, m.captures[1])
109140
inv = endswith(g_str, "^-1")
110-
base = inv ? replace(g_str[2:end-3], "g" => "") : replace(g_str, "g" => "")
111-
val = parse(Int, base)
112141
return inv ? -val : val
113142
end
114143

@@ -159,38 +188,5 @@ function abelianize_group(generators::Vector{String}, relations::Vector{String})
159188
pow = pow_str === nothing ? 1 : parse(Int, pow_str)
160189
M[i, gen_idx[base_w]] += pow
161190
end
162-
end
163-
end
164-
165-
# SNF on M gives the structure of the abelianized group
166-
U, S, V = svd(Float64.(M))
167-
s_vals = round.(Int, S[S .> 1e-10])
168-
torsion = sort(s_vals[s_vals .> 1])
169-
170-
rank = n_gens - length(s_vals)
171-
return rank, torsion
172-
end
173191

174-
end
175-
s = round.(Int, S[S .> tol])
176-
torsion = sort(s_vals[s_vals .> 1])
177-
178-
rank = n_gens - length(s_vals)
179-
return rank, torsion
180-
end
181-
end
182-
183-
end
184-
end
185-
end
186-
187-
end
188-
s = round.(Int, S[S .> tol])
189-
torsion = sort(s_vals[s_vals .> 1])
190-
191-
rank = n_gens - length(s_vals)
192-
return rank, torsion
193-
end
194-
end
195-
196-
end
192+
end # module SurgeryBackend

0 commit comments

Comments
 (0)