| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Adds array-of-column-vector to_matrix support and matrix-to-vector-array reshaping helpers for stan-dev#3233, with unit and targeted header tests.
Jenkins Console Log Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: G++: Clang: |
Sorry, something went wrong.
| * @return the matrix representation of the input | ||
| */ | ||
| template <typename T> | ||
| inline Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> to_matrix( |
There was a problem hiding this comment.
@WardBrian I think for std::vector<Eigen::Matrix<T, Eigen::Dynamic, 1>> we need to have a to_row_matrix and to_col_matrix so that the user can tell us if the vectors in the array are the rows or columns. Do you have thoughts about this?
Sorry, something went wrong.
There was a problem hiding this comment.
Wouldn't they just be providing std::vector<Eigen::Matrix<T, 1, Eigen::Dynamic>> in that case?
Sorry, something went wrong.
There was a problem hiding this comment.
Oh I did not think of that. So an array of row vectors would essentially be calling to_row_matrix and an array of column vectors would be use to_col_matrix
Sorry, something went wrong.
There was a problem hiding this comment.
@fatimmajumder so this function is currently only works for array vector. We want this function to take in a standard vector with row or column vectors and then use if constexpr (...) to dispatch to make a rowwise or columnwise matrix based on the input type.
Sorry, something went wrong.
There was a problem hiding this comment.
@SteveBronder there already is an overload for array row_vector pre-existing
Sorry, something went wrong.
| */ | ||
| template <typename EigMat, require_eigen_t<EigMat>* = nullptr> | ||
| inline std::vector<Eigen::Matrix<value_type_t<EigMat>, Eigen::Dynamic, 1>> | ||
| to_vector_array(const EigMat& matrix) { |
There was a problem hiding this comment.
| to_vector_array(const EigMat& matrix) { | |
| to_col_vector_array(const EigMat& matrix) { |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #3233.
This PR adds the remaining reshaping helpers requested in the issue:
The existing array-of-row-vector to_matrix overload was already present, so this PR leaves that behavior unchanged and adds tests for it.
The implemented semantics are:
Empty top-level arrays follow existing to_matrix behavior and return 0 x 0. Zero-length contained vectors preserve the inferable dimension.
Tests
Passed locally:
Also passed targeted header tests:
I did not run the complete make test-headers; I started it, but it was traversing unrelated forward-mode headers, so I stopped it and ran the targeted header isolation tests above instead.
Side Effects
No intentional side effects.
I intentionally did not add ragged-vector validation because the existing array-of-row-vector overload does not appear to validate ragged inputs either, and I did not want to introduce a new policy for only one direction of the reshape.
Release notes
Adds reshaping helpers for converting between matrices and arrays of Eigen vectors/row vectors.
Checklist