@@ -3,7 +3,7 @@ export polyvecvar
3
3
4
4
5
5
function 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... ))
7
7
end
8
8
9
9
function buildpolyvar (:: Type{PV} , var) where {PV}
43
43
44
44
struct PolyVar{C} <: AbstractVariable
45
45
id:: Int
46
- name:: AbstractString
46
+ name:: String
47
+
47
48
function PolyVar {C} (name:: AbstractString ) where {C}
48
49
# gensym returns something like Symbol("##42")
49
50
# we first remove "##" and then parse it into an Int
50
51
id = parse (Int, string (gensym ())[3 : end ])
51
- new (id, name)
52
+ new (id, convert (String, name) )
52
53
end
53
54
end
54
55
55
56
Base. hash (x:: PolyVar , u:: UInt ) = hash (x. id, u)
56
57
Base. broadcastable (x:: PolyVar ) = Ref (x)
57
58
58
59
MP. 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
+
59
69
MP. monomial (v:: PolyVar ) = Monomial (v)
60
70
_vars (v:: PolyVar ) = [v]
61
71
0 commit comments