map() with nested containers

map() with nested containers

Will you give an example (perhaps trivial) of using map() with nested containers? I have been unsuccessful, getting MSVC complier errors:

...\\include\\arbb\\cpp\\detail\\map_closure_template.hpp(97): error C2440: 'static_cast' : cannot convert...


...\\include\\arbb\\cpp\\detail\\map_closure_template.hpp(137): error C2078: too many initializers

Thank you,
- paul

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


Sorry for not responding to this question sooner. The map() operator does not support nested containers. We just realized that the documentation isn't explicit about this restriction. We will update the documentation to clearly state that, at present, map() only maps across elements in dense containers.

However, if what you want to do is applying an elemental function to all elements in a nested then it should be easy to do. You can flatten the nested container into a 1D dense. Then do a map() on the 1D dense. Last, use reshape_as() to restore the nested shape. Here is a trivial example:

void elemental_function(T& e, f32 f)
e = e * f;

void foobar(nested& out, f32 factor)
dense flattened = out.flatten();
map(elemental_function)(flattened, factor);
out = reshape_as(flattened, out);

Note this does not give you the ability to do stencil computation. For example, neighbor() is still not supported. But I believe this restriction is reasonable because, given that segments in a nested container have different lengths in general, the meaning of "neighbor" isn't always clear and depends on how we perceive the layout of all segments, for example, left-aligned, right-aligned, etc.

Please let us know if this helps. Maybe you can share with us a particular use case where you think map() support for nested is needed. Then, we will try to see if there're better workaround solutions.


Hi Zhang,

It was the complete generality of the documentation that raised my curiosity about the performance of map() for nested containers, not any planned use. While we agree that e.g. neighbor() could be a tricky thing, it seems that nested containers are second-class citizens of ArBB.

Best regards,
- paul

Leave a Comment

Please sign in to add a comment. Not a member? Join today