Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get index range of subarray? #240

Open
vpuri3 opened this issue Jan 23, 2024 · 3 comments
Open

How to get index range of subarray? #240

vpuri3 opened this issue Jan 23, 2024 · 3 comments

Comments

@vpuri3
Copy link
Contributor

vpuri3 commented Jan 23, 2024

In the case below, how do I get the range of indices spanned by x.a?

x = (; a = ones(2), b = ones(2)) |> ComponentArray

idx_a = ?? # want 1:2
@vpuri3
Copy link
Contributor Author

vpuri3 commented Jan 24, 2024

@jonniedie is that possible? TIA

@jonniedie
Copy link
Owner

It's a little clunky, but you can do

only(getaxes(x))[:a].idx

@vpuri3
Copy link
Contributor Author

vpuri3 commented Mar 4, 2024

Thanks, that works. Is there a similar way to get the global indices of nested arrays? eg.

ca = (; a = ones(2), b = (; x = 2 * ones(2), y = 3 * ones(2))) |> ComponentArray
idx_b_x = getindices(ca.b.x) # want 3:4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants