Skip to content

Commit

Permalink
Merge pull request #2670 from stan-dev/fix_to_matrix
Browse files Browse the repository at this point in the history
Fix for to_matrix(row_vector) and to_matrix(vector)
  • Loading branch information
rok-cesnovar authored Mar 2, 2022
2 parents 01dd2e7 + ca95b16 commit ca8cd94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
21 changes: 8 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,7 @@ pipeline {
}

stage('Full Unit Tests') {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
}
}
agent { label 'gg-linux' }
when {
expression {
!skipRemainingStages
Expand All @@ -257,17 +252,17 @@ pipeline {
steps {
unstash 'MathSetup'
// Set Stan local compiler flags to use the new TBB interface
sh """
export TBB_INC=\$(pwd)/lib/tbb_2020.3/include
export TBB_LIB=\$(pwd)/lib/tbb
echo TBB_INTERFACE_NEW=true > make/local
"""
// sh """
// export TBB_INC=\$(pwd)/lib/tbb_2020.3/include
// export TBB_LIB=\$(pwd)/lib/tbb
// echo TBB_INTERFACE_NEW=true > make/local
// """
sh "echo CXXFLAGS += -fsanitize=address >> make/local"
script {
if (isUnix()) {
runTests("test/unit/math/test_ad_test.cpp", false)
runTests("test/unit", false)
} else {
runTestsWin("test/unit/math/test_ad_test.cpp", true)
runTestsWin("test/unit", true)
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions stan/math/prim/fun/to_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,35 @@ namespace math {

/**
* Returns a matrix with dynamic dimensions constructed from an
* Eigen matrix which is either a row vector, column vector,
* or matrix.
* The runtime dimensions will be the same as the input.
* Eigen matrix.
*
* @tparam EigMat type of the matrix
*
* @param x matrix
* @return the matrix representation of the input
*/
template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
template <typename EigMat, require_eigen_dense_dynamic_t<EigMat>* = nullptr>
inline EigMat to_matrix(EigMat&& x) {
return std::forward<EigMat>(x);
}

/**
* Returns a matrix with dynamic dimensions constructed from an
* Eigen row or column vector.
* The runtime dimensions will be the same as the input.
*
* @tparam EigMat type of the vector/row vector
*
* @param x input vector/row vector
* @return the matrix representation of the input
*/
template <typename EigVec, require_eigen_vector_t<EigVec>* = nullptr>
inline auto to_matrix(EigVec&& matrix) {
return Eigen::Matrix<
value_type_t<EigVec>,
Eigen::Dynamic, Eigen::Dynamic>(std::forward<EigVec>(matrix));
}

/**
* Returns a matrix representation of a standard vector of Eigen
* row vectors with the same dimensions and indexing order.
Expand Down

0 comments on commit ca8cd94

Please sign in to comment.