@@ -3,7 +3,7 @@ export polyvecvar
33
44
55function polyarrayvar (:: Type{PV} , prefix, indices... ) where {PV}
6- map (i -> PV (" $(prefix) " * join (i, " _ " ) ), Iterators. product (indices... ))
6+ map (i -> PV (" $(prefix) [ $( join (i, " , " )) ] " ), Iterators. product (indices... ))
77end
88
99function buildpolyvar (:: Type{PV} , var) where {PV}
4343
4444struct PolyVar{C} <: AbstractVariable
4545 id:: Int
46- name:: AbstractString
46+ name:: String
47+
4748 function PolyVar {C} (name:: AbstractString ) where {C}
4849 # gensym returns something like Symbol("##42")
4950 # we first remove "##" and then parse it into an Int
5051 id = parse (Int, string (gensym ())[3 : end ])
51- new (id, name)
52+ new (id, convert (String, name) )
5253 end
5354end
5455
5556Base. hash (x:: PolyVar , u:: UInt ) = hash (x. id, u)
5657Base. broadcastable (x:: PolyVar ) = Ref (x)
5758
5859MP. name (v:: PolyVar ) = v. name
60+ function MP. name_base_indices (v:: PolyVar )
61+ splits = split (v. name, r" [\[ ,\] ]\s *" , keepempty= false )
62+ if length (splits) == 1
63+ return v. name, Int[]
64+ else
65+ return splits[1 ], parse .(Int, splits[2 : end ])
66+ end
67+ end
68+
5969MP. monomial (v:: PolyVar ) = Monomial (v)
6070_vars (v:: PolyVar ) = [v]
6171
0 commit comments