From eee1eb3e0b4bc76fb1b2a348d3e2b895991b31a2 Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Tue, 11 Jul 2023 22:56:06 +0300 Subject: [PATCH] format ome files --- src/arithmetic/QQ.jl | 1 - src/arithmetic/Zp.jl | 1 - src/f4/basis.jl | 3 ++- src/f4/f4.jl | 11 +++++++++-- src/f4/graph.jl | 23 +++++++++++++++------- src/f4/learn-apply.jl | 4 ++-- src/f4/matrix.jl | 37 ++++++++++++++++++++++------------- src/fglm/fglm.jl | 2 +- src/groebner/lucky.jl | 2 +- src/groebner/state.jl | 12 ++++++------ src/monomials/orderings.jl | 5 +---- src/monomials/packedtuples.jl | 21 +++++++++++++++----- src/monomials/sparsevector.jl | 6 +++++- src/utils/invariants.jl | 2 +- src/utils/parameters.jl | 2 +- src/utils/performance.jl | 1 - test/arithmetic/Z_p.jl | 2 -- 17 files changed, 84 insertions(+), 51 deletions(-) diff --git a/src/arithmetic/QQ.jl b/src/arithmetic/QQ.jl index d80c1b30..dba15375 100644 --- a/src/arithmetic/QQ.jl +++ b/src/arithmetic/QQ.jl @@ -4,5 +4,4 @@ abstract type AbstractArithmeticQQ end struct BuiltinArithmeticQQ <: AbstractArithmeticQQ - end diff --git a/src/arithmetic/Zp.jl b/src/arithmetic/Zp.jl index 04a43457..968ccf01 100644 --- a/src/arithmetic/Zp.jl +++ b/src/arithmetic/Zp.jl @@ -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 diff --git a/src/f4/basis.jl b/src/f4/basis.jl index 65729d54..e273901a 100644 --- a/src/f4/basis.jl +++ b/src/f4/basis.jl @@ -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 diff --git a/src/f4/f4.jl b/src/f4/f4.jl index 5d00b008..3a6c142d 100644 --- a/src/f4/f4.jl +++ b/src/f4/f4.jl @@ -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) @@ -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 diff --git a/src/f4/graph.jl b/src/f4/graph.jl index a2b333be..a362373d 100644 --- a/src/f4/graph.jl +++ b/src/f4/graph.jl @@ -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, @@ -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 @@ -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 diff --git a/src/f4/learn-apply.jl b/src/f4/learn-apply.jl index cd66713a..a70b28d7 100644 --- a/src/f4/learn-apply.jl +++ b/src/f4/learn-apply.jl @@ -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), diff --git a/src/f4/matrix.jl b/src/f4/matrix.jl index 8878f489..67f78f0a 100644 --- a/src/f4/matrix.jl +++ b/src/f4/matrix.jl @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/fglm/fglm.jl b/src/fglm/fglm.jl index 4c0f3cb4..9aae256f 100644 --- a/src/fglm/fglm.jl +++ b/src/fglm/fglm.jl @@ -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 diff --git a/src/groebner/lucky.jl b/src/groebner/lucky.jl index 8f0edc4e..d97768e7 100644 --- a/src/groebner/lucky.jl +++ b/src/groebner/lucky.jl @@ -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 diff --git a/src/groebner/state.jl b/src/groebner/state.jl index 576accdc..4cb3cc86 100644 --- a/src/groebner/state.jl +++ b/src/groebner/state.jl @@ -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) diff --git a/src/monomials/orderings.jl b/src/monomials/orderings.jl index a7e26dad..95af3d2d 100644 --- a/src/monomials/orderings.jl +++ b/src/monomials/orderings.jl @@ -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) diff --git a/src/monomials/packedtuples.jl b/src/monomials/packedtuples.jl index c30775cd..076bcb65 100644 --- a/src/monomials/packedtuples.jl +++ b/src/monomials/packedtuples.jl @@ -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` @@ -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 @@ -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 diff --git a/src/monomials/sparsevector.jl b/src/monomials/sparsevector.jl index bd3099e7..5d6c93ea 100644 --- a/src/monomials/sparsevector.jl +++ b/src/monomials/sparsevector.jl @@ -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) diff --git a/src/utils/invariants.jl b/src/utils/invariants.jl index 825f7029..85d98c72 100644 --- a/src/utils/invariants.jl +++ b/src/utils/invariants.jl @@ -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 diff --git a/src/utils/parameters.jl b/src/utils/parameters.jl index 5f6bbf14..2bc3b56e 100644 --- a/src/utils/parameters.jl +++ b/src/utils/parameters.jl @@ -95,7 +95,7 @@ function AlgorithmParameters(ring, kwargs::KeywordsHandler) threading = $threading seed = $seed rng = $rng""" - + AlgorithmParameters( target_ord, computation_ord, diff --git a/src/utils/performance.jl b/src/utils/performance.jl index af528442..0ac62ab6 100644 --- a/src/utils/performance.jl +++ b/src/utils/performance.jl @@ -2,7 +2,6 @@ # TODO: description, # TODO: this is not thread-safe - """ enable_performance_counters(flag) diff --git a/test/arithmetic/Z_p.jl b/test/arithmetic/Z_p.jl index 6bd48d05..46409041 100644 --- a/test/arithmetic/Z_p.jl +++ b/test/arithmetic/Z_p.jl @@ -1,3 +1 @@ # TODO - -