Skip to content

Commit 75f4fa5

Browse files
authored
better polynomial interface (#54)
* fix polynomial * update polynomial API * bump version
1 parent 9dd1255 commit 75f4fa5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GenericTensorNetworks"
22
uuid = "3521c873-ad32-4bb4-b63d-f4f178f42b49"
33
authors = ["GiggleLiu <[email protected]> and contributors"]
4-
version = "1.2.1"
4+
version = "1.2.2"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/graph_polynomials.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ function graph_polynomial(gp::GraphProblem, ::Val{:laurent}; usecuda=false, T=Fl
5353
contractx(gp::GraphProblem, LaurentPolynomial(T[1], 1))
5454
end
5555

56-
function _polynomial_single(gp::GraphProblem, ::Type{T}; usecuda, maxorder) where T
56+
function _polynomial_fit(f, ::Type{T}; maxorder) where T
5757
xs = 0:maxorder
58-
ys = [Array(contractx(gp, T(x); usecuda=usecuda)) for x in xs] # download to CPU
58+
ys = [f(T(x)) for x in xs] # download to CPU
5959
res = fill(T[], size(ys[1])) # contraction result can be a tensor
6060
for ci in 1:length(ys[1])
6161
A = zeros(T, maxorder+1, maxorder+1)
@@ -68,9 +68,10 @@ function _polynomial_single(gp::GraphProblem, ::Type{T}; usecuda, maxorder) wher
6868
end
6969

7070
# T is not used in finitefield approach
71-
function graph_polynomial(gp::GraphProblem, ::Val{:finitefield}; usecuda=false, T=Float64,
72-
maxorder=max_size(gp; usecuda=usecuda), max_iter=100)
73-
return map(Polynomial, big_integer_solve(T->_polynomial_single(gp, T; usecuda=usecuda, maxorder=maxorder), Int32, max_iter))
71+
function graph_polynomial(gp::GraphProblem, ::Val{:finitefield}; usecuda=false, T=BigInt,
72+
maxorder=max_size(gp; usecuda), max_iter=100)
73+
f = T->_polynomial_fit(x->Array(contractx(gp, x; usecuda)), T; maxorder)
74+
return map(Polynomial, big_integer_solve(f, Int32, max_iter))
7475
end
7576

7677
function big_integer_solve(f, ::Type{TI}, max_iter::Int=100) where TI
@@ -102,4 +103,4 @@ end
102103
function improved_counting(ys::AbstractArray...)
103104
map(yi->improved_counting(yi...), zip(ys...))
104105
end
105-
improved_counting(ys::Mod...) = Mods.CRT(ys...)
106+
improved_counting(ys::Mod...) = Mods.CRT(ys...)

0 commit comments

Comments
 (0)