Programming, Cplusplus.
use a 1-D buffer for storing data, and a mapping function that given the N-D index of an element, computes its location in the 1-D buffer. In the case of a matrix, elements in the same row are stored contiguously, and rows are stored one after the other in the 1-D buffer. For 3-D tensors, matrices