JuliaSmoothOptimizers / JuliaSmoothOptimizers/PartitionedStructures.jl
Memoryless and parallel evaluation of a partitioned vector WIP
- Dominant language
- Julia
- Stars
- 10
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
Define a structure storing the element contribution for each partitioned gradient component (of size `n`).
The following code is a draft of such a structure
```julia
using StatsBase
n = 6
N = 5
range_indices_component = 1:4
indices_components = map(i -> rand(range_indices_component), 1:n)
element_values_component_rand = map(indices_component -> rand(indices_component), indices_components)
elements_by_component = map(indices_component -> sample(1:N, indices_component, replace = false), indices_components)
res = rand(n)
res1 = map((i,j) -> i = reduce(+, j; init=0.), res, element_values_component_rand)
```
It define a new way to build the partitioned vector `res1` from the nested array.
There is an other nested array, this one from the element perspective.
The following code define a nested array of pairs; its size is `N`.
Each vector of pairs indicate the element components and the index of every elemental contribution in `elements_by_component`:
```julia
is_in(elt) = findall(map(elements -> in(elt, elements), elements_by_component))
components_by_element = map(elt -> is_in(elt),1:N)
pair(element, components) = map(index -> (components[index], findfirst(elt -> elt==element, elements_by_component[components[index]])), 1:length(components))
pair_components_by_element = map(element -> pair(element, components_by_element[element]), 1:N)
```
Then for GPU support we want to set the value of `elements_by_component ` from the element vector (from element gradient) only with map.
`res2` is an example of imbricated map to acces and manipulate the `element_values_component_rand` from `pair_components_by_element`.
````julia
# ::Tuple{Int64, Int64} is mandatory
set_nested_vector(pair_components, element_values_component_undef) = map((component, index)::Tuple{Int64, Int64} -> element_values_component_undef[component][index], pair_components)
res2 = map(pair_components -> set_nested_vector(pair_components, element_values_component_rand), pair_components_by_element)
```
Contributor guide
Assessment
This issue has not been assessed yet.