gtensor icon indicating copy to clipboard operation
gtensor copied to clipboard

add lower bound to view or as an adapt option

Open bd4 opened this issue 3 years ago • 1 comments

Suggested by @td-mpcdf. My understanding is that this would just be an offset, so if lbound=9, the range [10,20] would actually be [1,11] on the physical array. Basically lbound is subtracted from all indexes. Is this the desired behavior? @germasch do you think this makes sense for gtensor?

This could be it's own view type, or a new view parameter. Or something specific to gt::adapt and gt::adapt_device, which is where it wold be used in GENE, but these seems like an odd place to put the functionality when looking at gtensor as a whole.

bd4 avatar Jan 27 '22 22:01 bd4

Because of how many places contain index calculations, this would likely most easily be done with a new wrapper class, something like gt::lbound_view(E&& expr, gt::shape_type lbounds) that proxies all requests to the underlying expression, and provides an alternate operator() implementation that subtracts the specified lbounds in each dimension before passing on to the underlying expression. Unfortunately the "proxy everything else to the underlying expression" part requires some C++ template meta programming and knowledge of which parts are necessary for the new object to behave like a full expression. Note also that the reduction API does not currently work with arbitrary expressions - it only works with containers (so it's basically can't be combined into lazy expressions). This means that an lbound_view could not be used directly with reductions - it would have to be evaluated first, just like for other views.

bd4 avatar Jan 28 '22 18:01 bd4