Bugzilla – Attachment 327 Details for
Bug 564
maxCoeff() returns -nan instead of max, while maxCoeff(&maxRow, &maxCol) works
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
Add hasNaN and isFinite members.
Bug564_hasNaN.diff (text/plain), 5.57 KB, created by
Gael Guennebaud
on 2013-04-09 23:01:13 UTC
(
hide
)
Description:
Add hasNaN and isFinite members.
Filename:
MIME Type:
Creator:
Gael Guennebaud
Created:
2013-04-09 23:01:13 UTC
Size:
5.57 KB
patch
obsolete
># HG changeset patch ># Parent cd15b09304ff115a71df02672f13ea1c0110ee4d >Big 564: add hasNaN and isFinite members > >diff --git a/Eigen/src/Core/BooleanRedux.h b/Eigen/src/Core/BooleanRedux.h >--- a/Eigen/src/Core/BooleanRedux.h >+++ b/Eigen/src/Core/BooleanRedux.h >@@ -124,11 +124,31 @@ inline bool DenseBase<Derived>::any() co > * \sa all(), any() > */ > template<typename Derived> > inline typename DenseBase<Derived>::Index DenseBase<Derived>::count() const > { > return derived().template cast<bool>().template cast<Index>().sum(); > } > >+/** \returns true is \c *this contains at least one Not A Number (NaN). >+ * >+ * \sa isFinite() >+ */ >+template<typename Derived> >+inline bool DenseBase<Derived>::hasNaN() const >+{ >+ return !((derived().array()==derived().array()).all()); >+} >+ >+/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. >+ * >+ * \sa hasNaN() >+ */ >+template<typename Derived> >+inline bool DenseBase<Derived>::isFinite() const >+{ >+ return !((derived()-derived()).hasNaN()); >+} >+ > } // end namespace Eigen > > #endif // EIGEN_ALLANDANY_H >diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h >--- a/Eigen/src/Core/DenseBase.h >+++ b/Eigen/src/Core/DenseBase.h >@@ -331,16 +331,19 @@ template<typename Derived> class DenseBa > template<typename OtherDerived> > bool isMuchSmallerThan(const DenseBase<OtherDerived>& other, > const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; > > bool isApproxToConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; > bool isConstant(const Scalar& value, const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; > bool isZero(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; > bool isOnes(const RealScalar& prec = NumTraits<Scalar>::dummy_precision()) const; >+ >+ inline bool hasNaN() const; >+ inline bool isFinite() const; > > inline Derived& operator*=(const Scalar& other); > inline Derived& operator/=(const Scalar& other); > > typedef typename internal::add_const_on_value_type<typename internal::eval<Derived>::type>::type EvalReturnType; > /** \returns the matrix or vector obtained by evaluating this expression. > * > * Notice that in the case of a plain matrix or vector (not an expression) this function just returns >@@ -410,18 +413,16 @@ template<typename Derived> class DenseBa > /** \returns the unique coefficient of a 1x1 expression */ > CoeffReturnType value() const > { > EIGEN_STATIC_ASSERT_SIZE_1x1(Derived) > eigen_assert(this->rows() == 1 && this->cols() == 1); > return derived().coeff(0,0); > } > >-/////////// Array module /////////// >- > bool all(void) const; > bool any(void) const; > Index count() const; > > typedef VectorwiseOp<Derived, Horizontal> RowwiseReturnType; > typedef const VectorwiseOp<const Derived, Horizontal> ConstRowwiseReturnType; > typedef VectorwiseOp<Derived, Vertical> ColwiseReturnType; > typedef const VectorwiseOp<const Derived, Vertical> ConstColwiseReturnType; >diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt >--- a/test/CMakeLists.txt >+++ b/test/CMakeLists.txt >@@ -217,16 +217,17 @@ ei_add_test(sparse_permutations) > ei_add_test(nullary) > ei_add_test(nesting_ops "${CMAKE_CXX_FLAGS_DEBUG}") > ei_add_test(zerosized) > ei_add_test(dontalign) > ei_add_test(evaluators) > ei_add_test(sizeoverflow) > ei_add_test(prec_inverse_4x4) > ei_add_test(vectorwiseop) >+ei_add_test(special_numbers) > > ei_add_test(simplicial_cholesky) > ei_add_test(conjugate_gradient) > ei_add_test(bicgstab) > ei_add_test(sparselu) > ei_add_test(sparseqr) > > # ei_add_test(denseLM) >diff --git a/test/special_numbers.cpp b/test/special_numbers.cpp >new file mode 100644 >--- /dev/null >+++ b/test/special_numbers.cpp >@@ -0,0 +1,59 @@ >+// This file is part of Eigen, a lightweight C++ template library >+// for linear algebra. >+// >+// Copyright (C) 2013 Gael Guennebaud <gael.guennebaud@inria.fr> >+// >+// This Source Code Form is subject to the terms of the Mozilla >+// Public License v. 2.0. If a copy of the MPL was not distributed >+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. >+ >+#include "main.h" >+ >+template<typename Scalar> void special_numbers() >+{ >+ typedef typename NumTraits<Scalar>::Real RealScalar; >+ typedef Matrix<Scalar, Dynamic,Dynamic> MatType; >+ int rows = internal::random<int>(1,300); >+ int cols = internal::random<int>(1,300); >+ >+ Scalar nan = Scalar(0)/Scalar(0); >+ Scalar inf = Scalar(1)/Scalar(0); >+ Scalar s1 = internal::random<Scalar>(); >+ >+ MatType m1 = MatType::Random(rows,cols), >+ mnan = MatType::Random(rows,cols), >+ minf = MatType::Random(rows,cols), >+ mboth = MatType::Random(rows,cols); >+ >+ int n = internal::random<int>(1,10); >+ for(int k=0; k<n; ++k) >+ { >+ mnan(internal::random<int>(0,rows-1), internal::random<int>(0,cols-1)) = nan; >+ minf(internal::random<int>(0,rows-1), internal::random<int>(0,cols-1)) = inf; >+ } >+ mboth = mnan + minf; >+ >+ VERIFY(!m1.hasNaN()); >+ VERIFY(m1.isFinite()); >+ >+ VERIFY(mnan.hasNaN()); >+ VERIFY((s1*mnan).hasNaN()); >+ VERIFY(!minf.hasNaN()); >+ VERIFY(!(2*minf).hasNaN()); >+ VERIFY(mboth.hasNaN()); >+ VERIFY(mboth.array().hasNaN()); >+ >+ VERIFY(!mnan.isFinite()); >+ VERIFY(!minf.isFinite()); >+ VERIFY(!(minf-mboth).isFinite()); >+ VERIFY(!mboth.isFinite()); >+ VERIFY(!mboth.array().isFinite()); >+} >+ >+void test_special_numbers() >+{ >+ for(int i = 0; i < 10*g_repeat; i++) { >+ CALL_SUBTEST_1( special_numbers<float>() ); >+ CALL_SUBTEST_1( special_numbers<double>() ); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
gael.guennebaud
:
review?
Actions:
View
|
Diff
Attachments on
bug 564
: 327