SciML / SciML/ComponentArrays.jl

How to efficiently access first element of all subarrays, i.e. [:,1] or explicitly [(:SWATI, :GWAT),:amt]

Open
#165 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
375
Forks
42
Avg merge
7h 25m
Merged PRs (30d)
17

Description

Hi,
I was wondering if there ist an efficient way to access the first element of all the subarrays in a ComponentVector of ComponentVectors?

using BenchmarkTools
using ComponentArrays #, LabelledArrays, RecursiveArrayTools


SWATI=ComponentArray(amt = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], conc = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10])
GWAT =ComponentArray(amt = 1.0, conc = 3.0)
u0 = ComponentArray(SWATI = SWATI, GWAT = GWAT)


@btime sum(reduce(vcat,[u0.SWATI.amt, u0.GWAT.amt])) # 5.175 μs (54 allocations: 1.98 KiB)
@btime sum(vcat(u0.SWATI.amt, u0.GWAT.amt))          # 3.912 μs (48 allocations: 1.72 KiB)

Or would this require defining the ComponentVector with permuted dimensions?
Further, I saw higher dimensional ComponentArrays mentioned in the README.md, but I have not seen any example how to generate them in the documentation. Could you provide an example of this, please?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with README.md and the ComponentArray construction and indexing examples shown in the issue. Reproduce the BenchmarkTools examples to determine the supported way to access the first elements and how higher-dimensional ComponentArrays are created. Done means adding a clear, runnable documentation example covering both questions.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.