Skip to content

Commit

Permalink
format ome files
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jul 11, 2023
1 parent 9b26b27 commit eee1eb3
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 51 deletions.
1 change: 0 additions & 1 deletion src/arithmetic/QQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
abstract type AbstractArithmeticQQ end

struct BuiltinArithmeticQQ <: AbstractArithmeticQQ

end
1 change: 0 additions & 1 deletion src/arithmetic/Zp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ end
a - (x >>> mod.shift) * mod.divisor
end


function select_arithmetic(coeffs::Vector{Vector{T}}, ch) where {T <: CoeffFF}
SpecializedBuiltinArithmeticZp(convert(T, ch))
end
Expand Down
3 changes: 2 additions & 1 deletion src/f4/basis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ function is_redundant!(
# add new S-pair corresponding to Spoly(i, idx)
lcm_new = get_lcm(lead_i, lead_new, ht, ht)
psidx = pairset.load + 1
ps[psidx] = SPair{pt}(Int32(i), Int32(idx), lcm_new, pt(ht.hashdata[lcm_new].deg))
ps[psidx] =
SPair{pt}(Int32(i), Int32(idx), lcm_new, pt(ht.hashdata[lcm_new].deg))

# mark redundant
basis.isredundant[idx] = true
Expand Down
11 changes: 9 additions & 2 deletions src/f4/f4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ function select_normal!(
end
end

@log level=-4 "Selected $(npairs) pairs in select_normal!"
@log level = -4 "Selected $(npairs) pairs in select_normal!"

reinitialize_matrix!(matrix, npairs)

Expand Down Expand Up @@ -808,7 +808,14 @@ function f4!(
# if the iteration is redundant according to the previous modular run
if isready(tracer)
if is_iteration_redundant(tracer, i)
discard_normal!(pairset, basis, matrix, hashtable, symbol_ht, maxpairs=params.maxpairs)
discard_normal!(
pairset,
basis,
matrix,
hashtable,
symbol_ht,
maxpairs=params.maxpairs
)
matrix = initialize_matrix(ring, C)
symbol_ht = initialize_secondary_hashtable(hashtable)
continue
Expand Down
23 changes: 16 additions & 7 deletions src/f4/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ mutable struct ComputationGraphF4{C, M, Ord}
# matrix_columns::Vector{Vector{Int}}
end

function initialize_computation_graph_f4(ring, input_basis, gb_basis, hashtable, permutation)
function initialize_computation_graph_f4(
ring,
input_basis,
gb_basis,
hashtable,
permutation
)
ComputationGraphF4(
ring,
input_basis,
Expand All @@ -41,13 +47,13 @@ function initialize_computation_graph_f4(ring, input_basis, gb_basis, hashtable,
Vector{Tuple{Vector{Int}, Vector{MonomIdx}}}(),
Vector{Int}(),
Vector{Int}(),
Vector{Int}(),
Vector{Int}()
# Vector{Tuple{Vector{Int}, Vector{MonomIdx}}}(),
# Vector{Tuple{Vector{Int}, Vector{MonomIdx}}}(),
)
end

function finalize_graph!(graph::ComputationGraphF4)
function finalize_graph!(graph::ComputationGraphF4)
# TODO: trim sizes
graph.buf_basis = deepcopy_basis(graph.gb_basis)
graph.buf_basis.nnonredundant = graph.input_basis.nnonredundant
Expand All @@ -66,8 +72,11 @@ function Base.show(io::IO, ::MIME"text/plain", graph::ComputationGraphF4)
# TODO
total_matrix_up_rows_useful = sum(length first, graph.matrix_upper_rows)
total_matrix_low_rows_useful = sum(length first, graph.matrix_lower_rows)
println(io, """
Total iterations: $(total_iterations)
Total upper matrix rows: $(total_matrix_up_rows) ($(round(total_matrix_up_rows_useful / total_matrix_up_rows * 100, digits=2)) % are useful)
Total lower matrix rows: $(total_matrix_low_rows) ($(round(total_matrix_low_rows_useful / total_matrix_low_rows * 100, digits=2)) % are useful)""")
println(
io,
"""
Total iterations: $(total_iterations)
Total upper matrix rows: $(total_matrix_up_rows) ($(round(total_matrix_up_rows_useful / total_matrix_up_rows * 100, digits=2)) % are useful)
Total lower matrix rows: $(total_matrix_low_rows) ($(round(total_matrix_low_rows_useful / total_matrix_low_rows * 100, digits=2)) % are useful)"""
)
end
4 changes: 2 additions & 2 deletions src/f4/learn-apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ function f4_learn!(
# While there are pairs to be reduced
while !isempty(pairset)
i += 1
@log level=-3 "F4: iteration $i"
@log level=-3 "F4: available $(pairset.load) pairs"
@log level = -3 "F4: iteration $i"
@log level = -3 "F4: available $(pairset.load) pairs"

# selects pairs for reduction from pairset following normal strategy
# (minimal lcm degrees are selected),
Expand Down
37 changes: 23 additions & 14 deletions src/f4/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,20 @@ function interreduce_lower_part_learn!(
end

useful_reducers_sorted = sort(collect(useful_reducers))
@log level=-6 "" useful_reducers_sorted
@log level = -6 "" useful_reducers_sorted
push!(graph.matrix_infos, (nup=matrix.nup, nlow=matrix.nlow, ncols=matrix.ncols))
push!(graph.matrix_nonzeroed_rows, not_reduced_to_zero)
# push!(graph.matrix_upper_rows, (matrix.up2coef, matrix.up2mult))
# push!(graph.matrix_lower_rows, (matrix.low2coef, matrix.low2mult))
push!(graph.matrix_upper_rows, (matrix.up2coef[1:matrix.nup], matrix.up2mult[1:matrix.nup]))
push!(
graph.matrix_upper_rows,
(matrix.up2coef[1:(matrix.nup)], matrix.up2mult[1:(matrix.nup)])
)
# push!(graph.matrix_lower_rows, (rowidx2coef, matrix.low2mult))
# push!(graph.matrix_upper_rows, (map(first, useful_reducers_sorted), map(last, useful_reducers_sorted)))
push!(graph.matrix_lower_rows, (Int[], Int[]))
# push!(graph.matrix_lower_rows, (matrix.low2coef[not_reduced_to_zero], matrix.low2mult[not_reduced_to_zero]))

# TODO: we should learn and not reduce redundant elements in the first place!

# shrink matrix
Expand Down Expand Up @@ -722,7 +725,7 @@ function learn_sparse_rref!(
# no copy
# YES
pivs, l2c_tmp = absolute_pivots!(matrix)
@log level=-6 "absolute_pivots!" pivs l2c_tmp
@log level = -6 "absolute_pivots!" pivs l2c_tmp

rowidx2coef = matrix.low2coef
matrix.low2coef = l2c_tmp
Expand All @@ -735,7 +738,7 @@ function learn_sparse_rref!(
not_reduced_to_zero = Int[]
useful_reducers = Set{Any}()

@log level=-6 "Low to coef" rowidx2coef matrix.low2mult
@log level = -6 "Low to coef" rowidx2coef matrix.low2mult

@inbounds for i in 1:nlow
# select next row to be reduced
Expand All @@ -746,7 +749,7 @@ function learn_sparse_rref!(
# (no need to copy here)
cfsref = basis.coeffs[rowidx2coef[i]]

@log level=-7 "$i from $nlow" rowexps cfsref rowidx2coef
@log level = -7 "$i from $nlow" rowexps cfsref rowidx2coef

# we load coefficients into dense array
# into rowexps indices
Expand Down Expand Up @@ -777,7 +780,7 @@ function learn_sparse_rref!(
push!(useful_reducers, rr)
end

@log level=-7 "Not zero" i rowidx2coef[i] matrix.low2mult[i]
@log level = -7 "Not zero" i rowidx2coef[i] matrix.low2mult[i]

# matrix coeffs sparsely stores coefficients of new row
matrix.coeffs[i] = newcfs
Expand All @@ -791,16 +794,22 @@ function learn_sparse_rref!(
# normalize if needed
normalize_sparse_row!(matrix.coeffs[i], arithmetic)
end

# TODO
useful_reducers_sorted = sort(collect(useful_reducers))
@log level=-7 "" useful_reducers_sorted
@log level = -7 "" useful_reducers_sorted
push!(graph.matrix_infos, (nup=matrix.nup, nlow=matrix.nlow, ncols=matrix.ncols))
push!(graph.matrix_nonzeroed_rows, not_reduced_to_zero)
# push!(graph.matrix_upper_rows, (matrix.up2coef, matrix.up2mult))
# push!(graph.matrix_lower_rows, (rowidx2coef, matrix.low2mult))
push!(graph.matrix_upper_rows, (map(first, useful_reducers_sorted), map(last, useful_reducers_sorted)))
push!(graph.matrix_lower_rows, (rowidx2coef[not_reduced_to_zero], matrix.low2mult[not_reduced_to_zero]))
push!(
graph.matrix_upper_rows,
(map(first, useful_reducers_sorted), map(last, useful_reducers_sorted))
)
push!(
graph.matrix_lower_rows,
(rowidx2coef[not_reduced_to_zero], matrix.low2mult[not_reduced_to_zero])
)

interreduce_lower_part!(matrix, basis, pivs, arithmetic)
true
Expand All @@ -822,7 +831,7 @@ function apply_sparse_rref!(
# no copy
# YES
pivs, l2c_tmp = absolute_pivots!(matrix)
@log level=-7 "absolute_pivots!" pivs l2c_tmp
@log level = -7 "absolute_pivots!" pivs l2c_tmp

rowidx2coef = matrix.low2coef
matrix.low2coef = l2c_tmp
Expand All @@ -843,7 +852,7 @@ function apply_sparse_rref!(
# (no need to copy here)
cfsref = basis.coeffs[rowidx2coef[i]]

@log level=-7 "$i from $nlow" rowexps cfsref rowidx2coef
@log level = -7 "$i from $nlow" rowexps cfsref rowidx2coef

# we load coefficients into dense array
# into rowexps indices
Expand All @@ -866,7 +875,7 @@ function apply_sparse_rref!(
# then something has gone wrong in tracing
return false
end

push!(not_reduced_to_zero, i)

# matrix coeffs sparsely stores coefficients of new row
Expand Down
2 changes: 1 addition & 1 deletion src/fglm/fglm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function _kbase(polynomials, kws)
ring, monoms, coeffs = convert_to_internal(representation, polynomials, kws)
params = AlgorithmParameters(ring, kws)
if isempty(monoms)
@log level=-2 "Input consisting of zero polynomials."
@log level = -2 "Input consisting of zero polynomials."
throw(DomainError("Input consisting of zero polynomials to Groebner.kbase."))
return convert_to_output(ring, polynomials, monoms, coeffs, params)
end
Expand Down
2 changes: 1 addition & 1 deletion src/groebner/lucky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
# Check if the prime is lucky w.r.t. input basis coefficients -- does not divide
# any of the leading coefficients
function isluckyprime(lucky::LuckyPrimes, prime::UInt64)
@log level=-3 "Checking if $prime is lucky.."
@log level = -3 "Checking if $prime is lucky.."
buf = lucky.buf
p = BigInt(prime)
for poly in lucky.coeffs
Expand Down
12 changes: 6 additions & 6 deletions src/groebner/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ end
# Returns true is the reconstrction is successfull, false otherwise.
function rational_reconstruct!(state::GroebnerState, lucky::LuckyPrimes)
modulo = lucky.modulo
buffer = state.buffer
bnd = rational_reconstruction_bound(modulo)
buf, buf1 = buffer.reconstructbuf1, buffer.reconstructbuf2
buffer = state.buffer
bnd = rational_reconstruction_bound(modulo)
buf, buf1 = buffer.reconstructbuf1, buffer.reconstructbuf2
buf2, buf3 = buffer.reconstructbuf3, buffer.reconstructbuf4
u1, u2 = buffer.reconstructbuf5, buffer.reconstructbuf6
u3, v1 = buffer.reconstructbuf7, buffer.reconstructbuf8
v2, v3 = buffer.reconstructbuf9, buffer.reconstructbuf10
u1, u2 = buffer.reconstructbuf5, buffer.reconstructbuf6
u3, v1 = buffer.reconstructbuf7, buffer.reconstructbuf8
v2, v3 = buffer.reconstructbuf9, buffer.reconstructbuf10
gb_coeffs_zz = state.gb_coeffs_zz
gb_coeffs_qq = state.gb_coeffs_qq
@invariant length(gb_coeffs_zz) == length(gb_coeffs_qq)
Expand Down
5 changes: 1 addition & 4 deletions src/monomials/orderings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ groebner([x*y + x, x + y^2], ordering=ord)
struct WeightedOrdering{T} <: AbstractMonomialOrdering
weights::Vector{UInt64}
variables::Vector{T}
function WeightedOrdering(
weights::AbstractVector,
variables
)
function WeightedOrdering(weights::AbstractVector, variables)
@assert !isempty(weights)
@assert all(>=(0), weights) "Only nonnegative weights are supported."
# @assert length(weights) == length(variables)
Expand Down
21 changes: 16 additions & 5 deletions src/monomials/packedtuples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ for (op, n) in _defined_packed_pairs

# define `max_vars_in_monom`
@eval begin
max_vars_in_monom(::Type{$op{T, B}}) where {T, B} = $n * div(sizeof(T), sizeof(B)) - 1
max_vars_in_monom(::Type{$op{T, B}}) where {T, B} =
$n * div(sizeof(T), sizeof(B)) - 1
end

# define `totaldeg`
Expand Down Expand Up @@ -222,7 +223,8 @@ function monom_to_dense_vector!(tmp::Vector{I}, pv::PackedTuple2{T, B}) where {I
end
function monom_to_dense_vector!(tmp::Vector{I}, pv::PackedTuple3{T, B}) where {I, T, B}
epc = elperchunk(T, B)
(length(tmp) < 2 * epc) && return monom_to_dense_vector!(tmp, PackedTuple2{T, B}(pv.a1, pv.a2))
(length(tmp) < 2 * epc) &&
return monom_to_dense_vector!(tmp, PackedTuple2{T, B}(pv.a1, pv.a2))
indent = 0
packedunpack!(tmp, pv.a3, B, indent)
indent = 0
Expand Down Expand Up @@ -527,13 +529,22 @@ function is_monom_divisible!(
ans, e
end

function is_monom_elementwise_eq(ea::PackedTuple1{T, B}, eb::PackedTuple1{T, B}) where {T, B}
function is_monom_elementwise_eq(
ea::PackedTuple1{T, B},
eb::PackedTuple1{T, B}
) where {T, B}
ea.a1 == eb.a1
end
function is_monom_elementwise_eq(ea::PackedTuple2{T, B}, eb::PackedTuple2{T, B}) where {T, B}
function is_monom_elementwise_eq(
ea::PackedTuple2{T, B},
eb::PackedTuple2{T, B}
) where {T, B}
ea.a1 == eb.a1 && ea.a2 == eb.a2
end
function is_monom_elementwise_eq(ea::PackedTuple3{T, B}, eb::PackedTuple3{T, B}) where {T, B}
function is_monom_elementwise_eq(
ea::PackedTuple3{T, B},
eb::PackedTuple3{T, B}
) where {T, B}
ea.a1 == eb.a1 && ea.a2 == eb.a2 && ea.a3 == eb.a3
end

Expand Down
6 changes: 5 additions & 1 deletion src/monomials/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ end

# Returns the lcm of monomials ea and eb.
# Also writes the result to ec.
function monom_lcm!(ec::ExponentVector{T}, ea::ExponentVector{T}, eb::ExponentVector{T}) where {T}
function monom_lcm!(
ec::ExponentVector{T},
ea::ExponentVector{T},
eb::ExponentVector{T}
) where {T}
@assert length(ec) == length(ea) == length(eb)
@inbounds ec[1] = zero(T)
@inbounds for i in 2:length(ec)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/invariants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Check that expr evaluates to `true` at runtime. If not, throw an
@invariant 1 > 2 # throws!
```
"""
macro invariant(arg)
macro invariant(arg)
esc(:(
if $(@__MODULE__).invariants_enabled()
@assert $arg
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function AlgorithmParameters(ring, kwargs::KeywordsHandler)
threading = $threading
seed = $seed
rng = $rng"""

AlgorithmParameters(
target_ord,
computation_ord,
Expand Down
1 change: 0 additions & 1 deletion src/utils/performance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# TODO: description,
# TODO: this is not thread-safe


"""
enable_performance_counters(flag)
Expand Down
2 changes: 0 additions & 2 deletions test/arithmetic/Z_p.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# TODO


0 comments on commit eee1eb3

Please sign in to comment.