Skip to content

Commit d6335e9

Browse files
committed
This closes #5 and closes #3
1 parent 13e7d2e commit d6335e9

19 files changed

+235
-157
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ research/
55
.DS_Store
66
/dev/
77
/docs/build/
8-
/docs/site/
8+
/docs/site/
9+
/docs/make_local.jl
10+
/examples/wip
11+
/examples/.ipynb_checkpoints

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
4-
version = "0.1.1"
4+
version = "0.2.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,51 @@
66
[![Codecov](https://codecov.io/gh/jonniedie/ComponentArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/jonniedie/ComponentArrays.jl)
77
[![GitHub](https://img.shields.io/github/license/jonniedie/ComponentArrays.jl)](https://github.com/jonniedie/ComponentArrays.jl/blob/master/LICENSE.txt)
88

9-
The main export of this package is the ````CArray```` type. "Components" of ````CArray````s
9+
The main export of this package is the ````ComponentArray```` type. "Components" of ````ComponentArray````s
1010
are really just array blocks that can be accessed through a named index. The magic here is
11-
that this named indexing can create a new ```CArray``` whose data is a view into the original,
11+
that this named indexing can create a new ```ComponentArray``` whose data is a view into the original,
1212
allowing for standalone models to be composed together by simple function composition. In
13-
essence, ```CArray```s allow you to do the things you would usually need a modeling
13+
essence, ```ComponentArray```s allow you to do the things you would usually need a modeling
1414
language for, but without actually needing a modeling language. The main targets are for use
1515
in [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) and
1616
[Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl), but anything that requires
1717
flat vectors is fair game.
1818

1919
## General use
20-
The easiest way to construct 1-dimensional ```CArray```s is as if they were ```NamedTuple```s. In fact, a good way to think about them is as arbitrarily nested, mutable ```NamedTuple```s that can be passed through a solver.
20+
The easiest way to construct 1-dimensional ```ComponentArray```s is as if they were ```NamedTuple```s. In fact, a good way to think about them is as arbitrarily nested, mutable ```NamedTuple```s that can be passed through a solver.
2121
```julia
2222
julia> c = (a=2, b=[1, 2]);
2323

24-
julia> x = CArray(a=1, b=[2, 1, 4], c=c)
25-
CArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 2.0, b = [1.0, 2.0]))
24+
julia> x = ComponentArray(a=5, b=[(a=20., b=0), (a=33., b=0), (a=44., b=3)], c=c)
25+
ComponentArray{Float64}(a = 5.0, b = [(a = 20.0, b = 0.0), (a = 33.0, b = 0.0), (a = 44.0, b = 3.0)], c = (a = 2.0, b = [1.0, 2.0]))
2626

2727
julia> x.c.a = 400; x
28-
CArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 400.0, b = [1.0, 2.0]))
28+
ComponentArray{Float64}(a = 5.0, b = [(a = 20.0, b = 0.0), (a = 33.0, b = 0.0), (a = 44.0, b = 3.0)], c = (a = 400.0, b = [1.0, 2.0]))
2929

30-
julia> x[5]
30+
julia> x[8]
3131
400.0
3232

3333
julia> collect(x)
34-
7-element Array{Float64,1}:
35-
1.0
36-
2.0
37-
1.0
38-
4.0
34+
10-element Array{Float64,1}:
35+
5.0
36+
20.0
37+
0.0
38+
33.0
39+
0.0
40+
44.0
41+
3.0
3942
400.0
4043
1.0
4144
2.0
4245

43-
julia> typeof(similar(x, Int32)) === typeof(CArray{Int32}(a=1, b=[2, 1, 4], c=c))
46+
julia> typeof(similar(x, Int32)) === typeof(ComponentArray{Int32}(a=5, b=[(a=20., b=0), (a=33., b=0), (a=44., b=3)], c=c))
4447
true
4548
```
4649

47-
Higher dimensional ```CArray```s can be created too, but it's a little messy at the moment. The nice thing for modeling is that dimension expansion through broadcasted operations can create higher-dimensional ```CArray```s automatically, so Jacobian cache arrays that are created internally with ```false .* x .* x'``` will be ```CArray```s with proper axes. Check out the [ODE with Jacobian](https://github.com/jonniedie/ComponentArrays.jl/blob/master/examples/ODE_jac_example.jl) example in the examples folder to see how this looks in practice.
50+
Higher dimensional ```ComponentArray```s can be created too, but it's a little messy at the moment. The nice thing for modeling is that dimension expansion through broadcasted operations can create higher-dimensional ```ComponentArray```s automatically, so Jacobian cache arrays that are created internally with ```false .* x .* x'``` will be ```ComponentArray```s with proper axes. Check out the [ODE with Jacobian](https://github.com/jonniedie/ComponentArrays.jl/blob/master/examples/ODE_jac_example.jl) example in the examples folder to see how this looks in practice.
4851
```julia
4952
julia> x2 = x .* x'
50-
7×7 CArray{Tuple{Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))},Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))}},Float64,2,Array{Float64,2}}:
53+
7×7 ComponentArray{Tuple{Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))},Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))}},Float64,2,Array{Float64,2}}:
5154
1.0 2.0 1.0 4.0 2.0 1.0 2.0
5255
2.0 4.0 2.0 8.0 4.0 2.0 4.0
5356
1.0 2.0 1.0 4.0 2.0 1.0 2.0
@@ -57,7 +60,7 @@ julia> x2 = x .* x'
5760
2.0 4.0 2.0 8.0 4.0 2.0 4.0
5861

5962
julia> x2[:c,:c]
60-
3×3 CArray{Tuple{Axis{(a = 1, b = 2:3)},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
63+
3×3 ComponentArray{Tuple{Axis{(a = 1, b = 2:3)},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
6164
4.0 2.0 4.0
6265
2.0 1.0 2.0
6366
4.0 2.0 4.0
@@ -66,10 +69,10 @@ julia> x2[:a,:a]
6669
1.0
6770

6871
julia> x2[:a,:c]
69-
CArray{Float64}(a = 2.0, b = [1.0, 2.0])
72+
ComponentArray{Float64}(a = 2.0, b = [1.0, 2.0])
7073

7174
julia> x2[:b,:c]
72-
3×3 CArray{Tuple{Axis{NamedTuple()},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
75+
3×3 ComponentArray{Tuple{Axis{NamedTuple()},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
7376
4.0 2.0 4.0
7477
2.0 1.0 2.0
7578
8.0 4.0 8.0
@@ -102,7 +105,7 @@ function lorenz!(D, u, p, t; f=0.0)
102105
end
103106

104107
lorenz_p ==10.0, ρ=28.0, β=8/3)
105-
lorenz_ic = CArray(x=0.0, y=0.0, z=0.0)
108+
lorenz_ic = ComponentArray(x=0.0, y=0.0, z=0.0)
106109
lorenz_prob = ODEProblem(lorenz!, lorenz_ic, tspan, lorenz_p)
107110

108111

@@ -117,7 +120,7 @@ function lotka!(D, u, p, t; f=0.0)
117120
end
118121

119122
lotka_p ==2/3, β=4/3, γ=1.0, δ=1.0)
120-
lotka_ic = CArray(x=1.0, y=1.0)
123+
lotka_ic = ComponentArray(x=1.0, y=1.0)
121124
lotka_prob = ODEProblem(lotka!, lotka_ic, tspan, lotka_p)
122125

123126

@@ -132,7 +135,7 @@ function composed!(D, u, p, t)
132135
end
133136

134137
comp_p = (lorenz=lorenz_p, lotka=lotka_p, c=0.01)
135-
comp_ic = CArray(lorenz=lorenz_ic, lotka=lotka_ic)
138+
comp_ic = ComponentArray(lorenz=lorenz_ic, lotka=lotka_ic)
136139
comp_prob = ODEProblem(composed!, comp_ic, tspan, comp_p)
137140

138141

docs/src/examples/ODE_jac.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ODE with Jacobian
22

3-
This example shows how to use ComponentArrays for composing Jacobian update functions as well as ODE functions. Note using plain symbols to index into ```CArrays``` is still pretty slow. Until symbolic indexing is faster, the convenience function ```fastindices``` can be used to speed up simulation. The general syntax looks like
3+
This example shows how to use ComponentArrays for composing Jacobian update functions as well as ODE functions. Note using plain symbols to index into ```ComponentArrays``` is still pretty slow. Until symbolic indexing is faster, the convenience function ```fastindices``` can be used to speed up simulation. The general syntax looks like
44

55
```julia
66
_x, _y, _z = fastindices(:x, :y, :z)
@@ -46,7 +46,7 @@ function lorenz_jac!(D, u, p, t)
4646
end
4747

4848
lorenz_p ==10.0, ρ=28.0, β=8/3)
49-
lorenz_ic = CArray(x=0.0, y=0.0, z=0.0)
49+
lorenz_ic = ComponentArray(x=0.0, y=0.0, z=0.0)
5050
lorenz_fun = ODEFunction(lorenz!, jac=lorenz_jac!)
5151
lorenz_prob = ODEProblem(lorenz_fun, lorenz_ic, tspan, lorenz_p)
5252

@@ -73,7 +73,7 @@ function lotka_jac!(D, u, p, t)
7373
end
7474

7575
lotka_p ==2/3, β=4/3, γ=1.0, δ=1.0)
76-
lotka_ic = CArray(x=1.0, y=1.0)
76+
lotka_ic = ComponentArray(x=1.0, y=1.0)
7777
lotka_fun = ODEFunction(lotka!, jac=lotka_jac!)
7878
lotka_prob = ODEProblem(lotka_fun, lotka_ic, tspan, lotka_p)
7979

@@ -100,7 +100,7 @@ function composed_jac!(D, u, p, t)
100100
end
101101

102102
comp_p = (lorenz=lorenz_p, lotka=lotka_p, c=0.01)
103-
comp_ic = CArray(lorenz=lorenz_ic, lotka=lotka_ic)
103+
comp_ic = ComponentArray(lorenz=lorenz_ic, lotka=lotka_ic)
104104
comp_fun = ODEFunction(composed!, jac=composed_jac!)
105105
comp_prob = ODEProblem(comp_fun, comp_ic, tspan, comp_p)
106106

docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# ComponentArrays.jl
22

3-
The main export of this package is the ```CArray``` type. "Components" of ```CArray```s
3+
The main export of this package is the ```ComponentArray``` type. "Components" of ```ComponentArray```s
44
are really just array blocks that can be accessed through a named index. The magic here is
5-
that this named indexing can create a new ```CArray``` whose data is a view into the original,
5+
that this named indexing can create a new ```ComponentArray``` whose data is a view into the original,
66
allowing for standalone models to be composed together by simple function composition. In
7-
essence, ```CArray```s allow you to do the things you would usually need a modeling
7+
essence, ```ComponentArray```s allow you to do the things you would usually need a modeling
88
language for, but without actually needing a modeling language. The main targets are for use
99
in [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) and
1010
[Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl), but anything that requires

docs/src/quickstart.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Quick Start
22

33
## General use
4-
The easiest way to construct 1-dimensional ```CArray```s is as if they were ```NamedTuple```s. In fact, a good way to think about them is as arbitrarily nested, mutable ```NamedTuple```s that can be passed through a solver.
4+
The easiest way to construct 1-dimensional ```ComponentArray```s is as if they were ```NamedTuple```s. In fact, a good way to think about them is as arbitrarily nested, mutable ```NamedTuple```s that can be passed through a solver.
55
```julia
66
julia> c = (a=2, b=[1, 2]);
77

8-
julia> x = CArray(a=1, b=[2, 1, 4], c=c)
9-
CArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 2.0, b = [1.0, 2.0]))
8+
julia> x = ComponentArray(a=1, b=[2, 1, 4], c=c)
9+
ComponentArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 2.0, b = [1.0, 2.0]))
1010

1111
julia> x.c.a = 400; x
12-
CArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 400.0, b = [1.0, 2.0]))
12+
ComponentArray{Float64}(a = 1.0, b = [2.0, 1.0, 4.0], c = (a = 400.0, b = [1.0, 2.0]))
1313

1414
julia> x[5]
1515
400.0
@@ -24,14 +24,14 @@ julia> collect(x)
2424
1.0
2525
2.0
2626

27-
julia> typeof(similar(x, Int32)) === typeof(CArray{Int32}(a=1, b=[2, 1, 4], c=c))
27+
julia> typeof(similar(x, Int32)) === typeof(ComponentArray{Int32}(a=1, b=[2, 1, 4], c=c))
2828
true
2929
```
3030

31-
Higher dimensional ```CArray```s can be created too, but it's a little messy at the moment. The nice thing for modeling is that dimension expansion through broadcasted operations can create higher-dimensional ```CArray```s automatically, so Jacobian cache arrays that are created internally with ```false .* x .* x'``` will be ```CArray```s with proper axes. Check out the [ODE with Jacobian](https://github.com/jonniedie/ComponentArrays.jl/blob/master/examples/ODE_jac_example.jl) example in the examples folder to see how this looks in practice.
31+
Higher dimensional ```ComponentArray```s can be created too, but it's a little messy at the moment. The nice thing for modeling is that dimension expansion through broadcasted operations can create higher-dimensional ```ComponentArray```s automatically, so Jacobian cache arrays that are created internally with ```false .* x .* x'``` will be ```ComponentArray```s with proper axes. Check out the [ODE with Jacobian](https://github.com/jonniedie/ComponentArrays.jl/blob/master/examples/ODE_jac_example.jl) example in the examples folder to see how this looks in practice.
3232
```julia
3333
julia> x2 = x .* x'
34-
7×7 CArray{Tuple{Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))},Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))}},Float64,2,Array{Float64,2}}:
34+
7×7 ComponentArray{Tuple{Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))},Axis{(a = 1, b = 2:4, c = (5:7, (a = 1, b = 2:3)))}},Float64,2,Array{Float64,2}}:
3535
1.0 2.0 1.0 4.0 2.0 1.0 2.0
3636
2.0 4.0 2.0 8.0 4.0 2.0 4.0
3737
1.0 2.0 1.0 4.0 2.0 1.0 2.0
@@ -41,7 +41,7 @@ julia> x2 = x .* x'
4141
2.0 4.0 2.0 8.0 4.0 2.0 4.0
4242

4343
julia> x2[:c,:c]
44-
3×3 CArray{Tuple{Axis{(a = 1, b = 2:3)},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
44+
3×3 ComponentArray{Tuple{Axis{(a = 1, b = 2:3)},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
4545
4.0 2.0 4.0
4646
2.0 1.0 2.0
4747
4.0 2.0 4.0
@@ -50,10 +50,10 @@ julia> x2[:a,:a]
5050
1.0
5151

5252
julia> x2[:a,:c]
53-
CArray{Float64}(a = 2.0, b = [1.0, 2.0])
53+
ComponentArray{Float64}(a = 2.0, b = [1.0, 2.0])
5454

5555
julia> x2[:b,:c]
56-
3×3 CArray{Tuple{Axis{NamedTuple()},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
56+
3×3 ComponentArray{Tuple{Axis{NamedTuple()},Axis{(a = 1, b = 2:3)}},Float64,2,SubArray{Float64,2,Array{Float64,2},Tuple{UnitRange{Int64},UnitRange{Int64}},false}}:
5757
4.0 2.0 4.0
5858
2.0 1.0 2.0
5959
8.0 4.0 8.0

examples/ODE_example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function lorenz!(D, u, p, t; f=0.0)
1818
end
1919

2020
lorenz_p ==10.0, ρ=28.0, β=8/3)
21-
lorenz_ic = CArray(x=0.0, y=0.0, z=0.0)
21+
lorenz_ic = ComponentArray(x=0.0, y=0.0, z=0.0)
2222
lorenz_prob = ODEProblem(lorenz!, lorenz_ic, tspan, lorenz_p)
2323

2424

@@ -33,7 +33,7 @@ function lotka!(D, u, p, t; f=0.0)
3333
end
3434

3535
lotka_p ==2/3, β=4/3, γ=1.0, δ=1.0)
36-
lotka_ic = CArray(x=1.0, y=1.0)
36+
lotka_ic = ComponentArray(x=1.0, y=1.0)
3737
lotka_prob = ODEProblem(lotka!, lotka_ic, tspan, lotka_p)
3838

3939

@@ -48,7 +48,7 @@ function composed!(D, u, p, t)
4848
end
4949

5050
comp_p = (lorenz=lorenz_p, lotka=lotka_p, c=0.01)
51-
comp_ic = CArray(lorenz=lorenz_ic, lotka=lotka_ic)
51+
comp_ic = ComponentArray(lorenz=lorenz_ic, lotka=lotka_ic)
5252
comp_prob = ODEProblem(composed!, comp_ic, tspan, comp_p)
5353

5454

examples/ODE_jac_example.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function lorenz_jac!(D, u, p, t)
3434
end
3535

3636
lorenz_p ==10.0, ρ=28.0, β=8/3)
37-
lorenz_ic = CArray(x=0.0, y=0.0, z=0.0)
37+
lorenz_ic = ComponentArray(x=0.0, y=0.0, z=0.0)
3838
lorenz_fun = ODEFunction(lorenz!, jac=lorenz_jac!)
3939
lorenz_prob = ODEProblem(lorenz_fun, lorenz_ic, tspan, lorenz_p)
4040

@@ -61,7 +61,7 @@ function lotka_jac!(D, u, p, t)
6161
end
6262

6363
lotka_p ==2/3, β=4/3, γ=1.0, δ=1.0)
64-
lotka_ic = CArray(x=1.0, y=1.0)
64+
lotka_ic = ComponentArray(x=1.0, y=1.0)
6565
lotka_fun = ODEFunction(lotka!, jac=lotka_jac!)
6666
lotka_prob = ODEProblem(lotka_fun, lotka_ic, tspan, lotka_p)
6767

@@ -88,14 +88,14 @@ function composed_jac!(D, u, p, t)
8888
end
8989

9090
comp_p = (lorenz=lorenz_p, lotka=lotka_p, c=0.01)
91-
comp_ic = CArray(lorenz=lorenz_ic, lotka=lotka_ic)
91+
comp_ic = ComponentArray(lorenz=lorenz_ic, lotka=lotka_ic)
9292
comp_fun = ODEFunction(composed!, jac=composed_jac!)
9393
comp_prob = ODEProblem(comp_fun, comp_ic, tspan, comp_p)
9494

9595

9696
## Solve problem
9797
# We can solve the composed system...
98-
comp_sol = solve(comp_prob, alg_hints=[:stiff])
98+
comp_sol = solve(comp_prob, Rodas5())
9999

100100
# ...or we can unit test one of the component systems
101-
lotka_sol = solve(lotka_prob, alg_hints=[:stiff])
101+
lotka_sol = solve(lotka_prob, Rodas5())

examples/Optim_example.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ using Optim
33

44
rosen(u) = (1.0 - u.x)^2 + 100.0 * (u.y - u.x^2)^2
55

6-
u₀ = CArray(x=0, y=0)
7-
lb = CArray(x=-0.5, y=-0.5)
8-
ub = CArray(x=0.5, y=0.5)
6+
u₀ = ComponentArray(x=0, y=0)
7+
lb = ComponentArray(x=-0.5, y=-0.5)
8+
ub = ComponentArray(x=0.5, y=0.5)
99

1010
df = TwiceDifferentiable(rosen, u₀; autodiff=:forward)
1111
dfc = TwiceDifferentiableConstraints(lb, ub)

src/Axis.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
ax = Axis(nt::NamedTuple)
33
4-
Axes for named component access of CArrays. These are a little confusing and poorly
4+
Axes for named component access of ComponentArrays. These are a little confusing and poorly
55
thought-out, so maybe don't use them directly.
66
77
# Examples
@@ -14,9 +14,9 @@ Axis{(a = 1, b = 2:3, c = (4:10, (a = (1:3, (a = 1, b = 2:3)), b = 4:7)))}()
1414
1515
julia> A = [100, 4, 1.3, 1, 1, 4.4, 0.4, 2, 1, 45];
1616
17-
julia> cvec = CArray(A, ax);
17+
julia> cvec = ComponentArray(A, ax);
1818
19-
julia> cmat = CArray(A .* A', ax, ax);
19+
julia> cmat = ComponentArray(A .* A', ax, ax);
2020
2121
julia> cmat[:c,:c] * cvec.c
2222
7-element Array{Float64,1}:
@@ -43,17 +43,24 @@ const AxisorNAxis = Union{Axis, NAxis}
4343
const VarAxes = Tuple{Vararg{<:Axis}}
4444

4545
Axis{IdxMap}(x) where {IdxMap} = Axis{IdxMap}()
46-
Axis(x::Type{Axis{IdxMap}}) where {IdxMap} = Axis{IdxMap}()
46+
Axis(::Type{Axis{IdxMap}}) where {IdxMap} = Axis{IdxMap}()
4747
Axis(L, IdxMap) = Axis{IdxMap}()
4848
Axis(::Number, IdxMap) = NullAxis()
4949
Axis(::Colon, IdxMap) = Axis{IdxMap}()
50-
Axis(i, IdxMap, N) = NAxis(N, Axis(i, IdxMap))
50+
Axis(i, N, IdxMap) = NAxis(N, Axis(i, IdxMap))
5151
Axis(tup) = Axis(tup...)
5252
Axis(nt::NamedTuple) = Axis{nt}()
5353
Axis(;kwargs...) = Axis{(;kwargs...)}()
54+
Axis(x::Axis) = x
55+
Axis(x::NAxis{N,IdxMap}) where {N,IdxMap} = Axis{IdxMap}()
5456

5557
idxmap(::Axis{IdxMap}) where IdxMap = IdxMap
5658
idxmap(::Type{Axis{IdxMap}}) where IdxMap = IdxMap
59+
idxmap(::NAxis{N,IdxMap}) where {N,IdxMap} = IdxMap
60+
idxmap(::Type{NAxis{N,IdxMap}}) where {N,IdxMap} = IdxMap
61+
62+
numaxes(::NAxis{N,IdxMap}) where {N,IdxMap} = N
63+
numaxes(::Type{NAxis{N,IdxMap}}) where {N,IdxMap} = N
5764

5865
lastof(x) = x[end]
5966
lastof(x::Union{Tuple, NamedTuple}) = lastof(x[end])

0 commit comments

Comments
 (0)