[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #65343] Replace ancient Fortran coding pattern
From: |
Rik |
Subject: |
[Octave-bug-tracker] [bug #65343] Replace ancient Fortran coding pattern with C++ |
Date: |
Wed, 21 Feb 2024 12:53:33 -0500 (EST) |
URL:
<https://savannah.gnu.org/bugs/?65343>
Summary: Replace ancient Fortran coding pattern with C++
Group: GNU Octave
Submitter: rik5
Submitted: Wed 21 Feb 2024 09:53:33 AM PST
Category: Coding Style and Maintenance
Severity: 2 - Minor
Priority: 5 - Normal
Item Group: Other
Status: Confirmed
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Release: dev
Discussion Lock: Any
Operating System: Any
Fixed Release: None
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Wed 21 Feb 2024 09:53:33 AM PST By: Rik <rik5>
In the liboctave/array directory there are multiple instances of a
Fortran-like code pattern used to detect if a matrix is singular based on the
condition number returned from LAPACK.
An example from dMatrix.cc is
// Prevent use of extra precision.
double rcond_plus_one = rcon + 1.0;
if (rcond_plus_one == 1.0 || octave::math::isnan (rcon))
The idea is that any extra precision, such as from using an x87 math
co-processor, will be lost by the forced addition of 1.0 and so if the
condition number was very small, but not 0, it will now be detected as 0.
But, this is confusing as to intent, and also relies on various assumptions
about how addition will be implemented and that it will be guaranteed to
truncate extra precision.
It would seem that a more direct test of checking for a singular matrix by
looking for a very small reciprocal condition number would be preferable.
Simple code to do that as proposed by jwe is
template <typename T>
inline bool
is_numerically_singular (T rcond)
{
return (std::abs (rcond) <= std::numeric_limits<T>::epsilon ());
}
First implementation question is whether this should be a function (which is
inlined) or whether it should replace code directly. My vote would be for a
function implementation because in a file like dMatrix.cc this pattern occurs
8 times.
The second implementation question is whether this should be a member function
of the class and in the file dMatrix.h or whether it should be a static helper
function present in dMatrix.cc. I would vote for the latter because this
doesn't seem to be a universal need. Also, the way liboctave/array is set up
there are files for each fundamental matrix type so dMatrix for doubles,
fMatrix for floats, etc. If the function is placed in a file it doesn't need
to be templated and can just use the correct type.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?65343>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Octave-bug-tracker] [bug #65343] Replace ancient Fortran coding pattern with C++,
Rik <=