Skip to content

Commit 6795fc4

Browse files
authored
Support VT("name") where VT::Type{<:Variable} (#137)
Rather than creating a variable with `Variable{name, V, M)`, sometimes it's easier to create one with `Variable{V,M}(name)`. This allows one to create a new variable from an old one with `typeof(oldvar)(newname)`.
1 parent a90376c commit 6795fc4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/var.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ struct Variable{V,M} <: AbstractVariable
118118
name::String
119119
variable_order::V
120120

121+
function Variable{V,M}(name::AbstractString) where {V<:AbstractVariableOrdering,M<:MP.AbstractMonomialOrdering}
122+
return new{V,M}(convert(String, name), instantiate(V))
123+
end
121124
function Variable(
122125
name::AbstractString,
123126
::Type{V},

test/mono.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import MultivariatePolynomials as MP
1515
@test size(u) == (3, 2)
1616
@test x[1] > x[2] > x[3] > y > z[1] > z[2]
1717
@test u[1, 1] > u[2, 1] > u[2, 2]
18+
dummy = VT("dummy")
19+
@test dummy isa VT
20+
@test name(dummy) == "dummy"
1821

1922
@polyvar a[1:5, 1:3, 1:2]
2023
@test size(a) == (5, 3, 2)

0 commit comments

Comments
 (0)