|
64 | 64 |
|
65 | 65 | function graph_polynomial(gp::GraphProblem, ::Val{:finitefield}; usecuda=false,
|
66 | 66 | maxorder=max_size(gp; usecuda=usecuda), max_iter=100)
|
67 |
| - TI = Int32 # Int 32 is faster |
| 67 | + return map(Polynomial, big_integer_solve(T->_polynomial_single(gp, T; usecuda=usecuda, maxorder=maxorder), Int32, max_iter)) |
| 68 | +end |
| 69 | + |
| 70 | +function big_integer_solve(f, ::Type{TI}, max_iter::Int=100) where TI |
68 | 71 | N = typemax(TI)
|
69 |
| - YS = fill(Any[], (fill(bondsize(gp), length(getiyv(gp.code)))...,)) |
70 |
| - local res, respre |
| 72 | + local res, respre, YS |
71 | 73 | for k = 1:max_iter
|
72 | 74 | N = prevprime(N-TI(1))
|
73 |
| - @debug "iteration $k, computing on GP$(N) ..." |
| 75 | + @debug "iteration $k, computing on GP($(N)) ..." |
74 | 76 | T = Mods.Mod{N,TI}
|
75 |
| - rk = _polynomial_single(gp, T; usecuda=usecuda, maxorder=maxorder) |
76 |
| - push!.(YS, rk) |
| 77 | + rk = f(T) |
77 | 78 | if max_iter==1
|
78 |
| - return map(Polynomial, map(x->BigInt.(Mods.value.(x)), YS[1])) |
79 |
| - elseif k != 1 |
80 |
| - res = map(improved_counting, YS) |
81 |
| - all(respre .== res) && return map(Polynomial, res) |
| 79 | + return map(x->BigInt.(Mods.value.(x)), rk) # needs test |
| 80 | + end |
| 81 | + if k != 1 |
| 82 | + push!.(YS, rk) |
| 83 | + res = map(x->improved_counting(x...), YS) |
| 84 | + all(respre .== res) && return res |
82 | 85 | respre = res
|
83 |
| - else |
84 |
| - respre = map(x->BigInt.(value.(x)), YS[1]) |
| 86 | + else # k=1 |
| 87 | + YS = reshape([Any[] for i=1:length(rk)], size(rk)) |
| 88 | + push!.(YS, rk) |
| 89 | + respre = map(x->BigInt.(value.(x)), rk) |
85 | 90 | end
|
86 | 91 | end
|
87 | 92 | @warn "result is potentially inconsistent."
|
88 |
| - return map(Polynomial, res) |
| 93 | + return res |
89 | 94 | end
|
90 | 95 |
|
91 |
| -function improved_counting(sequences) |
92 |
| - map(yi->Mods.CRT(yi...), zip(sequences...)) |
| 96 | +function improved_counting(ys::AbstractArray...) |
| 97 | + map(yi->improved_counting(yi...), zip(ys...)) |
93 | 98 | end
|
| 99 | +improved_counting(ys::Mod...) = Mods.CRT(ys...) |
94 | 100 |
|
95 | 101 | contractx(gp::GraphProblem, x; usecuda=false) = contractf(_->x, gp; usecuda=usecuda)
|
96 | 102 | function contractf(f, gp::GraphProblem; usecuda=false)
|
|
0 commit comments