array icon indicating copy to clipboard operation
array copied to clipboard

Need a version of generate() that takes indices

Open jiawen opened this issue 4 years ago • 2 comments

generate() works like std::generate() and needs to maintain state elsewhere. It'd be nice to have a function that does a fill based on "pattern function" that takes in indices instead:

Equivalent to something like:

for_each_index(image.shape(), [&](const typename Shape::index_type& i) {
  image(i) = std::apply(pattern, i);
});

jiawen avatar Sep 14 '21 22:09 jiawen

I don't have any good names though. fill() is already taken. fill_with_pattern? What's the dual of enumerate?

jiawen avatar Sep 14 '21 22:09 jiawen

We might be able to just overload fill?

dsharlet avatar Sep 14 '21 22:09 dsharlet

Implemented in #69 as transform_index and transform_indices.

jiawen avatar Dec 21 '22 17:12 jiawen