### Install LabelledArrays.jl Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/index.md Use the Julia package manager to add LabelledArrays.jl to your project. This is the standard way to install Julia packages. ```julia using Pkg Pkg.add("LabelledArrays") ``` -------------------------------- ### Create SLArray using @SLArray macro Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Use the @SLArray macro for convenient construction of static labelled arrays of arbitrary dimensions. No specific setup is required beyond importing the macro. ```julia @SLArray ``` -------------------------------- ### Create SLVector using @SLVector macro Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Use the @SLVector macro for convenient construction of static labelled vectors (1D arrays). No specific setup is required beyond importing the macro. ```julia @SLVector ``` -------------------------------- ### Get labels of SLArray using symbols() Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Retrieve a tuple of array labels from an SLArray using the symbols() function. This is useful for inspecting the structure of the labelled array. ```julia symbols(::SLArray) ``` -------------------------------- ### LArray Constructor Documentation Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Displays documentation for the original LArray constructor, used for creating labelled arrays. ```julia LArray ``` -------------------------------- ### Integration with OrdinaryDiffEq Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Demonstrates using labelled arrays (both mutable `LArray` and immutable `SLArray`) to define and solve Ordinary Differential Equations (ODEs) with human-readable state and parameter names, offering a performance-neutral approach. ```APIDOC ## Integration with OrdinaryDiffEq — Labelled ODE states and parameters Use labelled arrays to write ODE systems with human-readable state and parameter names instead of integer indices, with no performance penalty. ```julia using LabelledArrays, OrdinaryDiffEq # Mutable LArray approach (non-allocating in-place form) function lorenz!(du, u, p, t) du.x = p.σ * (u.y - u.x) du.y = u.x * (p.ρ - u.z) - u.y du.z = u.x * u.y - p.β * u.z end u0 = @LArray [1.0, 0.0, 0.0] (:x, :y, :z) p = @LArray [10.0, 28.0, 8/3] (:σ, :ρ, :β) prob = ODEProblem(lorenz!, u0, (0.0, 10.0), p) sol = solve(prob, Tsit5()) sol[10].x # solution elements are also labelled # Immutable SLArray approach (allocating out-of-place form) LorenzState = @SLVector (:x, :y, :z) LorenzParams = @SLVector (:σ, :ρ, :β) function lorenz(u, p, t) LorenzState( p.σ * (u.y - u.x), u.x * (p.ρ - u.z) - u.y, u.x * u.y - p.β * u.z ) end u0 = LorenzState(1.0, 0.0, 0.0) p = LorenzParams(10.0, 28.0, 8/3) prob = ODEProblem(lorenz, u0, (0.0, 10.0), p) sol = solve(prob, Tsit5()) ``` ``` -------------------------------- ### Constructing a NamedTuple Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/NamedTuples_relation.md Demonstrates the basic syntax for creating a NamedTuple in Julia. ```julia p = (σ = 10.0, ρ = 28.0, β = 8 / 3) ``` -------------------------------- ### Constructing LVector from NamedTuple Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/NamedTuples_relation.md Shows how to initialize an LVector using a NamedTuple. ```julia LVector((a = 1, b = 2)) ``` -------------------------------- ### LVector Constructor Documentation Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Displays documentation for the original LVector constructor, used for creating one-dimensional labelled arrays. ```julia LVector ``` -------------------------------- ### Construct SLVector with Keyword Arguments Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Instantiate an SLVector by providing labels and values as keyword arguments. ```julia SLVector(a = 1, b = 2, c = 3) ``` -------------------------------- ### Constructing SLVector from NamedTuple Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/NamedTuples_relation.md Illustrates initializing an SLVector with a NamedTuple. ```julia SLVector((a = 1, b = 2)) ``` -------------------------------- ### Display Julia Version Information Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/index.md Prints detailed information about the Julia version, operating system, and hardware. Helpful for reproducibility and troubleshooting. ```julia using InteractiveUtils versioninfo() ``` -------------------------------- ### Construct LArray with keyword arguments Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Construct an LArray using keyword arguments for labels and values, specifying dimensions as the first argument. ```julia LArray((2, 2); a = 1, b = 2, c = 3, d = 4) ``` -------------------------------- ### Construct SLArray using constructor Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Construct a static labelled array by providing entries as keyword arguments to the SLArray constructor. This method offers an alternative to the macro. ```julia SLArray ``` -------------------------------- ### Construct N-dimensional SLArray with Keyword Arguments Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Instantiate an N-dimensional SLArray by specifying the size and providing labels and values as keyword arguments. ```julia SLArray{Tuple{2, 2}}(a = 1, b = 2, c = 3, d = 4) ``` -------------------------------- ### Show Detailed Package Status Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/index.md Displays a more detailed status of packages, including manifest information. Use PKGMODE_MANIFEST for a comprehensive view. ```julia using Pkg Pkg.status(; mode = PKGMODE_MANIFEST) ``` -------------------------------- ### SLArray and SLVector Constructors Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Users can also construct static labelled arrays directly using the SLArray and SLVector constructors by specifying entries as keyword arguments. ```APIDOC ## Direct Constructors ### `SLArray` Constructs a static labelled array of arbitrary dimension using keyword arguments for entries. ### `SLVector` Constructs a one-dimensional static labelled array using keyword arguments for entries. ``` -------------------------------- ### Construct LVector with keyword arguments Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Construct an LVector using keyword arguments for labels and values, providing a more readable initialization. ```julia LVector(a = 1, b = 2, c = 3) ``` -------------------------------- ### Construct SLVector using constructor Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md Construct a static labelled vector (1D array) by providing entries as keyword arguments to the SLVector constructor. This method offers an alternative to the macro. ```julia SLVector ``` -------------------------------- ### LArray Macro Documentation Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Displays documentation for the @LArray macro, used for creating labelled arrays of arbitrary dimensions. ```julia @LArray ``` -------------------------------- ### Constructing SLArray from NamedTuple Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/NamedTuples_relation.md Shows how to initialize an SLArray with a specific shape using a NamedTuple. ```julia SLArray{Tuple{2, 2}}((a = 1, b = 2, c = 3, d = 4)) ``` -------------------------------- ### Solving Lorenz Equation with Mutable LArray Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/Example_dsl.md Use a mutable LArray for initial conditions and parameters when solving differential equations. This allows for the non-allocating form of the OrdinaryDiffEq API. The solution can also be indexed by name. ```julia using LabelledArrays, OrdinaryDiffEq function lorenz_f!(du, u, p, t) du.x = p.σ * (u.y - u.x) du.y = u.x * (p.ρ - u.z) - u.y du.z = u.x * u.y - p.β * u.z end u0 = @LArray [1.0, 0.0, 0.0] (:x, :y, :z) p = @LArray [10.0, 28.0, 8 / 3] (:σ, :ρ, :β) tspan = (0.0, 10.0) prob = ODEProblem(lorenz_f!, u0, tspan, p) sol = solve(prob, Tsit5()) # Now the solution can be indexed as .x/y/z as well! sol[10].x ``` -------------------------------- ### LVector Macro Documentation Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Displays documentation for the @LVector macro, used for creating one-dimensional labelled arrays. ```julia @LVector ``` -------------------------------- ### Labelled ODE States and Parameters with OrdinaryDiffEq Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Demonstrates using mutable LArray for non-allocating ODE systems and immutable SLArray for allocating ODE systems with OrdinaryDiffEq. ```julia using LabelledArrays, OrdinaryDiffEq # Mutable LArray approach (non-allocating in-place form) function lorenz!(du, u, p, t) du.x = p.σ * (u.y - u.x) du.y = u.x * (p.ρ - u.z) - u.y du.z = u.x * u.y - p.β * u.z end u0 = @LArray [1.0, 0.0, 0.0] (:x, :y, :z) p = @LArray [10.0, 28.0, 8/3] (:σ, :ρ, :β) prob = ODEProblem(lorenz!, u0, (0.0, 10.0), p) sol = solve(prob, Tsit5()) sol[10].x # solution elements are also labelled ``` ```julia # Immutable SLArray approach (allocating out-of-place form) LorenzState = @SLVector (:x, :y, :z) LorenzParams = @SLVector (:σ, :ρ, :β) function lorenz(u, p, t) LorenzState( p.σ * (u.y - u.x), u.x * (p.ρ - u.z) - u.y, u.x * u.y - p.β * u.z ) end u0 = LorenzState(1.0, 0.0, 0.0) p = LorenzParams(10.0, 28.0, 8/3) prob = ODEProblem(lorenz, u0, (0.0, 10.0), p) sol = solve(prob, Tsit5()) ``` -------------------------------- ### @LArray and @LVector Macros Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md These macros provide convenient ways to construct LArray and LVector objects with specified values and labels. ```APIDOC ## `@LArray` macro ### Description Constructs a multi-dimensional labelled array. ### Usage ```julia @LArray(values, labels) ``` ## `@LVector` macro ### Description Constructs a one-dimensional labelled array (vector). ### Usage ```julia @LVector(values, labels) ``` ``` -------------------------------- ### Constructing LArray from NamedTuple Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/NamedTuples_relation.md Demonstrates creating an LArray with specified dimensions using a NamedTuple for values. ```julia LArray((2, 2), (a = 1, b = 2, c = 3, d = 4)) ``` -------------------------------- ### Construct N-dimensional LArray using Keyword Arguments or NamedTuple Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Construct an N-dimensional LArray by providing the size explicitly, along with keyword arguments or a NamedTuple for initialization. Supports creating a copy with modified values. ```julia using LabelledArrays # 2×2 array via keyword arguments (size must be provided) M = LArray((2, 2); a = 1, b = 2, c = 3, d = 4) # 2×2 LArray{Int64,2,(:a, :b, :c, :d)}: # 1 3 # 2 4 M.c # => 3 M[1, 2] # => 3 # From a NamedTuple M2 = LArray((2, 2), (a = 10, b = 20, c = 30, d = 40)) M2.d # => 40 # Copy an existing array with some values changed M3 = LArray(M; c = 300) M3.c # => 300 M3.a # => 1 (unchanged) ``` -------------------------------- ### Show Package Status Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/index.md Displays the current status of packages in the Julia environment. Useful for debugging and understanding dependencies. ```julia using Pkg Pkg.status() ``` -------------------------------- ### SLArray Constructor with Keyword Arguments Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs a multi-dimensional SLArray using keyword arguments for element access. The size is specified as a type parameter. ```julia using LabelledArrays # Size given as type parameter, values as keyword arguments M = SLArray{Tuple{2, 2}}(a = 1, b = 2, c = 3, d = 4) # 2×2 SLArray{Tuple{2,2},2,(:a, :b, :c, :d),Int64}: # 1 3 # 2 4 M.c # => 3 ``` ```julia # From a NamedTuple M2 = SLArray{Tuple{2, 2}}((a = 10, b = 20, c = 30, d = 40)) M2.d # => 40 ``` ```julia # Copy with changed values M3 = SLArray(M; c = 300) M3.c # => 300 M3.a # => 1 (unchanged) ``` ```julia symbols(M) # => (:a, :b, :c, :d) ``` -------------------------------- ### SLVector Constructor with Keyword Arguments Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs a 1D SLVector using keyword arguments or a NamedTuple for element access. Supports creating immutable copies with updated fields. ```julia using LabelledArrays # Keyword argument form v = SLVector(a = 1.1, b = 2.2, c = 3.3) # 3-element SLArray{Tuple{3},Float64,1,3,(:a, :b, :c)}: # 1.1 # 2.2 # 3.3 v.b # => 2.2 ``` ```julia # NamedTuple form v2 = SLVector((x = 10, y = 20)) v2.x # => 10 ``` ```julia # Immutable copy with updated fields v3 = SLVector(v; b = 99.9, c = 100.0) v3.b # => 99.9 v3.a # => 1.1 (unchanged) ``` ```julia symbols(v) # => (:a, :b, :c) ``` -------------------------------- ### LArray and LVector Constructors Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md The original constructors for creating LArray and LVector objects. ```APIDOC ## `LArray` constructor ### Description Creates a labelled array of arbitrary dimension. ### Usage ```julia LArray(values, labels) ``` ## `LVector` constructor ### Description Creates a one-dimensional labelled array (vector). ### Usage ```julia LVector(values, labels) ``` ``` -------------------------------- ### Create and Use SLArray Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Define a static 2D array type with labels and create an instance. Access elements using dot notation or indexing. ```julia ABCD = @SLArray (2, 2) (:a, :b, :c, :d) B = ABCD(1, 2, 3, 4) B.c == 3 B[2, 2] == B.d ``` -------------------------------- ### Create and Use SLVector Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Define a static vector type with labels and create an instance. Access elements using dot notation. ```julia ABC = @SLVector (:a, :b, :c) A = ABC(1, 2, 3) A.a == 1 ``` -------------------------------- ### LArray with multi-dimensional index ranges Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Create a multi-dimensional LArray where labels map to specific index ranges or slices. ```julia z = @LArray [1 2; 3 4] (a = (2, :), b = 2:3) z.a ``` -------------------------------- ### Create LArray with values and labels Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Use the @LArray macro to generate a labelled array with specified values and corresponding labels. ```julia A = @LArray [1, 2, 3] (:a, :b, :c) A.a == 1 ``` -------------------------------- ### `SLArray` constructor Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs multi-dimensional static arrays with symbolic labels. Supports specifying dimensions as a type parameter and initializing with keyword arguments or a NamedTuple. Allows creating immutable copies with updated fields. ```APIDOC ## `SLArray` constructor — Keyword and NamedTuple construction for static N-D arrays Direct constructor for multi-dimensional `SLArray` with size specified as a type parameter. ```julia using LabelledArrays # Size given as type parameter, values as keyword arguments M = SLArray{Tuple{2, 2}}(a = 1, b = 2, c = 3, d = 4) # 2×2 SLArray{Tuple{2,2},2,(:a, :b, :c, :d),Int64}: # 1 3 # 2 4 M.c # => 3 # From a NamedTuple M2 = SLArray{Tuple{2, 2}}((a = 10, b = 20, c = 30, d = 40)) M2.d # => 40 # Copy with changed values M3 = SLArray(M; c = 300) M3.c # => 300 M3.a # => 1 (unchanged) symbols(M) # => (:a, :b, :c, :d) ``` ``` -------------------------------- ### `SLVector` constructor Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs static vectors with symbolic labels using keyword arguments or a NamedTuple. Supports creating immutable copies with modified fields. ```APIDOC ## `SLVector` constructor — Keyword and NamedTuple construction for static vectors Direct constructor form for `SLArray` 1D vectors without macros. ```julia using LabelledArrays # Keyword argument form v = SLVector(a = 1.1, b = 2.2, c = 3.3) # 3-element SLArray{Tuple{3},Float64,1,3,(:a, :b, :c)}: # 1.1 # 2.2 # 3.3 v.b # => 2.2 # NamedTuple form v2 = SLVector((x = 10, y = 20)) v2.x # => 10 # Immutable copy with updated fields v3 = SLVector(v; b = 99.9, c = 100.0) v3.b # => 99.9 v3.a # => 1.1 (unchanged) symbols(v) # => (:a, :b, :c) ``` ``` -------------------------------- ### Define SLArray with Indexing Labels Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Create a 2D SLArray where a label maps to a specific row and all columns. ```julia Arr = @SLArray (2, 2) (a = (2, :), b = 3) z = Arr(1, 2, 3, 4) z.a ``` -------------------------------- ### Create LVector shorthand Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Use the @LVector macro as a shorthand for creating 1D labelled arrays with undefined values. ```julia A = @LVector Float64 (:a, :b, :c, :d) A .= rand(4) ``` -------------------------------- ### SLArray and SLVector Macros Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md The @SLArray and @SLVector macros provide a convenient way to construct static labelled arrays of arbitrary or one-dimensional types, respectively. ```APIDOC ## Macro Constructors ### `@SLArray` Creates a static labelled array of arbitrary dimension. ### `@SLVector` Creates a one-dimensional static labelled array. ``` -------------------------------- ### Symbols Function Documentation Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Displays documentation for the symbols function, which returns a tuple of array labels for LArrays and LVectors. ```julia symbols ``` -------------------------------- ### Construct LVector using Keyword Arguments or NamedTuple Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Construct a 1D LArray directly using keyword arguments or a NamedTuple, without a macro. Supports creating a copy with modified values. ```julia using LabelledArrays # Keyword argument form v = LVector(a = 1, b = 2, c = 3) # 3-element LArray{Int64,1,(:a, :b, :c)}: # 1 # 2 # 3 v.b # => 2 # NamedTuple form nt = (x = 1.0, y = 2.0, z = 3.0) v2 = LVector(nt) v2.z # => 3.0 # Copy constructor with modified values v3 = LVector(v; b = 99) v3.b # => 99 v3.a # => 1 (unchanged) ``` -------------------------------- ### Solving Lorenz Equation with Immutable SLVector Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/Example_dsl.md Employ an immutable SLVector for initial conditions and parameters when the model equation requires the allocating form of the OrdinaryDiffEq API. This approach defines named types for vectors. ```julia LorenzVector = @SLVector (:x, :y, :z) LorenzParameterVector = @SLVector (:σ, :ρ, :β) function f(u, p, t) x = p.σ * (u.y - u.x) y = u.x * (p.ρ - u.z) - u.y z = u.x * u.y - p.β * u.z LorenzVector(x, y, z) end u0 = LorenzVector(1.0, 0.0, 0.0) p = LorenzParameterVector(10.0, 28.0, 8 / 3) tspan = (0.0, 10.0) prob = ODEProblem(f, u0, tspan, p) sol = solve(prob, Tsit5()) ``` -------------------------------- ### NamedTuple Interoperability (`convert` and `pairs`) Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Provides functions to convert labelled arrays to `NamedTuple` and to iterate over label-value pairs. Also supports constructing labelled arrays from `NamedTuple`s. ```APIDOC ## `convert(NamedTuple, x)` and `pairs` — NamedTuple interoperability Converts a labelled array to a `NamedTuple`, or iterates over label–value pairs. ```julia using LabelledArrays v = LVector(a = 1, b = 2, c = 3) # Convert to NamedTuple nt = convert(NamedTuple, v) # (a = 1, b = 2, c = 3) nt.b # => 2 # Pairs iterator (label => value) for (k, val) in pairs(v) println(k, " => ", val) end # a => 1 # b => 2 # c => 3 # Construct LArray/SLArray from NamedTuples lv = LVector((x = 10, y = 20)) sv = SLVector((x = 10, y = 20)) la = LArray((2, 2), (a = 1, b = 2, c = 3, d = 4)) sa = SLArray{Tuple{2, 2}}((a = 1, b = 2, c = 3, d = 4)) ``` ``` -------------------------------- ### `LArray` constructor — Multi-dimensional keyword and NamedTuple construction Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs an N-dimensional `LArray` with explicit size specification using keyword arguments or a `NamedTuple`. Supports creating immutable copies with modified values. ```APIDOC ## `LArray` constructor — Multi-dimensional keyword and NamedTuple construction Constructs an N-dimensional `LArray` with explicit size specification. ```julia using LabelledArrays # 2×2 array via keyword arguments (size must be provided) M = LArray((2, 2); a = 1, b = 2, c = 3, d = 4) # 2×2 LArray{Int64,2,(:a, :b, :c, :d)}: # 1 3 # 2 4 M.c # => 3 M[1, 2] # => 3 # From a NamedTuple M2 = LArray((2, 2), (a = 10, b = 20, c = 30, d = 40)) M2.d # => 40 # Copy an existing array with some values changed M3 = LArray(M; c = 300) M3.c # => 300 M3.a # => 1 (unchanged) ``` ``` -------------------------------- ### Define SLArray with Range and Index Labels Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Create a 2D SLArray where one label corresponds to a range of indices and another to a specific index. ```julia EFG = @SLArray (2, 2) (e = 1:3, f = 4, g = 2:4) y = EFG(1.0, 2.5, 3.0, 5.0) y.g ``` -------------------------------- ### `LVector` constructor — Keyword-argument and NamedTuple construction Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Constructs a 1D `LArray` directly from keyword arguments or a `NamedTuple`, without using a macro. Supports creating immutable copies with modified values. ```APIDOC ## `LVector` constructor — Keyword-argument and NamedTuple construction Constructs a 1D `LArray` directly from keyword arguments or a `NamedTuple`, without using a macro. ```julia using LabelledArrays # Keyword argument form v = LVector(a = 1, b = 2, c = 3) # 3-element LArray{Int64,1,(:a, :b, :c)}: # 1 # 2 # 3 v.b # => 2 # NamedTuple form nt = (x = 1.0, y = 2.0, z = 3.0) v2 = LVector(nt) v2.z # => 3.0 # Copy constructor with modified values v3 = LVector(v; b = 99) v3.b # => 99 v3.a # => 1 (unchanged) ``` ``` -------------------------------- ### LArray with index ranges Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Define an LArray where labels map to index ranges, allowing slicing by label. ```julia z = @LArray [1.0, 2.0, 3.0] (a = 1:2, b = 2:3) z.b ``` -------------------------------- ### Create LArray with undefined values Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Generate a labelled array with undefined values by providing dimensions and labels. Values can be assigned later. ```julia A = @LArray Float64 (2, 2) (:a, :b, :c, :d) W = rand(2, 2) A .= W A.d == W[2, 2] ``` -------------------------------- ### Create Immutable Static Labelled N-dimensional Array with @SLArray Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Use @SLArray to define a reusable constructor for a static multi-dimensional labelled array. Supports simple per-element labels and range/slice-based labels for compile-time optimizations. ```julia using LabelledArrays # 2×2 static labelled array type ABCD = @SLArray (2, 2) (:a, :b, :c, :d) B = ABCD(1, 2, 3, 4) B.a # => 1 B.c # => 3 B[2, 2] # => 4 (== B.d) # Range-based labels (one label covers multiple elements) EFG = @SLArray (2, 2) (e = 1:3, f = 4, g = 2:4) y = EFG(1.0, 2.5, 3.0, 5.0) y.e # => view of elements 1:3 => [1.0, 2.5, 3.0] y.f # => 5.0 ``` -------------------------------- ### NamedTuple Interoperability with Labelled Arrays Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Converts labelled arrays to NamedTuples and iterates over label-value pairs using `pairs`. Also shows construction of LArray/SLArray from NamedTuples. ```julia using LabelledArrays v = LVector(a = 1, b = 2, c = 3) # Convert to NamedTuple nt = convert(NamedTuple, v) # (a = 1, b = 2, c = 3) nt.b # => 2 ``` ```julia # Pairs iterator (label => value) for (k, val) in pairs(v) println(k, " => ", val) end # a => 1 # b => 2 # c => 3 ``` ```julia # Construct LArray/SLArray from NamedTuples lv = LVector((x = 10, y = 20)) sv = SLVector((x = 10, y = 20)) la = LArray((2, 2), (a = 1, b = 2, c = 3, d = 4)) sa = SLArray{Tuple{2, 2}}((a = 1, b = 2, c = 3, d = 4)) ``` -------------------------------- ### `@LArray` — Create a mutable labelled array with values Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Creates a mutable LArray from an existing array and a tuple of symbol names. Elements can be accessed by integer index or by `.label` syntax. Supports mutation by label and range-based label mapping for slices. ```APIDOC ## `@LArray` — Create a mutable labelled array with values Creates an `LArray` from an existing array and a tuple of symbol names. Elements are accessible both by integer index and by `.label` syntax. No performance overhead over plain arrays. ```julia using LabelledArrays # Create a 1D labelled array with initial values A = @LArray [1.0, 2.0, 3.0] (:x, :y, :z) A.x # => 1.0 A[2] # => 2.0 A.z # => 3.0 # Mutate by label A.y = 99.0 A # => [1.0, 99.0, 3.0] # Create a 2D labelled array with undefined values, then fill M = @LArray Float64 (2, 2) (:a, :b, :c, :d) W = rand(2, 2) M .= W M.d == W[2, 2] # => true # Range-based label mapping (label covers a slice) z = @LArray [1.0, 2.0, 3.0] (lo = 1:2, hi = 2:3) z.lo # => [1.0, 2.0] (view of indices 1:2) z.hi # => [2.0, 3.0] (view of indices 2:3) # 2D slice label: label maps to a row z2 = @LArray [1 2; 3 4] (top = (1, :), bot = (2, :)) z2.bot # => [3, 4] (view of row 2) ``` ``` -------------------------------- ### Create Typed SLVector Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Define a static vector type with labels and a specific element type (Float64). ```julia SVType = @SLVector Float64 (:a, :b, :c) ``` -------------------------------- ### `@SLVector` — Create an immutable (static) labelled vector type Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Defines a reusable constructor for an immutable labelled vector, backed by `StaticArrays.SArray` for compile-time optimizations. Supports explicit element types and immutable copying with modified values. ```APIDOC ## `@SLVector` — Create an immutable (static) labelled vector type Defines a reusable constructor for an immutable labelled vector. Backed by `StaticArrays.SArray` for compile-time optimizations. ```julia using LabelledArrays # Define a named static vector type ABC = @SLVector (:a, :b, :c) v = ABC(1.0, 2.5, 3.0) v.a # => 1.0 v.b # => 2.5 v[3] # => 3.0 (numeric indexing still works) # With explicit element type ABCf = @SLVector Float64 (:a, :b, :c) v2 = ABCf(1, 2, 3) # values converted to Float64 v2.c # => 3.0 # Immutable: copy with changed value using keyword constructor v3 = SLVector(v; b = 99.9) v3.b # => 99.9 v3.a # => 1.0 (unchanged) # Get labels symbols(v) # => (:a, :b, :c) ``` ``` -------------------------------- ### Create Modified SLArray Copy (2D) Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Generate a new 2D SLArray instance based on an existing one, with specific elements modified using keyword arguments. ```julia ABCD = @SLArray (2, 2) (:a, :b, :c, :d) B = ABCD(1, 2, 3, 4) B2 = SLArray(B; c = 30) ``` -------------------------------- ### `@LVector` — Create a mutable labelled vector (pre-allocated) Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Creates a 1D mutable LArray with undefined values, inferring its length from the number of labels. Useful for pre-allocating output buffers, such as ODE derivative vectors. ```APIDOC ## `@LVector` — Create a mutable labelled vector (pre-allocated) Creates a 1D `LArray` with undefined values; its length is inferred from the number of labels. Useful for pre-allocating output buffers (e.g., ODE derivative vectors). ```julia using LabelledArrays # Pre-allocate a Float64 vector with 4 labels du = @LVector Float64 (:dx, :dy, :dz, :dw) du .= rand(4) du.dz # => some Float64 value # Equivalent: use @LArray to allocate and set values simultaneously b = @LArray [10.0, 20.0, 30.0] (:dx, :dy, :dz) b.dy # => 20.0 ``` ``` -------------------------------- ### `@SLArray` — Create an immutable (static) labelled N-dimensional array type Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Defines a reusable constructor for a static multi-dimensional labelled array, backed by `StaticArrays.SArray`. Supports both per-element labels and range/slice-based labels. ```APIDOC ## `@SLArray` — Create an immutable (static) labelled N-dimensional array type Defines a reusable constructor for a static multi-dimensional labelled array. Supports both simple per-element labels and range/slice-based labels. ```julia using LabelledArrays # 2×2 static labelled array type ABCD = @SLArray (2, 2) (:a, :b, :c, :d) B = ABCD(1, 2, 3, 4) B.a # => 1 B.c # => 3 B[2, 2] # => 4 (== B.d) # Range-based labels (one label covers multiple elements) EFG = @SLArray (2, 2) (e = 1:3, f = 4, g = 2:4) y = EFG(1.0, 2.5, 3.0, 5.0) y.e # => view of elements 1:3 => [1.0, 2.5, 3.0] y.f # => 5.0 ``` ``` -------------------------------- ### Define Immutable Static Labelled Vector Type with @SLVector Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Use @SLVector to define a reusable constructor for an immutable labelled vector, backed by StaticArrays.SArray for compile-time optimizations. Supports explicit element types and copying with modifications. ```julia using LabelledArrays # Define a named static vector type ABC = @SLVector (:a, :b, :c) v = ABC(1.0, 2.5, 3.0) v.a # => 1.0 v.b # => 2.5 v[3] # => 3.0 (numeric indexing still works) # With explicit element type ABCf = @SLVector Float64 (:a, :b, :c) v2 = ABCf(1, 2, 3) # values converted to Float64 v2.c # => 3.0 # Immutable: copy with changed value using keyword constructor v3 = SLVector(v; b = 99.9) v3.b # => 99.9 v3.a # => 1.0 (unchanged) # Get labels symbols(v) # => (:a, :b, :c) ``` -------------------------------- ### Create Modified SLArray Copy Source: https://github.com/sciml/labelledarrays.jl/blob/master/README.md Generate a new SLArray instance based on an existing one, with specific elements modified using keyword arguments. ```julia v1 = SLVector(a = 1.1, b = 2.2, c = 3.3) v2 = SLVector(v1; b = 20.20, c = 30.30) ``` -------------------------------- ### `symbols` function Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Retrieves the tuple of symbolic labels associated with an `LArray` or `SLArray`. Useful for dynamic iteration over labels and their corresponding values. ```APIDOC ## `symbols` — Retrieve the labels of a labelled array Returns a tuple of the symbolic labels associated with an `LArray` or `SLArray`. ```julia using LabelledArrays v = LVector(x = 1.0, y = 2.0, z = 3.0) symbols(v) # => (:x, :y, :z) M = @SLArray (2, 2) (:a, :b, :c, :d) s = M(1, 2, 3, 4) symbols(s) # => (:a, :b, :c, :d) # Useful for iterating over labels dynamically for sym in symbols(v) println(sym, " => ", getproperty(v, sym)) end # x => 1.0 # y => 2.0 # z => 3.0 ``` ``` -------------------------------- ### Create Mutable LArray with Values using @LArray Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Use @LArray to create a mutable labelled array from an existing array and symbol names. Elements can be accessed by label or integer index, and mutated by label. Supports range-based label mapping for slices. ```julia using LabelledArrays # Create a 1D labelled array with initial values A = @LArray [1.0, 2.0, 3.0] (:x, :y, :z) A.x # => 1.0 A[2] # => 2.0 A.z # => 3.0 # Mutate by label A.y = 99.0 A # => [1.0, 99.0, 3.0] # Create a 2D labelled array with undefined values, then fill M = @LArray Float64 (2, 2) (:a, :b, :c, :d) W = rand(2, 2) M .= W M.d == W[2, 2] # => true # Range-based label mapping (label covers a slice) z = @LArray [1.0, 2.0, 3.0] (lo = 1:2, hi = 2:3) z.lo # => [1.0, 2.0] (view of indices 1:2) z.hi # => [2.0, 3.0] (view of indices 2:3) # 2D slice label: label maps to a row z2 = @LArray [1 2; 3 4] (top = (1, :), bot = (2, :)) z2.bot # => [3, 4] (view of row 2) ``` -------------------------------- ### symbols(::SLArray) Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/SLArrays.md The symbols function retrieves a tuple of the labels (or keys) associated with an SLArray or SLVector. ```APIDOC ## Manipulating SLArrays and SLVectors ### `symbols(::SLArray)` Returns a tuple of the array labels for an `SLArray` or `SLVector`. ``` -------------------------------- ### Create Mutable LVector with @LVector Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Use @LVector to pre-allocate a mutable 1D labelled array (LArray) with undefined values, inferring its length from the number of labels. Useful for output buffers. An equivalent using @LArray is also shown. ```julia using LabelledArrays # Pre-allocate a Float64 vector with 4 labels du = @LVector Float64 (:dx, :dy, :dz, :dw) du .= rand(4) du.dz # => some Float64 value # Equivalent: use @LArray to allocate and set values simultaneously b = @LArray [10.0, 20.0, 30.0] (:dx, :dy, :dz) b.dy # => 20.0 ``` -------------------------------- ### symbols Function Source: https://github.com/sciml/labelledarrays.jl/blob/master/docs/src/LArrays.md Retrieves the labels (symbols) associated with an LArray or LVector. ```APIDOC ## `symbols` function ### Description Returns a tuple of the labels (symbols) of an `LArray` or `LVector`. ### Usage ```julia symbols(array) ``` ### Parameters #### Path Parameters - **array** (LArray or LVector) - The labelled array from which to retrieve symbols. ### Returns - `Tuple` - A tuple containing the labels of the array. ``` -------------------------------- ### symbols Function for Labelled Arrays Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Retrieves the symbolic labels associated with an LArray or SLArray. Useful for iterating over labels dynamically. ```julia using LabelledArrays v = LVector(x = 1.0, y = 2.0, z = 3.0) symbols(v) # => (:x, :y, :z) ``` ```julia M = @SLArray (2, 2) (:a, :b, :c, :d) s = M(1, 2, 3, 4) symbols(s) # => (:a, :b, :c, :d) ``` ```julia # Useful for iterating over labels dynamically for sym in symbols(v) println(sym, " => ", getproperty(v, sym)) end # x => 1.0 # y => 2.0 # z => 3.0 ``` -------------------------------- ### `vcat` function Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Concatenates two `LArray`s or `SLArray`s vertically, merging their symbolic labels. The resulting array retains labelled access to all elements. ```APIDOC ## `vcat` — Concatenate labelled arrays Concatenates two `LArray`s or `SLArray`s, merging their labels. ```julia using LabelledArrays v1 = LVector(a = 1, b = 2) v2 = LVector(c = 3, d = 4) v3 = vcat(v1, v2) # 4-element LArray{Int64,1,(:a, :b, :c, :d)} v3.c # => 3 v3.d # => 4 # SLArray vcat sv1 = SLVector(x = 1.0, y = 2.0) sv2 = SLVector(z = 3.0) sv3 = vcat(sv1, sv2) sv3.z # => 3.0 symbols(sv3) # => (:x, :y, :z) ``` ``` -------------------------------- ### vcat for Concatenating Labelled Arrays Source: https://context7.com/sciml/labelledarrays.jl/llms.txt Concatenates two LArray or SLArray objects, merging their labels. The resulting array retains the labelled structure. ```julia using LabelledArrays v1 = LVector(a = 1, b = 2) v2 = LVector(c = 3, d = 4) v3 = vcat(v1, v2) # 4-element LArray{Int64,1,(:a, :b, :c, :d)} v3.c # => 3 v3.d # => 4 ``` ```julia # SLArray vcat sv1 = SLVector(x = 1.0, y = 2.0) sv2 = SLVector(z = 3.0) sv3 = vcat(sv1, sv2) sv3.z # => 3.0 symbols(sv3) # => (:x, :y, :z) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.