This is really old school, but a lot of times we have users sending us
copy pasting of codes, and that is the only way to know the version of
the code.
This is mostly a long term maintenance improvement.
Many coding styles require elimination of trailing whitespace, and
many editors and source code management configurations automatically
gobble up whitespace. When these tools gobble up whitespace, it
complicates reviewing the meaningful code changes.
By removing whitespace on one patch, it makes future
code reviews much easier.
=SCRIPT====================================================================
if which tempfile &>/dev/null; then
TEMPMAKER=tempfile
elif which mktemp &>/dev/null; then
TEMPMAKER=mktemp
else
echo "Cannot find tempfile program." 2>&1
exit 1
fi
MYTEMP=$($TEMPMAKER)
trap 'rm -f $MYTEMP' SIGINT SIGTERM
stripit() {
echo "stripping $1"
sed 's/[ \t]*$//' "$1" > $MYTEMP
cp $MYTEMP "$1"
}
if [ $# -gt 0 ]; then
while [ "$1" != "" ]; do
stripit $1
shift
done
else
while read -t 2; do
stripit $REPLY
done
fi
rm $MYTEMP
=================================================
**** (I also fixed the documentation of the six subroutines ****
Bug reported by Victor_K on the forum.
See forum http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=13&t=4643
Bug fix by Julien Langou. Involved as well Nick Higham, Sven Hammarling and Craig Lucas.
** Bug **
xPSTF2 and xPSTRF returns NaNs when the matrix in input has N negative diagonal entries.
** Note **
A matrix with N negative diagonal entries is a highly non valid input, but, yet no reason to create some NaNs, better to have a cleaner solution.
** Description **
xPSTF2 and xPSTRF first scan the diagonal of the matrix to find the greatest element on the diagonal.
During this pass on the diagonal, xPSTF2/xPSTRF checks as well for ZERO or NAN on the diagonal and aborts if it finds a ZERO or a NAN on the diagonal.
*
* Compute stopping value
*
PVT = 1
AJJ = A( PVT, PVT )
DO I = 2, N
IF( A( I, I ).GT.AJJ ) THEN
PVT = I
AJJ = A( PVT, PVT )
END IF
END DO
IF( AJJ.EQ.ZERO.OR.DISNAN( AJJ ) ) THEN
RANK = 0
INFO = 1
GO TO 170
END IF
Since the input matrix is filled with a negative diagonal (and no ZERO and no NAN), xPSTF2/xPSTRF finds a maximum element (which is the largest negative elements on the diagonal), and then this (negative) element is used to compute DSTOP, the stopping value. But then we get a negative DSTOP,
IF( TOL.LT.ZERO ) THEN
DSTOP = N * DLAMCH( 'Epsilon' ) * AJJ
ELSE
DSTOP = TOL
END IF
and then I stop even thinking on what would happen next. It seems that the code continues and does produce NAN in the first column. Why not. But I think we should catch this case and try to handle it in a different way. Maybe.
** Bug fix **
Replace
IF( AJJ.EQ.ZERO.OR.DISNAN( AJJ ) ) THEN
With
IF( AJJ.LE.ZERO.OR.DISNAN( AJJ ) ) THEN
So that if there is any nonpositive element or any NAN on the diagonal of A, we return right away with RANK=0 and INFO=1.
** Email from Nick Higham **
[ Julien wrote ] So that if there is any nonpositive element or any NAN on the diagonal of A, we return right away with RANK=0 and INFO=1?
[ Nick wrote ]
I think so.
This is justified by the documentation, which says
INFO is INTEGER
If INFO = -K, the K-th argument had an illegal value,
= 0: algorithm completed successfully, and
> 0: the matrix A is either rank deficient with computed rank
as returned in RANK, or is indefinite.
We are in the indefinite case if any diagonal element is negative.
Actually, that is not quite true: we are in the "not positive definite"
case. We can only say "indefinite" if there are both positive *and* negative
diagonal entries! However, if that is going to be said then it would be
necessary to check that all other LAPACK routines are similarly precise in
their wording, so it's simplest, and not too misleading,
to stay with "indefinite".
Use \par instead of \details for section.
add a Contributors Section and a Reference Section.
Remove (some) verbatim section when not needed.
Those changes have been done by hand so I am not sure I manage to catch them all.