Skip to content

Commit 9ab9df3

Browse files
allow any indices
1 parent 1d38a4f commit 9ab9df3

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/variables.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
export Variable, @variables, @parameters
22

3-
const IndexMap = Dict{Int,Char}(
4-
0 => '',
5-
1 => '',
6-
2 => '',
7-
3 => '',
8-
4 => '',
9-
5 => '',
10-
6 => '',
11-
7 => '',
12-
8 => '',
13-
9 => '')
3+
const IndexMap = Dict{Char,Char}(
4+
'0' => '',
5+
'1' => '',
6+
'2' => '',
7+
'3' => '',
8+
'4' => '',
9+
'5' => '',
10+
'6' => '',
11+
'7' => '',
12+
'8' => '',
13+
'9' => '')
14+
function map_subscripts(indices)
15+
str = string(indices)
16+
join(IndexMap[c] for c in str)
17+
end
1418

1519
"""
1620
$(TYPEDEF)
@@ -31,7 +35,7 @@ struct Variable <: Function
3135
Variable(name; known = false) = new(name, known)
3236
end
3337
function Variable(name, indices...; known = false)
34-
var_name = Symbol("$(name)$(join(getindex.((IndexMap,),indices), "̒"))")
38+
var_name = Symbol("$(name)$(join(map_subscripts.(indices), "̒"))")
3539
Variable(var_name; known=known)
3640
end
3741

test/variable_parsing.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ s1 = [Variable(:s, 1, 1; known = true)() Variable(:s, 1, 2; known = true)()
5656
@variables x[1:2](t)
5757
x1 = [Variable(:x, 1)(t), Variable(:x, 2)(t)]
5858
@test isequal(x1, x)
59+
60+
@variables a[1:11,1:2]
61+
@variables a()

0 commit comments

Comments
 (0)