From 0b469c2b702c0ac0b54127ea610bda668d41947c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 6 Dec 2023 21:51:56 +0100 Subject: [PATCH] Fix interference for polynomial_ring constructor (#1519) Co-authored-by: Tommy Hofmann --- Project.toml | 2 +- src/misc/VarNames.jl | 12 ++++++++++-- test/generic/MPoly-test.jl | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 74d1096a41..76b15f87ad 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "AbstractAlgebra" uuid = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" -version = "0.34.3" +version = "0.34.4" [deps] GroupsCore = "d5909c97-4eac-4ecc-a3dc-fdd0858a4120" diff --git a/src/misc/VarNames.jl b/src/misc/VarNames.jl index 6481b976a8..5c618cf310 100644 --- a/src/misc/VarNames.jl +++ b/src/misc/VarNames.jl @@ -142,18 +142,26 @@ reshape_to_varnames(vec::Vector, varnames::VarNames...) = reshape_to_varnames(vec, varnames) function reshape_to_varnames(vec::Vector, varnames::Tuple{Vararg{VarNames}}) iter = Iterators.Stateful(vec) - result = Tuple(_reshape_to_varnames(iter, x) for x in varnames) + result = _unpeel_reshape_to_varnames(iter, varnames) @assert isempty(iter) return result end +function _unpeel_reshape_to_varnames(iter, x::Tuple) + if length(x) === 1 + return (_reshape_to_varnames(iter, x[1]), ) + else + return tuple(_reshape_to_varnames(iter, x[1]), _unpeel_reshape_to_varnames(iter, Base.tail(x))...) + end +end + _reshape_to_varnames(iter::Iterators.Stateful, ::VarName) = popfirst!(iter) _reshape_to_varnames(iter::Iterators.Stateful, a::AbstractArray{<:VarName}) = _reshape(iter, size(a)) _reshape_to_varnames(iter::Iterators.Stateful, (_, shape)::Pair{<:VarName}) = __reshape(iter, shape) -__reshape(iter, axes::Tuple) = _reshape(iter, Int[d for axe in axes for d in size(axe)]) +__reshape(iter, axes::Tuple) = _reshape(iter, ntuple(i -> size(axes[i])[1], length(axes))) __reshape(iter, axe) = _reshape(iter, size(axe)) _reshape(iter, dims) = reshape(collect(Iterators.take(iter, prod(dims))), Tuple(dims)) diff --git a/test/generic/MPoly-test.jl b/test/generic/MPoly-test.jl index 2f06f5825f..2580ada0ad 100644 --- a/test/generic/MPoly-test.jl +++ b/test/generic/MPoly-test.jl @@ -113,10 +113,10 @@ @test y isa Generic.MPoly{Generic.Poly{BigInt}} @test z isa Generic.MPoly{Generic.Poly{BigInt}} - ZZxyz_ = polynomial_ring(ZZ, 'x':'z') - ZZxyz2, xyz2 = polynomial_ring(ZZ, VarName[:x, 'y', GenericString("z")]) - ZZxyz4_ = polynomial_ring(ZZ, Union{String,Char,Symbol}["x", 'y', :z]) - ZZxyz5_ = ZZ["x", 'y', :z] + ZZxyz_ = @inferred polynomial_ring(ZZ, 'x':'z') + ZZxyz2, xyz2 = @inferred polynomial_ring(ZZ, VarName[:x, 'y', GenericString("z")]) + ZZxyz4_ = @inferred polynomial_ring(ZZ, Union{String,Char,Symbol}["x", 'y', :z]) + ZZxyz5_ = @inferred ZZ["x", 'y', :z] ZZxyz6 = @polynomial_ring(ZZ, [:x, :y, :z]) @test ZZxyz_[1] isa Generic.MPolyRing @@ -125,13 +125,13 @@ @test ZZxyz_ == ZZxyz5_ @test ZZxyz_ == (ZZxyz6, [x, y, z]) - ZZxxx0_ = polynomial_ring(ZZ, :x=>Base.OneTo(3)) - ZZxxx_ = polynomial_ring(ZZ, :x=>1:3) + ZZxxx0_ = @inferred polynomial_ring(ZZ, :x=>Base.OneTo(3)) + ZZxxx_ = @inferred polynomial_ring(ZZ, :x=>1:3) @test ZZxxx_[1] isa Generic.MPolyRing @test ZZxxx_ == ZZxxx0_ - QQxxx_ = polynomial_ring(QQ, "x#" => 1:3) + QQxxx_ = @inferred polynomial_ring(QQ, "x#" => 1:3) QQxxx2 = @polynomial_ring(QQ, "x#" => 1:3) @test QQxxx_[1] isa Generic.MPolyRing @@ -140,13 +140,13 @@ QQxxx3 = @polynomial_ring(QQ, :x=>1:3) @test QQxxx_ == (QQxxx3, [x1, x2, x3]) - ZZxy_ = polynomial_ring(ZZ, :x => (1:2, 1:2), :y => 0:3) - ZZxy2_ = polynomial_ring(ZZ, :x => ["1,1" "1,2"; "2,1" "2,2"], :y => (0:3,)) + ZZxy_ = @inferred polynomial_ring(ZZ, :x => (1:2, 1:2), :y => 0:3) + ZZxy2_ = @inferred polynomial_ring(ZZ, :x => ["1,1" "1,2"; "2,1" "2,2"], :y => (0:3,)) @test ZZxy_[1] isa Generic.MPolyRing @test ZZxy_ == ZZxy2_ - QQxy_ = polynomial_ring(QQ, "x#" => (1:2, 1:2), Symbol.(:y, 0:3)) + QQxy_ = @inferred polynomial_ring(QQ, "x#" => (1:2, 1:2), Symbol.(:y, 0:3)) QQxy2 = @polynomial_ring(QQ, "x#" => (1:2, 1:2), Symbol.(:y, 0:3)) @test QQxy_[1] isa Generic.MPolyRing