|
1 | 1 | # SLArrays |
2 | 2 |
|
3 | | -The `SLArray` and `SLVector` macros are for creating static LabelledArrays. |
4 | | -First you create the type and then you can use that constructor to generate |
| 3 | +The `SLArray` and `SLVector` macros create static LabelledArrays. |
| 4 | +First the user would create the array type, then use that constructor to generate |
5 | 5 | instances of the labelled array. |
6 | 6 |
|
7 | | -```julia |
8 | | -ABC = @SLVector (:a,:b,:c) |
9 | | -A = ABC(1,2,3) |
10 | | -A.a == 1 |
| 7 | +## `@SLArray` and `@SLVector` macros |
11 | 8 |
|
12 | | -ABCD = @SLArray (2,2) (:a,:b,:c,:d) |
13 | | -B = ABCD(1,2,3,4) |
14 | | -B.c == 3 |
15 | | -B[2,2] == B.d |
16 | | -``` |
17 | | - |
18 | | -Here we have that `A == [1,2,3]` and for example `A.b == 2`. We can create a |
19 | | -typed `SLArray` via: |
20 | | - |
21 | | -```julia |
22 | | -SVType = @SLVector Float64 (:a,:b,:c) |
23 | | -``` |
24 | | - |
25 | | -Alternatively, you can also construct a static labelled array using the |
26 | | -`SLVector` constructor by writing out the entries as keyword arguments: |
| 9 | +Macro constructors are convenient for building most `SLArray` objects. An |
| 10 | +`@SLArray` may be of arbitrary dimension while an `@SLVector` is a |
| 11 | +one dimensional array. |
27 | 12 |
|
28 | | -```julia |
29 | | -julia> SLVector(a=1, b=2, c=3) |
30 | | -3-element SLArray{Tuple{3},1,(:a, :b, :c),Int64}: |
31 | | - 1 |
32 | | - 2 |
33 | | - 3 |
| 13 | +```@docs |
| 14 | +@SLArray |
| 15 | +@SLVector |
34 | 16 | ``` |
35 | 17 |
|
36 | | -For general N-dimensional labelled arrays, you need to specify the size |
37 | | -(`Tuple{dim1,dim2,...}`) as the type parameter to the `SLArray` constructor: |
| 18 | +## `SLArray` and `SLVector` constructors |
38 | 19 |
|
39 | | -```julia |
40 | | -julia> SLArray{Tuple{2,2}}(a=1, b=2, c=3, d=4) |
41 | | -2×2 SLArray{Tuple{2,2},2,(:a, :b, :c, :d),Int64}: |
42 | | - 1 3 |
43 | | - 2 4 |
44 | | -``` |
45 | | - |
46 | | -Constructing copies with some items changed is supported by |
47 | | -a keyword constructor whose first argument is the source and |
48 | | -additonal keyword arguments change several entries. |
49 | | - |
50 | | -```julia |
51 | | -julia> v1 = SLVector(a=1.1, b=2.2, c=3.3); |
52 | | -julia> v2 = SLVector(v1; b=20.20, c=30.30 ) |
53 | | -3-element SLArray{Tuple{3},Float64,1,3,(:a, :b, :c)}: |
54 | | - 1.1 |
55 | | - 20.2 |
56 | | - 30.3 |
57 | | -``` |
| 20 | +Alternatively, users can construct a static labelled array using the |
| 21 | +`SLVector` and `SLArrays` constructors by writing out the entries as keyword arguments: |
58 | 22 |
|
59 | | -```julia |
60 | | -julia> ABCD = @SLArray (2,2) (:a,:b,:c,:d); |
61 | | -julia> B = ABCD(1,2,3,4); |
62 | | -julia> B2 = SLArray(B; c=30 ) |
63 | | -2×2 SLArray{Tuple{2,2},Int64,2,4,(:a, :b, :c, :d)}: |
64 | | - 1 30 |
65 | | - 2 4 |
| 23 | +```@docs |
| 24 | +SLArray |
| 25 | +SLVector |
66 | 26 | ``` |
67 | 27 |
|
68 | | -One can also specify the indices directly. |
69 | | -```julia |
70 | | -julia> EFG = @SLArray (2,2) (e=1:3, f=4, g=2:4); |
71 | | -julia> y = EFG(1.0,2.5,3.0,5.0) |
72 | | -2×2 SLArray{Tuple{2,2},Float64,2,4,(e = 1:3, f = 4, g = 2:4)}: |
73 | | - 1.0 3.0 |
74 | | - 2.5 5.0 |
| 28 | +## Manipulating `SLArrays` and `SLVectors` |
75 | 29 |
|
76 | | -julia> y.g |
77 | | -3-element view(reshape(::StaticArrays.SArray{Tuple{2,2},Float64,2,4}, 4), 2:4) with eltype Float64: |
78 | | - 2.5 |
79 | | - 3.0 |
80 | | - 5.0 |
| 30 | +Users may want a list of the labels or keys in an `SLArray` or `SLVector`. |
| 31 | +The `symbols(::SLArray)` function returns a tuple of array labels. |
81 | 32 |
|
82 | | -julia> Arr = @SLArray (2, 2) (a = (2, :), b = 3); |
83 | | -julia> z = Arr(1, 2, 3, 4); |
84 | | -julia> z.a |
85 | | -2-element view(::StaticArrays.SArray{Tuple{2,2},Int64,2,4}, 2, :) with eltype Int64: |
86 | | - 2 |
87 | | - 4 |
| 33 | +```@docs |
| 34 | +symbols(::SLArray) |
88 | 35 | ``` |
0 commit comments