fix(math): preflight finite dense operands at dispatch boundary
This commit is contained in:
@@ -31,7 +31,7 @@ class ScopedSingleEquationThreads {
|
||||
Result<MKL_INT> ToMklSize(std::size_t size);
|
||||
|
||||
/// @brief Computes left-transpose times right through ordinary dense MKL.
|
||||
/// @throws std::invalid_argument if the row counts differ.
|
||||
/// @throws std::invalid_argument for mismatched rows or nonfinite operands.
|
||||
Matrix MultiplyTransposeLeft(const Matrix& left, const Matrix& right);
|
||||
|
||||
/// @brief Multiplies a compact diagonal matrix by a vector through MKL.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "fesa/math/matrix.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <mkl.h>
|
||||
|
||||
#include <limits>
|
||||
@@ -107,6 +108,12 @@ Vector Matrix::Multiply(const Vector& rhs) const {
|
||||
throw std::invalid_argument{
|
||||
"Matrix-vector multiplication has incompatible dimensions."};
|
||||
}
|
||||
for (const double value : values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
for (std::size_t i = 0; i < rhs.Size(); ++i)
|
||||
if (!std::isfinite(rhs.Data()[i]))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
|
||||
Vector result{rows_};
|
||||
if (rows_ == 0 || columns_ == 0) {
|
||||
@@ -126,6 +133,12 @@ Matrix Matrix::Multiply(const Matrix& rhs) const {
|
||||
throw std::invalid_argument{
|
||||
"Matrix multiplication has incompatible dimensions."};
|
||||
}
|
||||
for (const double value : values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
for (const double value : rhs.values_)
|
||||
if (!std::isfinite(value))
|
||||
throw std::invalid_argument{"Matrix product inputs must be finite."};
|
||||
|
||||
Matrix result{rows_, rhs.columns_};
|
||||
if (rows_ == 0 || columns_ == 0 || rhs.columns_ == 0) {
|
||||
|
||||
Reference in New Issue
Block a user