dsharlet / array

C++ multidimensional arrays in the spirit of the STL
Apache License 2.0
198 stars 15 forks source link

Better differentiate between ranges and shapes #23

Open dsharlet opened 4 years ago

dsharlet commented 4 years ago

It would be better if shapes/dims and ranges were better differentiated. They are very similar, but differ in the following ways:

  1. shapes/dims have strides, ranges do not.
  2. Typically, one cares more about the min of a range, and the extent of a dim.

A common pattern, e.g. a(b.x(), b.y()), but it's passing the stride of x and y to b's operator(). It doesn't cause problems, but it is messy. A worse example is array b(a.shape()): If b has padding (e.g. if it were the result of a crop), it allocates b with the same padding, which is a surprising behavior.

The second issue manifests in a current ugly minor issue: range(index_t x) is interpreted as a range with a min of x and extent 1, while dim(index_t) is interpreted as a dim with extent 1.

This is a bit of a generalization of #12.