-
Notifications
You must be signed in to change notification settings - Fork 480
Fix bug in (s,d)COMBSSQ #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in (s,d)COMBSSQ #569
Conversation
Codecov Report
@@ Coverage Diff @@
## master #569 +/- ##
=======================================
Coverage 82.37% 82.37%
=======================================
Files 1894 1894
Lines 190677 190679 +2
=======================================
+ Hits 157063 157065 +2
Misses 33614 33614
Continue to review full report at Codecov.
|
|
Good catch. To repeat. For example if V1=( 1e-100, 1e+00 ) and V2=( 1e+100, 0e+00 ), Again, we want to do the output can then be V1, so OUTPUT = ( 1e-100, 1e+00 ) which represents 1e-200. then with V1( 2 ) = V2( 2 ) + ( V1( 1 ) / V2( 1 ) )**2 * V1( 2 )
V1( 1 ) = V2( 1 )we get and so the output is OUTPUT = ( 1e+100, 0e+00 ) and that is not good. Without overflow we would have gotten OUTPUT = ( 1e+100, 1e-400 ) which is a correct representation for 1e-200. But with overflow, well, we have problems. Comment 1: Writing all this and I am not convinced that DCOMBSSQ does what it should. Maybe DCOMBSSQ assumes a certain range of input? Comment 2: I see that in lots of codes (for example dlassq.f90) if( sumsq == zero ) scl = oneWhich might have helped for the previous version of the code. It is weird that DLASSQ passes to DCOMBSSQ V2 as (bigNum, 0e+00). Is it really what is happening? Maybe, if that is the case, then we can "clean" DLASSQ so that if SUMSQ is ZERO, then SCL is ONE. That could be cleaner. It seems that the "older" DLASSQ was returning something clear, while the new DLASSQ is cleaning in input. |
|
I have concerns with DCOMBSSQ and I do not understand the range of valid input. V1=( 1e-100, 1e+200 ) and V2=( 1e+100, 1e-200 ), But V1( 2 ) = V2( 2 ) + ( V1( 1 ) / V2( 1 ) )**2 * V1( 2 )
V1( 1 ) = V2( 1 )we get and so the output is OUTPUT = ( 1e+100, 1e-200 ) and that is not good, since this represents 1e+00, and we want to represent 2e+00. Without overflow we would have gotten OUTPUT = ( 1e+100, 2e-200 ) which is a correct representation for 2e+00. But with overflow, well, we have problems. As written above, I do not think V1=( 1e-100, 1e+200 ) and V2=( 1e+100, 1e-200 ) is a valid input data for DCOMBSSQ. But then we should probably describe and define the range of input for which this routine works. |
|
One more comment. It seems that the new DLASSQ from #494 actually might enable us to forego using DCOMBSSQ. Maybe we can go back to a LANGE() code that performs: *
* Find normF(A).
*
SCALE = ZERO
SUM = ONE
DO 90 J = 1, N
CALL DLASSQ( M, A( 1, J ), 1, SCALE, SUM )
90 CONTINUE
VALUE = SCALE*SQRT( SUM )This is related to #290 |
Just one comment here. If results in This is exactly what happens with @christoph-conrads's example from #565 (comment). Whenever V1 is a sum of squares that underflows, a scale 1.0 in V2 figures as a big number. |
Description
The default behavior of
(s,d)COMBSSQis to always update the sumV1even ifV2is null. The problem is that it also changes the scaling factor ofV1. Note that a null sum is a representable floating-point number no matter its scaling factor. For instance, ifV1 = (smallScale, smallNum)andV2 = (bigNum, 0),SCOMBSSQ( V1, V2 )may result inV1 = (bigNum, 0).This PR:
to
(s,d)COMBSSQto prevent the scaling factor ofV1from being updated when the second sum is zero.This PR closes #565.