Skip to content

Commit

Permalink
Fix interference for polynomial_ring constructor (#1519)
Browse files Browse the repository at this point in the history
Co-authored-by: Tommy Hofmann <[email protected]>
  • Loading branch information
lgoettgens and thofma authored Dec 6, 2023
1 parent 8fe5835 commit 0b469c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 10 additions & 2 deletions src/misc/VarNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions test/generic/MPoly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

2 comments on commit 0b469c2

@fingolfin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96649

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.34.4 -m "<description of version>" 0b469c2b702c0ac0b54127ea610bda668d41947c
git push origin v0.34.4

Please sign in to comment.