mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +08:00
Fix stableNorm when input is zero-sized.
This commit is contained in:
parent
c29a410116
commit
b2814d53a7
@ -55,6 +55,10 @@ typename MatrixType::RealScalar stable_norm_impl(const MatrixType& mat) {
|
|||||||
RealScalar invScale(1);
|
RealScalar invScale(1);
|
||||||
RealScalar ssq(0); // sum of squares
|
RealScalar ssq(0); // sum of squares
|
||||||
|
|
||||||
|
if (mat.size() == 0) {
|
||||||
|
return RealScalar(0);
|
||||||
|
}
|
||||||
|
|
||||||
stable_norm_kernel(mat, ssq, scale, invScale);
|
stable_norm_kernel(mat, ssq, scale, invScale);
|
||||||
return scale * sqrt(ssq);
|
return scale * sqrt(ssq);
|
||||||
}
|
}
|
||||||
|
@ -209,6 +209,11 @@ void stable_norm(const MatrixType& m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_empty() {
|
||||||
|
Eigen::VectorXf empty(0);
|
||||||
|
VERIFY_IS_EQUAL(empty.stableNorm(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Scalar>
|
template <typename Scalar>
|
||||||
void test_hypot() {
|
void test_hypot() {
|
||||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
@ -235,6 +240,8 @@ void test_hypot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DECLARE_TEST(stable_norm) {
|
EIGEN_DECLARE_TEST(stable_norm) {
|
||||||
|
CALL_SUBTEST_1(test_empty());
|
||||||
|
|
||||||
for (int i = 0; i < g_repeat; i++) {
|
for (int i = 0; i < g_repeat; i++) {
|
||||||
CALL_SUBTEST_3(test_hypot<double>());
|
CALL_SUBTEST_3(test_hypot<double>());
|
||||||
CALL_SUBTEST_4(test_hypot<float>());
|
CALL_SUBTEST_4(test_hypot<float>());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user