-
Notifications
You must be signed in to change notification settings - Fork 302
Eigen subvector support, unit tests #4415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from all commits
4bb6ee3
8e3a323
b52cca0
8b3c77c
9f91b86
f766c8a
8b94269
29ce670
2d4895c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,6 +426,57 @@ void EigenSparseVector<T>::pointwise_divide (const NumericVector<T> & /*vec1*/, | |
| } | ||
|
|
||
|
|
||
|
|
||
| template <typename T> | ||
| void EigenSparseVector<T>::create_subvector(NumericVector<T> & subvector, | ||
| const std::vector<numeric_index_type> & rows, | ||
| const bool /* supplying_global_rows */) const | ||
| { | ||
| // Make sure the passed in subvector is really an EigenSparseVector | ||
| EigenSparseVector<T> * eigen_subvector = cast_ptr<EigenSparseVector<T> *>(&subvector); | ||
|
|
||
| // If the eigen_subvector is already initialized, we assume that the | ||
| // user has already allocated the *correct* amount of space for it. | ||
| // If not, we do so. | ||
| if (!eigen_subvector->initialized()) | ||
| eigen_subvector->init(rows.size()); | ||
|
|
||
| eigen_subvector->vec() = this->vec()(rows); | ||
|
|
||
| eigen_subvector->_is_closed = true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| template <typename T> | ||
| std::unique_ptr<NumericVector<T>> | ||
| EigenSparseVector<T>::get_subvector(const std::vector<numeric_index_type> & rows) | ||
| { | ||
| auto returnval = std::make_unique<EigenSparseVector<T>>(this->comm(), rows.size()); | ||
|
|
||
| // We're just going to make a copy here, since we'll be calling a | ||
| // restore later anyway. Someone with more familiarity with Eigen | ||
| // can see if there's a way to improve this later. | ||
| this->create_subvector(*returnval, rows); | ||
|
|
||
| this->_is_closed = false; | ||
|
|
||
| return returnval; | ||
| } | ||
|
|
||
| template <typename T> | ||
| void | ||
| EigenSparseVector<T>::restore_subvector(std::unique_ptr<NumericVector<T>> subvector, | ||
| const std::vector<numeric_index_type> & rows) | ||
| { | ||
| auto * const eigen_subvector = cast_ptr<EigenSparseVector<T> *>(subvector.get()); | ||
|
|
||
| this->vec()(rows) = eigen_subvector->vec(); | ||
| this->_is_closed = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, should we mark
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're basically not supposed to touch the original vector until the subvector is restored, right? Marking it non-closed would make that misuse subject to a whole bunch more assertions. I'll do it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops - you already did it in the PETSc version. I just missed that when I was implementing here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we assert that we're already closed when we
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea I think that's a good idea |
||
| } | ||
|
|
||
|
|
||
|
|
||
| template <typename T> | ||
| Real EigenSparseVector<T>::max() const | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.