Skip to content

Commit

Permalink
Support VT("name") where VT::Type{<:Variable} (#137)
Browse files Browse the repository at this point in the history
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)`.
  • Loading branch information
timholy authored Jul 12, 2023
1 parent a90376c commit 6795fc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/var.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ struct Variable{V,M} <: AbstractVariable
name::String
variable_order::V

function Variable{V,M}(name::AbstractString) where {V<:AbstractVariableOrdering,M<:MP.AbstractMonomialOrdering}
return new{V,M}(convert(String, name), instantiate(V))
end
function Variable(
name::AbstractString,
::Type{V},
Expand Down
3 changes: 3 additions & 0 deletions test/mono.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import MultivariatePolynomials as MP
@test size(u) == (3, 2)
@test x[1] > x[2] > x[3] > y > z[1] > z[2]
@test u[1, 1] > u[2, 1] > u[2, 2]
dummy = VT("dummy")
@test dummy isa VT
@test name(dummy) == "dummy"

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

0 comments on commit 6795fc4

Please sign in to comment.