kiwaku
kiwaku copied to clipboard
[FEATURE] General 'simultaneous static&dynamic' ops on axes
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:
- merge two shapes (example an add operation): verify that the two shapes are the same (mathematically) and produce a new one which maximizes compile time information from both input shapes (e.g. one can have a fixed 2nd axis while the other a fixed 3rd axis so the result should have two fixed axes)
- concatenation of two shapes across an axis - you have to perform the addition in ct and rt space (and again maximize ct information)
- reshaping with a placeholder/free axis (this is an operation in itself that you could add to the library)
- what convolutions (in ml space) do with their inputs - for in[N, H, W, C] - the N gets forwarded while H and W get forwarded if padding is on, otherwise they are slightly reduced and input C is fully replaced with a different value etc....
So provide a generic way (which compiles today ;P) to specify and perform these operations w/o duplication ;D
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.
cool thanks will try it...once <...> works and i can compile ;D
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)