On 3/7/26 22:41, Andrzej Krzemienski via Boost wrote:
sob., 7 mar 2026 o 10:58 Rainer Deyke via Boost <boost@lists.boost.org> napisaĆ(a):
On 3/5/26 14:26, Matt Borland via Boost wrote:
Multi is a modern C++ library that provides manipulation and access of data in multidimensional arrays for both CPU and GPU memory. I have my own multidimensional array type that I use extensively, so I thought it would be interesting to compare my own efforts to the proposed library.
The proposed library uses an array-of-arrays model. By contrast, my own library uses an array-indexed-by-vector model. This makes iteration a lot more convenient with my type. I do a lot of iteration in my own code, so this is kind of a big deal. Compare:
My multi_array type:
multi_array<int, 2> a({5, 2}); for (auto &element: a) { element = 5; } for (auto index: a.get_bounds()) { a[index] = get<0>(index) + get<1>(index) * 10; }
The proposed library:
multi::array<int, 2> a({5, 2}); for (auto &row: a) { for (auto &element: row) { element = 5; } } auto [rows, columns] = a.extensions(); for (auto row_index: rows) { for (auto column_index: columns) { a[row_index][column_index] = row_index + column_index * 10; } }
On the other hand, Boost.Multi is designed so that one usually doesn't need to do manual iteration. Your examples can be expressed as:
multi::array<int, 2> a({5, 2}, 5); // start with 5's std::ranges::fill(a.elements(), 6); // fill with 6's multi::array<int, 2> b = restricted([](int i, int j) { return i * j * 10; }, multi::extensions_t{5, 2}); // start with index-dependent values
That's great for these trivial examples, which I based on similar trivial examples in the Boost.Multi documentation. Not so much if I'm trying to run a Gaussian blur on my data. Or run a cellular automaton. Or even just render a 2D tile map on the screen. -- Rainer Deyke - rainerd@eldwood.com