Skip to content
Snippets Groups Projects

[hybrid] Allow dune-istl MultiBlock types as ranges in forEach

Closed Timo Koch requested to merge feature/hybrid-allow-istl-multiblocktypes-as-ranges into master

Currently MultiTypeBlockMatrix can be used as a range in forEach

using namespace Dune::Hybrid;
forEach(m, [](auto& row){
   ...
});

because it has a static constexpr member function size. However, size is deprecated in favour of N. This MR attempt at removing the deprecation warning (because N is looked for first) and also allow types that use a static constexpr member function N to be interpreted as range in the sense of Hybrid::forEach.

Merge request reports

Pipeline #26404 passed

Closed by Timo KochTimo Koch 4 years ago (Mar 31, 2021 2:35am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Are you sure about the meaning of size() for matrices to be the number of rows? In many libraries matrix-size is number of rows times number of columns. What, if you have column-major ordering?

    I would suggest a slightly different design, e.g.

    using namespace Dune::Hybrid;
    MultiTypeBlockMatrix<...> m(...);
    forEach(rows(m), [](auto& row){
       ...
    });

    or m.rows(), or if you just want to have traversal of the major-dimension: m.asTuple(). The specialization of size() for tuples does not kick in, since the matrix is just derived from tuple, but not the tuple type itself. So, one could also just add a specialization of std::tuple_size for multi-type matrices instead.

  • Author Owner

    ok yeah maybe this is stupid. I mean I can also do

    using namespace Dune::Hybrid;
    forEach(integralRange(M::N()), [](auto& i){
       auto& row = m[i];
       ...
    });

    In my case I'm actually not interested in the hybridness of the forEach. I just want a compile time loop.

  • While it's slightly inconvenient I'd not like to have a specialization for ::N() here. While size() has a generic meaning (motivated by the STL) this is not the case for ::N(). forEach is for iterating over ranges and extends the range concept to statically sized multi-type ranges using static constexpr size(). If your class does not provide size(), then it's neither a container nor a range in the classical or extended sense.

    This also applies to MultiTypeBlockMatrix. Unfortunately, I somehow missed the deprecation of size(). In fact I think it's a pretty bad idea, especially because it's replaced by a one-letter method whose introduction was a bad idea, too.

  • I like @simon.praetorius' suggestion to provide ranges using rows(matrix).

  • Unfortunately, I somehow missed the deprecation of size(). In fact I think it's a pretty bad idea.

    It was me who did the deprecation, but I have no strong opinions about it. We can decide to un-deprecate it anytime.

  • mentioned in merge request dune-istl!424 (merged)

  • There is a proposal now in dune-istl: dune-istl!425

  • Can we close this MR?

  • closed

Please register or sign in to reply
Loading