Search code examples
c++functionnaming

Name of a transversal reduction operation?


I am currently writing a highly templated C++ helper class for vectorized operations and I need a name for a specific operation.

I have already 2 functions with very common names taken from vectorial languages :

  • apply() which apply a function to each element of a vector
  • reduce() which apply a reduction operation over the vector and returns a scalar

Now I would like to implement another function, which is a mix between these two : it takes several vectors as an input, and apply a reduction operation over each line, and returns a vector.

To illustrate that, we have :

  • apply(func, vec) -> returns {func(vec[0]), func(vec[1]), ..., func(vec[n])}
  • reduce(func, vec) -> returns func(vec[0], vec[1], ..., vec[n])

and :

  • something(func, vec1, vec2, ..., vecn) -> returns {func(vec0[0], vec1[0], ..., vecn[0]), func(vec0[1], vec1[1], ..., vecn[1]), ..., func(vec0[n], vec1[n], ..., vecn[n])}

What would be a common name for this function (a simple verb like apply or reduce) (compatible with other vectorial languages if such a function exists) ?


Solution

  • Maybe zip_with which I've seen used from Haskell?