add windows template specialization

release/4.3a0
Tal Regev 2023-12-31 23:19:29 +02:00
parent 2971d9e74e
commit 8023df456d
2 changed files with 53 additions and 3 deletions

View File

@ -166,9 +166,6 @@ jobs:
bash .github/scripts/python.sh -b
- name: Test
# Disable running tests for windows because some of them are failing.
# Remove this condition when you want to run tests on windows CI.
if: runner.os != 'Windows'
shell: bash
run: |
bash .github/scripts/python.sh -t

View File

@ -197,6 +197,59 @@ namespace gtsam {
}
};
#ifdef _WIN32
// Handle dynamic matrices
template <int M, int N>
struct handle_matrix<Eigen::Matrix<double, M, N, 0, M, N>, true> {
inline Eigen::Matrix<double, M, N> operator()(Key j, const Value* const pointer) {
auto ptr = dynamic_cast<const GenericValue<Eigen::Matrix<double, M, N>>*>(pointer);
if (ptr) {
// value returns a const Matrix&, and the return makes a copy !!!!!
return ptr->value();
} else {
// If a fixed matrix was stored, we end up here as well.
throw ValuesIncorrectType(j, typeid(*pointer), typeid(Eigen::Matrix<double, M, N>));
}
}
};
// Handle fixed matrices
template <int M, int N>
struct handle_matrix<Eigen::Matrix<double, M, N, 0, M, N>, false> {
inline Eigen::Matrix<double, M, N> operator()(Key j, const Value* const pointer) {
auto ptr = dynamic_cast<const GenericValue<Eigen::Matrix<double, M, N>>*>(pointer);
if (ptr) {
// value returns a const MatrixMN&, and the return makes a copy !!!!!
return ptr->value();
} else {
Matrix A;
// Check if a dynamic matrix was stored
auto ptr = dynamic_cast<const GenericValue<Eigen::MatrixXd>*>(pointer);
if (ptr) {
A = ptr->value();
} else {
// Or a dynamic vector
A = handle_matrix<Eigen::VectorXd, true>()(j, pointer); // will throw if not....
}
// Yes: check size, and throw if not a match
if (A.rows() != M || A.cols() != N)
throw NoMatchFoundForFixed(M, N, A.rows(), A.cols());
else
return A; // copy but not malloc
}
}
};
// Handle matrices
template <int M, int N>
struct handle<Eigen::Matrix<double, M, N, 0, M, N>> {
Eigen::Matrix<double, M, N> operator()(Key j, const Value* const pointer) {
return handle_matrix<Eigen::Matrix<double, M, N, 0, M, N>,
(M == Eigen::Dynamic || N == Eigen::Dynamic)>()(j, pointer);
}
};
#endif // #ifdef _WIN32
} // internal
/* ************************************************************************* */