LabelledArrays

Arrays which also have a label for each element for easy scientific machine learning (SciML)

https://github.com/sciml/labelledarrays.jl

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    3 of 27 committers (11.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.7%) to scientific vocabulary

Keywords

arrays scientific-machine-learning sciml

Keywords from Contributors

matrix-exponential pde sde numerical ode differential-equations dae dde differentialequations partial-differential-equations
Last synced: 9 months ago · JSON representation ·

Repository

Arrays which also have a label for each element for easy scientific machine learning (SciML)

Basic Info
Statistics
  • Stars: 121
  • Watchers: 3
  • Forks: 20
  • Open Issues: 19
  • Releases: 56
Topics
arrays scientific-machine-learning sciml
Created over 8 years ago · Last pushed 10 months ago
Metadata Files
Readme License Citation

README.md

LabelledArrays.jl

Join the chat at https://julialang.zulipchat.com #sciml-bridged Global Docs

codecov Build Status

ColPrac: Contributor's Guide on Collaborative Practices for Community Packages SciML Code Style

About

LabelledArrays.jl is a package which provides arrays with labels, i.e. they are arrays which map, broadcast, and all of that good stuff, but their components are labelled. Thus for instance you can set that the second component is named :second and retrieve it with A.second.

How to install

The package can be installed from this repository by

julia using Pkg Pkg.add("LabelledArrays")

Tutorials and Documentation

For information on using the package, see the stable documentation. Use the in-development documentation for the version of the documentation, which contains the unreleased features.

SLArrays

The SLArray and SLVector macros are for creating static LabelledArrays. First you create the type and then you can use that constructor to generate instances of the labelled array.

```julia ABC = @SLVector (:a, :b, :c) A = ABC(1, 2, 3) A.a == 1

ABCD = @SLArray (2, 2) (:a, :b, :c, :d) B = ABCD(1, 2, 3, 4) B.c == 3 B[2, 2] == B.d ```

Here we have that A == [1,2,3] and for example A.b == 2. We can create a typed SLArray via:

julia SVType = @SLVector Float64 (:a, :b, :c)

Alternatively, you can also construct a static labelled array using the SLVector constructor by writing out the entries as keyword arguments:

julia julia> SLVector(a = 1, b = 2, c = 3) 3-element SLArray{Tuple{3},1,(:a, :b, :c),Int64}: 1 2 3

For general N-dimensional labelled arrays, you need to specify the size (Tuple{dim1,dim2,...}) as the type parameter to the SLArray constructor:

julia julia> 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

Constructing copies with some items changed is supported by a keyword constructor whose first argument is the source and additional keyword arguments change several entries.

```julia julia> v1 = SLVector(a = 1.1, b = 2.2, c = 3.3);

julia> v2 = SLVector(v1; b = 20.20, c = 30.30) 3-element SLArray{Tuple{3},Float64,1,3,(:a, :b, :c)}: 1.1 20.2 30.3 ```

```julia julia> ABCD = @SLArray (2, 2) (:a, :b, :c, :d);

julia> B = ABCD(1, 2, 3, 4);

julia> B2 = SLArray(B; c = 30) 2×2 SLArray{Tuple{2,2},Int64,2,4,(:a, :b, :c, :d)}: 1 30 2 4 ```

One can also specify the indices directly.

```julia julia> EFG = @SLArray (2, 2) (e = 1:3, f = 4, g = 2:4);

julia> y = EFG(1.0, 2.5, 3.0, 5.0) 2×2 SLArray{Tuple{2,2},Float64,2,4,(e = 1:3, f = 4, g = 2:4)}: 1.0 3.0 2.5 5.0

julia> y.g 3-element view(reshape(::StaticArrays.SArray{Tuple{2,2},Float64,2,4}, 4), 2:4) with eltype Float64: 2.5 3.0 5.0

julia> Arr = @SLArray (2, 2) (a = (2, :), b = 3);

julia> z = Arr(1, 2, 3, 4);

julia> z.a 2-element view(::StaticArrays.SArray{Tuple{2,2},Int64,2,4}, 2, :) with eltype Int64: 2 4 ```

LArrays

The LArrayss are fully mutable arrays with labels. There is no performance loss by using the labelled instead of indexing. Using the macro with values and labels generates the labelled array with the given values:

julia A = @LArray [1, 2, 3] (:a, :b, :c) A.a == 1

One can generate a labelled array with undefined values by instead giving the dimensions:

julia A = @LArray Float64 (2, 2) (:a, :b, :c, :d) W = rand(2, 2) A .= W A.d == W[2, 2]

or using an @LVector shorthand:

julia A = @LVector Float64 (:a, :b, :c, :d) A .= rand(4)

As with SLArray, alternative constructors exist that use the keyword argument form:

```julia julia> LVector(a = 1, b = 2, c = 3) 3-element LArray{Int64,1,(:a, :b, :c)}: 1 2 3

julia> LArray((2, 2); a = 1, b = 2, c = 3, d = 4) # need to specify size as first argument 2×2 LArray{Int64,2,(:a, :b, :c, :d)}: 1 3 2 4 ```

One can also specify the indices directly.

```julia julia> z = @LArray 1.0, 2.0, 3.0;

julia> z.b 2-element view(::Array{Float64,1}, 2:3) with eltype Float64: 2.0 3.0

julia> z = @LArray 1 2; 3 4;

julia> z.a 2-element view(::Array{Int64,2}, 2, :) with eltype Int64: 3 4 ```

The labels of LArray and SLArray can be accessed by function symbols, which returns a tuple of symbols.

Example: Nice DiffEq Syntax Without A DSL

LabelledArrays.jl are a way to get DSL-like syntax without a macro. In this case, we can solve differential equations with labelled components by making use of labelled arrays, and always refer to the components by name instead of index.

Let's solve the Lorenz equation. Using @LVectors, we can do:

```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 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 ```

We can also make use of @SLVector:

```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()) ```

Relation to NamedTuples

Julia's Base has NamedTuples in v0.7+. They are constructed as:

julia p = (σ = 10.0, ρ = 28.0, β = 8 / 3)

and they support p[1] and p.σ as well. The LVector, SLVector, LArray and SLArray constructors also support named tuples as their arguments:

```julia julia> LVector((a = 1, b = 2)) 2-element LArray{Int64,1,(:a, :b)}: 1 2

julia> SLVector((a = 1, b = 2)) 2-element SLArray{Tuple{2},1,(:a, :b),Int64}: 1 2

julia> LArray((2, 2), (a = 1, b = 2, c = 3, d = 4)) 2×2 LArray{Int64,2,(:a, :b, :c, :d)}: 1 3 2 4

julia> 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 ```

Converting to a named tuple from a labelled array x is available using convert(NamedTuple, x). Furthermore, pairs(x) creates an iterator that is functionally the same as pairs(convert(NamedTuple, x)), yielding :label => x.label for each label of the array.

There are some crucial differences between a labelled array and a named tuple. Labelled arrays can have any dimensions while named tuples are always 1D. A named tuple can have different types on each element, while an SLArray can only have one element type and furthermore it has the actions of a static vector. As a result SLArray has less element type information, which improves compilation speed while giving more vector functionality than a NamedTuple. LArray also only has a single element type and, unlike a named tuple, is mutable.

Note: Labelled slices

This functionality has been removed from LabelledArrays.jl, but can replicated with the same compile-time performance and indexing syntax using DimensionalData.jl.

Owner

  • Name: SciML Open Source Scientific Machine Learning
  • Login: SciML
  • Kind: organization
  • Email: contact@chrisrackauckas.com

Open source software for scientific machine learning

Citation (CITATION.bib)

@article{DifferentialEquations.jl-2017,
 author = {Rackauckas, Christopher and Nie, Qing},
 doi = {10.5334/jors.151},
 journal = {The Journal of Open Research Software},
 keywords = {Applied Mathematics},
 note = {Exported from https://app.dimensions.ai on 2019/05/05},
 number = {1},
 pages = {},
 title = {DifferentialEquations.jl – A Performant and Feature-Rich Ecosystem for Solving Differential Equations in Julia},
 url = {https://app.dimensions.ai/details/publication/pub.1085583166 and http://openresearchsoftware.metajnl.com/articles/10.5334/jors.151/galley/245/download/},
 volume = {5},
 year = {2017}
}

GitHub Events

Total
  • Create event: 8
  • Release event: 1
  • Issues event: 3
  • Watch event: 2
  • Delete event: 4
  • Issue comment event: 9
  • Push event: 12
  • Pull request event: 8
Last Year
  • Create event: 8
  • Release event: 1
  • Issues event: 3
  • Watch event: 2
  • Delete event: 4
  • Issue comment event: 9
  • Push event: 12
  • Pull request event: 8

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 273
  • Total Committers: 27
  • Avg Commits per committer: 10.111
  • Development Distribution Score (DDS): 0.564
Past Year
  • Commits: 9
  • Committers: 4
  • Avg Commits per committer: 2.25
  • Development Distribution Score (DDS): 0.444
Top Committers
Name Email Commits
Christopher Rackauckas a****s@c****m 119
Yingbo Ma m****5@g****m 24
Xingjian Guo x****3@n****u 13
Chris Elrod e****c@g****m 13
ArnoStrouwen a****n@t****e 13
Thomas Wutzler t****z@b****e 11
Rafael Schouten r****n@g****m 10
krishna bhogaonker c****q@g****m 10
Tor Erlend Fjelde t****5@g****m 9
dependabot[bot] 4****] 7
Anant Thazhemadam a****m@g****m 7
David Widmann d****b@d****e 5
github-actions[bot] 4****] 5
Andreas Noack a****s@n****k 5
CompatHelper Julia c****y@j****g 3
Aayush Sabharwal a****l@j****m 3
alecloudenback a****k 3
Chris de Graaf me@c****v 2
Mus m****m@o****m 2
Thomas Vetter 8****t 2
Anshul Singhvi a****7@s****u 1
Erik Schnetter s****r@g****m 1
Hendrik Ranocha m****l@r****e 1
Julia TagBot 5****t 1
Oscar Smith o****h@g****m 1
Thomas Wutzler p****w@a****e 1
femtocleaner[bot] f****] 1

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 35
  • Total pull requests: 86
  • Average time to close issues: 6 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 21
  • Total pull request authors: 22
  • Average comments per issue: 6.6
  • Average comments per pull request: 0.45
  • Merged pull requests: 79
  • Bot issues: 0
  • Bot pull requests: 15
Past Year
  • Issues: 2
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: about 3 hours
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 4.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • ChrisRackauckas (7)
  • bgctw (5)
  • fkrauer (3)
  • Deduction42 (2)
  • pcjentsch (2)
  • dutille (1)
  • chriselrod (1)
  • JuliaTagBot (1)
  • rvignolo (1)
  • rafaqz (1)
  • pkofod (1)
  • scheidan (1)
  • dmbates (1)
  • jpfairbanks (1)
  • yakir12 (1)
Pull Request Authors
  • ChrisRackauckas (21)
  • ArnoStrouwen (12)
  • dependabot[bot] (10)
  • github-actions[bot] (8)
  • thazhemadam (7)
  • chriselrod (6)
  • YingboMa (5)
  • bgctw (4)
  • AayushSabharwal (4)
  • andreasnoack (4)
  • christopher-dG (2)
  • torfjelde (2)
  • oscardssmith (2)
  • 00krishna (2)
  • alecloudenback (2)
Top Labels
Issue Labels
bug (2) question (1)
Pull Request Labels
dependencies (10)

Packages

  • Total packages: 1
  • Total downloads:
    • julia 785 total
  • Total dependent packages: 25
  • Total dependent repositories: 0
  • Total versions: 56
juliahub.com: LabelledArrays

Arrays which also have a label for each element for easy scientific machine learning (SciML)

  • Versions: 56
  • Dependent Packages: 25
  • Dependent Repositories: 0
  • Downloads: 785 Total
Rankings
Dependent packages count: 3.2%
Stargazers count: 6.8%
Average: 7.2%
Forks count: 8.9%
Dependent repos count: 9.9%
Last synced: 9 months ago

Dependencies

.github/workflows/CI.yml actions
  • actions/cache v1 composite
  • actions/checkout v2 composite
  • codecov/codecov-action v1 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-processcoverage v1 composite
  • julia-actions/julia-runtest v1 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/CompatHelper.yml actions
  • julia-actions/setup-julia latest composite
.github/workflows/Documentation.yml actions
  • actions/checkout v2 composite
  • codecov/codecov-action v1 composite
  • julia-actions/julia-processcoverage v1 composite
  • julia-actions/setup-julia latest composite
.github/workflows/FormatCheck.yml actions
  • actions/checkout v1 composite
  • julia-actions/setup-julia latest composite
.github/workflows/Invalidations.yml actions
  • actions/checkout v3 composite
  • julia-actions/julia-buildpkg v1 composite
  • julia-actions/julia-invalidations v1 composite
  • julia-actions/setup-julia v1 composite
.github/workflows/TagBot.yml actions
  • JuliaRegistries/TagBot v1 composite