From 2580b3d25721f3f5c5b1ebdcb3ae76a88b75f28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BRIOL?= Date: Wed, 3 Jul 2024 23:53:45 +0200 Subject: [PATCH] refactor: Improve error handling and shape checking in harmonic_analysis function --- src/library/wave/table.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/library/wave/table.cpp b/src/library/wave/table.cpp index 78fb3da..9281c4b 100644 --- a/src/library/wave/table.cpp +++ b/src/library/wave/table.cpp @@ -332,18 +332,11 @@ auto Table::harmonic_analysis(const Eigen::Ref& h, const DynamicRef& f, const DynamicRef& vu) -> Eigen::VectorXcd { - if (f.rows() != vu.rows() || f.cols() != vu.cols()) { - throw std::invalid_argument( - "f and vu could not be broadcast together with shape (" + - std::to_string(f.rows()) + ", " + std::to_string(f.cols()) + ") (" + - std::to_string(vu.rows()) + ", " + std::to_string(vu.cols()) + ")"); - } - + detail::check_eigen_shape("f", f, "vu", vu); if (h.rows() != f.cols() || h.rows() != vu.cols()) { throw std::invalid_argument( - "f, vu could not be broadcast with h with shape (" + - std::to_string(f.rows()) + ", " + std::to_string(f.cols()) + ") (" + - std::to_string(h.cols()) + ")"); + "f, vu could not be broadcast with h with shape " + + detail::eigen_shape(f) + ", " + detail::eigen_shape(h)); } auto w_size = f.rows(); auto result = Eigen::VectorXcd(w_size); @@ -442,6 +435,7 @@ auto Table::compute_nodal_modulations( const angle::Formulae& formulae) const -> std::tuple { detail::check_eigen_shape("epoch", epoch, "leap_seconds", leap_seconds); + auto f = Eigen::MatrixXd(size(), epoch.size()); auto vu = Eigen::MatrixXd(size(), epoch.size());