Re: [multi] Formal Review Begins

Andrzej Krzemienski via Boost <[email protected]>
Newsgroups gmane.comp.lib.boost.devel
Message-ID <CAOenAXgcNZHsL4aG5Hp0S-2VndJKjpC5XLYaFz=-tDXjaoDOyw@mail.gmail.com>
sob., 7 mar 2026 o 10:58 Rainer Deyke via Boost <[email protected]>
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

Regards,
&rzej;
_______________________________________________
Boost mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/[email protected]/message/CBSWXVSCTKTEAWZHK5K25PVLFBM65X2U/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.