parentindexes

parentindexes(A)

From an array view `A`, returns the corresponding indexes in the parent

Examples

In the Julia programming language, the function `parentindexes(A)` returns the corresponding indexes in the parent array view `A`.

``````julia> A = reshape([1, 2, 3, 4, 5, 6], (2, 3))
2×3 reshape(::Vector{Int64}, 2, 3) with eltype Int64:
1  3  5
2  4  6

julia> parentindexes(A)
6-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)
CartesianIndex(1, 3)
CartesianIndex(2, 3)``````

Here are some common examples of its use:

1. Obtain parent indexes from a reshaped array:

``````julia> A = reshape([1, 2, 3, 4, 5, 6], (2, 3));
julia> parentindexes(A)
6-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)
CartesianIndex(1, 3)
CartesianIndex(2, 3)``````

This example shows how to retrieve the parent indexes from a reshaped array `A`.

2. Get parent indexes from a subarray view:
``````julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> B = view(A, 2:3, 1:2);
julia> parentindexes(B)
6-element Array{CartesianIndex{2},1}:
CartesianIndex(2, 1)
CartesianIndex(3, 1)
CartesianIndex(2, 2)
CartesianIndex(3, 2)``````

In this example, the `parentindexes` function is used to obtain the parent indexes from a subarray view `B`.

Note: The `CartesianIndex` type represents a multi-dimensional index.

If the array view `A` is not provided or is empty, the `parentindexes` function will return an empty array.