Add matrix/vector array reshaping helpers#3312
Add matrix/vector array reshaping helpers#3312fatimmajumder wants to merge 2 commits intostan-dev:developfrom
Conversation
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 informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
Summary
Fixes #3233.
This PR adds the remaining reshaping helpers requested in the issue:
to_matrix(std::vector<Eigen::Matrix<T, Eigen::Dynamic, 1>>)for array-of-column-vector reshapingto_vector_array(matrix)to_row_vector_array(matrix)The existing array-of-row-vector
to_matrixoverload was already present, so this PR leaves that behavior unchanged and adds tests for it.The implemented semantics are:
result(i, j) = x[j](i)Empty top-level arrays follow existing
to_matrixbehavior and return0 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