This library provides a multidimensional array class for C++, with the following design goals:
Enable specification of array parameters as compile-time constants, enabling significantly more efficient code generation in some cases.
Provide an API following the conventions of the C++ STL where possible.
Minimal dependencies and requirements (the library is currently a single header file, and depends only on the C++ STL).
The library uses some ideas established in other existing projects, such as numpy, Halide, and Eigen. Array shapes are specified as a list of N dimensions, where each dimension has parameters such as an extent and a stride. Array references and objects use shape objects to map N-dimensional indices to a flat index. N-dimensional indices are mapped to flat offsets with the following formula:
flat_offset = (x0 - min0)*stride0 + (x1 - min1)*stride1 + ... + (xN - minN)*strideN
where:
xN are the indices in each dimension.
minN are the mins in each dimension. The min is the value of the first in-range index in this dimension (the max is minN + extentN - 1).
strideN are the distances in the flat offsets between elements in each dimension.
Arrays efficiently support advanced manipulations like cropping, slicing, and splitting loops, all while preserving compile-time constant parameters when possible. Although it is a heavily templated library, most features do not have significant code size or compile time implications, and incorrect usage generates informative and helpful error messages. Typically, an issue will result in only one error message, located at the site of the problem in user code.
github地址:https://github.com/dsharlet/array