Proposing Tpetra::subview, a flexible free function which returns a view of a existing Tpetra::MultiVector in the spirit of Kokkos::subview
Created by: Novermars
At this moment, Tpetra::MultiVector offers the member methods MultiVector::subView(NonConst) and MultiVector::offsetView(NonConst). I would like to propose a new free function Tpetra::subview which generalizes these two functions.
First of all, why a free function instead of a member method: There are a couple of reasons, first and foremost, there already is a subView member method, as described above. Secondly, Kokkos uses a free function Kokkos::subview. Having Tpetra be consistent with Kokkos, then it would be easier for users to use both libraries. And finally, MultiVector already has a great number of member methods. Adding more would is something that might be preferred to be prevented.
In my mind, I had the following interface:
namespace Tpetra
{
using MV = typename Tpetra::MultiVector;
MV subview(MV const& mvec, std::pair<int, int> rowRange,
std::pair<int, int> colRange);
}
The aforementioned member method all return a Teuchos::RCP to a MV, but since Kokkos::subview returns a Kokkos::view, I opted to be consistent with Kokkos. This can be changed of course.
Unfortunately, the mentioned interface does not support noncontiguous rows or columns. A possible solution would be an overload taking two tuples with indices of the requested rows and/or columns.
And just like with Kokkos, it would be nice to have an "all rows/cols" tag, just like Kokkos::ALL().
Let me know what you think!