jfalcou / kiwaku

C++20 and onward collection of high performance data containers and related tools
https://jfalcou.github.io/kiwaku
Boost Software License 1.0
51 stars 5 forks source link

[FEATURE] General 'simultaneous static&dynamic' ops on axes #107

Open psiha opened 1 year ago

psiha commented 1 year ago

I often have a need to perform some transformation on a shape (or a pair of shapes) (implicitly when doing transformations on an ndarray which affects its shape) - and when we have the ability to have both static and dynamic ones I usually have to duplicate the logic. Some motivating examples:

So provide a generic way (which compiles today ;P) to specify and perform these operations w/o duplication ;D

jfalcou commented 1 year ago

Note while I'm looking at that: the static size can be specififed via kwk::fixed<N> and this typ esupports static-compatible +-*/ so fixed+fixed is still a fixed. When used as parameters to of_size, it will do the correct thing.

So:

auto add_shape(auto s1, auto s2)
{
  return of_size( kumi::map( [](auto a, auto b) { return a+b; }, s1, s2);
}

should work with mixed size with no extra work.

Maybe this can help.

psiha commented 1 year ago

cool thanks will try it...once <...> works and i can compile ;D

psiha commented 1 year ago

tried it with the current code with a simple example:

kwk::shape<_> shape_d;
kwk::shape<kwk::width[ 5 ]> shape_s;
auto z = kumi::map( []( auto a, auto b ) { return a + b; }, shape_d, shape_s );

and z is a plain kumi::tuple<int> - so both parts of compile time info are lost (width type and size 5) (and it is no longer shape but a plain tuple)