Provide isFinite() and isNan() functions
It would be convenient to have functions that check whether a matrix/vector is finite or NaN, analogous to std::isfinite()
and std::isnan()
:
blaze::DynamicVector<double> v {std::numeric_limits<double>::infinity(), 42.};
blaze::DynamicVector<double> v1 {0., 42.};
blaze::DynamicMatrix<double> m {{1., 2.}, {std::numeric_limits<double>::quiet_NaN(), 3.}};
assert(!isFinite(v));
assert(!isNaN(v));
assert(isFinite(v));
assert(!isNaN(v));
assert(!isFinite(m));
assert(isNaN(m));
Comments (6)
-
-
Hi Misha!
After doing some research we decided to also add the two functions
isfinite()
(named after the C++ isfinite() function; the function you initially asked for) andisnormal()
(named after C++ isnormal()). Thanks again,Best regards,
Klaus!
-
reporter Great, thank you!
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Summary
The
isinf()
andisfinite()
functions have been added for dense and sparse vectors and dense and sparse matrices. The feature is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.8.isinf()
The
isinf()
function checks the given dense or sparse vector or dense and sparse matrix for infinite (inf
) elements:blaze::DynamicVector<double> a; // ... Resizing and initialization if( isinf( a ) ) { ... }
blaze::DynamicMatrix<double> A; // ... Resizing and initialization if( isinf( A ) ) { ... }
If at least one element of the vector or matrix is infinite, the function returns
true
, otherwise it returnsfalse
.isfinite()
The
isfinite()
function checks if all elements of the given dense or sparse vector or dense or sparse matrix are finite elements (i.e. normal, subnormal or zero elements, but not infinite or NaN):blaze::DynamicVector<double> a; // ... Resizing and initialization if( isfinite( a ) ) { ... }
blaze::DynamicMatrix<double> A; // ... Resizing and initialization if( isfinite( A ) ) { ... }
If all elements of the vector are finite, the function returns
true
, otherwise it returnsfalse
. - Log in to comment
Hi Misha!
Thanks for creating this issue. I have good news with respect to a
isnan()
function: Such a function already exists for both vectors and matrices. I admit that the name is not chosen according to Blaze naming conventions, but it is consistent with the C++ standard function isnan().What is still missing is a function based on the C++ standard function isinf(). We will make sure to also add this function for both vectors and matrices. Thanks for pointing out this missing puzzle piece,
Best regards,
Klaus!