Skip to content

Commit ea2a102

Browse files
authored
Avoid out-of-bounds accesses in complex EIG tests
fixes #333
1 parent 12d8253 commit ea2a102

4 files changed

Lines changed: 65 additions & 78 deletions

File tree

TESTING/EIG/chet21.f

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
*>
3030
*> CHET21 generally checks a decomposition of the form
3131
*>
32-
*> A = U S U**H
33-
*>
34-
*> where **H means conjugate transpose, A is hermitian, U is unitary, and
32+
*> A = U S UC>
33+
*> where * means conjugate transpose, A is hermitian, U is unitary, and
3534
*> S is diagonal (if KBAND=0) or (real) symmetric tridiagonal (if
3635
*> KBAND=1).
3736
*>
@@ -43,19 +42,18 @@
4342
*>
4443
*> Specifically, if ITYPE=1, then:
4544
*>
46-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
47-
*> RESULT(2) = | I - U U**H | / ( n ulp )
45+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
4846
*>
4947
*> If ITYPE=2, then:
5048
*>
51-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
49+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
5250
*>
5351
*> If ITYPE=3, then:
5452
*>
55-
*> RESULT(1) = | I - U V**H | / ( n ulp )
53+
*> RESULT(1) = | I - UV* | / ( n ulp )
5654
*>
5755
*> For ITYPE > 1, the transformation U is expressed as a product
58-
*> V = H(1)...H(n-2), where H(j) = I - tau(j) v(j) v(j)**H and each
56+
*> V = H(1)...H(n-2), where H(j) = I - tau(j) v(j) v(j)C> and each
5957
*> vector v(j) has its first j elements 0 and the remaining n-j elements
6058
*> stored in V(j+1:n,j).
6159
*> \endverbatim
@@ -68,15 +66,14 @@
6866
*> ITYPE is INTEGER
6967
*> Specifies the type of tests to be performed.
7068
*> 1: U expressed as a dense unitary matrix:
71-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
72-
*> RESULT(2) = | I - U U**H | / ( n ulp )
69+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
7370
*>
7471
*> 2: U expressed as a product V of Housholder transformations:
75-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
72+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
7673
*>
7774
*> 3: U expressed both as a dense unitary matrix and
7875
*> as a product of Housholder transformations:
79-
*> RESULT(1) = | I - U V**H | / ( n ulp )
76+
*> RESULT(1) = | I - UV* | / ( n ulp )
8077
*> \endverbatim
8178
*>
8279
*> \param[in] UPLO
@@ -174,7 +171,7 @@
174171
*> \verbatim
175172
*> TAU is COMPLEX array, dimension (N)
176173
*> If ITYPE >= 2, then TAU(j) is the scalar factor of
177-
*> v(j) v(j)**H in the Householder transformation H(j) of
174+
*> v(j) v(j)* in the Householder transformation H(j) of
178175
*> the product U = H(1)...H(n-2)
179176
*> If ITYPE < 2, then TAU is not referenced.
180177
*> \endverbatim
@@ -297,7 +294,7 @@ SUBROUTINE CHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
297294
*
298295
IF( ITYPE.EQ.1 ) THEN
299296
*
300-
* ITYPE=1: error = A - U S U**H
297+
* ITYPE=1: error = A - U S U*
301298
*
302299
CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
303300
CALL CLACPY( CUPLO, N, N, A, LDA, WORK, N )
@@ -307,7 +304,8 @@ SUBROUTINE CHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
307304
10 CONTINUE
308305
*
309306
IF( N.GT.1 .AND. KBAND.EQ.1 ) THEN
310-
DO 20 J = 1, N - 1
307+
CMK DO 20 J = 1, N - 1
308+
DO 20 J = 2, N - 1
311309
CALL CHER2( CUPLO, N, -CMPLX( E( J ) ), U( 1, J ), 1,
312310
$ U( 1, J-1 ), 1, WORK, N )
313311
20 CONTINUE
@@ -316,7 +314,7 @@ SUBROUTINE CHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
316314
*
317315
ELSE IF( ITYPE.EQ.2 ) THEN
318316
*
319-
* ITYPE=2: error = V S V**H - A
317+
* ITYPE=2: error = V S V* - A
320318
*
321319
CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
322320
*
@@ -373,7 +371,7 @@ SUBROUTINE CHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
373371
*
374372
ELSE IF( ITYPE.EQ.3 ) THEN
375373
*
376-
* ITYPE=3: error = U V**H - I
374+
* ITYPE=3: error = U V* - I
377375
*
378376
IF( N.LT.2 )
379377
$ RETURN
@@ -409,7 +407,7 @@ SUBROUTINE CHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
409407
*
410408
* Do Test 2
411409
*
412-
* Compute U U**H - I
410+
* Compute UU* - I
413411
*
414412
IF( ITYPE.EQ.1 ) THEN
415413
CALL CGEMM( 'N', 'C', N, N, N, CONE, U, LDU, U, LDU, CZERO,

TESTING/EIG/chpt21.f

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
*>
3030
*> CHPT21 generally checks a decomposition of the form
3131
*>
32-
*> A = U S U**H
33-
*>
34-
*> where **H means conjugate transpose, A is hermitian, U is
32+
*> A = U S UC>
33+
*> where * means conjugate transpose, A is hermitian, U is
3534
*> unitary, and S is diagonal (if KBAND=0) or (real) symmetric
3635
*> tridiagonal (if KBAND=1). If ITYPE=1, then U is represented as
3736
*> a dense matrix, otherwise the U is expressed as a product of
@@ -42,16 +41,15 @@
4241
*>
4342
*> Specifically, if ITYPE=1, then:
4443
*>
45-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
46-
*> RESULT(2) = | I - U U**H | / ( n ulp )
44+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
4745
*>
4846
*> If ITYPE=2, then:
4947
*>
50-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
48+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
5149
*>
5250
*> If ITYPE=3, then:
5351
*>
54-
*> RESULT(1) = | I - U V**H | / ( n ulp )
52+
*> RESULT(1) = | I - UV* | / ( n ulp )
5553
*>
5654
*> Packed storage means that, for example, if UPLO='U', then the columns
5755
*> of the upper triangle of A are stored one after another, so that
@@ -72,16 +70,14 @@
7270
*>
7371
*> If UPLO='U', then V = H(n-1)...H(1), where
7472
*>
75-
*> H(j) = I - tau(j) v(j) v(j)**H
76-
*>
73+
*> H(j) = I - tau(j) v(j) v(j)C>
7774
*> and the first j-1 elements of v(j) are stored in V(1:j-1,j+1),
7875
*> (i.e., VP( j*(j+1)/2 + 1 : j*(j+1)/2 + j-1 ) ),
7976
*> the j-th element is 1, and the last n-j elements are 0.
8077
*>
8178
*> If UPLO='L', then V = H(1)...H(n-1), where
8279
*>
83-
*> H(j) = I - tau(j) v(j) v(j)**H
84-
*>
80+
*> H(j) = I - tau(j) v(j) v(j)C>
8581
*> and the first j elements of v(j) are 0, the (j+1)-st is 1, and the
8682
*> (j+2)-nd through n-th elements are stored in V(j+2:n,j) (i.e.,
8783
*> in VP( (2*n-j)*(j-1)/2 + j+2 : (2*n-j)*(j-1)/2 + n ) .)
@@ -95,15 +91,14 @@
9591
*> ITYPE is INTEGER
9692
*> Specifies the type of tests to be performed.
9793
*> 1: U expressed as a dense unitary matrix:
98-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
99-
*> RESULT(2) = | I - U U**H | / ( n ulp )
94+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
10095
*>
10196
*> 2: U expressed as a product V of Housholder transformations:
102-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
97+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
10398
*>
10499
*> 3: U expressed both as a dense unitary matrix and
105100
*> as a product of Housholder transformations:
106-
*> RESULT(1) = | I - U V**H | / ( n ulp )
101+
*> RESULT(1) = | I - UV* | / ( n ulp )
107102
*> \endverbatim
108103
*>
109104
*> \param[in] UPLO
@@ -186,7 +181,7 @@
186181
*> \verbatim
187182
*> TAU is COMPLEX array, dimension (N)
188183
*> If ITYPE >= 2, then TAU(j) is the scalar factor of
189-
*> v(j) v(j)**H in the Householder transformation H(j) of
184+
*> v(j) v(j)* in the Householder transformation H(j) of
190185
*> the product U = H(1)...H(n-2)
191186
*> If ITYPE < 2, then TAU is not referenced.
192187
*> \endverbatim
@@ -318,7 +313,7 @@ SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
318313
*
319314
IF( ITYPE.EQ.1 ) THEN
320315
*
321-
* ITYPE=1: error = A - U S U**H
316+
* ITYPE=1: error = A - U S U*
322317
*
323318
CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
324319
CALL CCOPY( LAP, AP, 1, WORK, 1 )
@@ -328,7 +323,7 @@ SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
328323
10 CONTINUE
329324
*
330325
IF( N.GT.1 .AND. KBAND.EQ.1 ) THEN
331-
DO 20 J = 1, N - 1
326+
DO 20 J = 2, N - 1
332327
CALL CHPR2( CUPLO, N, -CMPLX( E( J ) ), U( 1, J ), 1,
333328
$ U( 1, J-1 ), 1, WORK )
334329
20 CONTINUE
@@ -337,7 +332,7 @@ SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
337332
*
338333
ELSE IF( ITYPE.EQ.2 ) THEN
339334
*
340-
* ITYPE=2: error = V S V**H - A
335+
* ITYPE=2: error = V S V* - A
341336
*
342337
CALL CLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
343338
*
@@ -405,7 +400,7 @@ SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
405400
*
406401
ELSE IF( ITYPE.EQ.3 ) THEN
407402
*
408-
* ITYPE=3: error = U V**H - I
403+
* ITYPE=3: error = U V* - I
409404
*
410405
IF( N.LT.2 )
411406
$ RETURN
@@ -436,7 +431,7 @@ SUBROUTINE CHPT21( ITYPE, UPLO, N, KBAND, AP, D, E, U, LDU, VP,
436431
*
437432
* Do Test 2
438433
*
439-
* Compute U U**H - I
434+
* Compute UU* - I
440435
*
441436
IF( ITYPE.EQ.1 ) THEN
442437
CALL CGEMM( 'N', 'C', N, N, N, CONE, U, LDU, U, LDU, CZERO,

TESTING/EIG/zhet21.f

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@
2929
*>
3030
*> ZHET21 generally checks a decomposition of the form
3131
*>
32-
*> A = U S U**H
33-
*>
34-
*> where **H means conjugate transpose, A is hermitian, U is unitary, and
32+
*> A = U S UC>
33+
*> where * means conjugate transpose, A is hermitian, U is unitary, and
3534
*> S is diagonal (if KBAND=0) or (real) symmetric tridiagonal (if
3635
*> KBAND=1).
3736
*>
@@ -43,19 +42,18 @@
4342
*>
4443
*> Specifically, if ITYPE=1, then:
4544
*>
46-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
47-
*> RESULT(2) = | I - U U**H | / ( n ulp )
45+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
4846
*>
4947
*> If ITYPE=2, then:
5048
*>
51-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
49+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
5250
*>
5351
*> If ITYPE=3, then:
5452
*>
55-
*> RESULT(1) = | I - U V**H | / ( n ulp )
53+
*> RESULT(1) = | I - UV* | / ( n ulp )
5654
*>
5755
*> For ITYPE > 1, the transformation U is expressed as a product
58-
*> V = H(1)...H(n-2), where H(j) = I - tau(j) v(j) v(j)**H and each
56+
*> V = H(1)...H(n-2), where H(j) = I - tau(j) v(j) v(j)C> and each
5957
*> vector v(j) has its first j elements 0 and the remaining n-j elements
6058
*> stored in V(j+1:n,j).
6159
*> \endverbatim
@@ -68,15 +66,14 @@
6866
*> ITYPE is INTEGER
6967
*> Specifies the type of tests to be performed.
7068
*> 1: U expressed as a dense unitary matrix:
71-
*> RESULT(1) = | A - U S U**H | / ( |A| n ulp ) and
72-
*> RESULT(2) = | I - U U**H | / ( n ulp )
69+
*> RESULT(1) = | A - U S U* | / ( |A| n ulp ) *andC> RESULT(2) = | I - UU* | / ( n ulp )
7370
*>
7471
*> 2: U expressed as a product V of Housholder transformations:
75-
*> RESULT(1) = | A - V S V**H | / ( |A| n ulp )
72+
*> RESULT(1) = | A - V S V* | / ( |A| n ulp )
7673
*>
7774
*> 3: U expressed both as a dense unitary matrix and
7875
*> as a product of Housholder transformations:
79-
*> RESULT(1) = | I - U V**H | / ( n ulp )
76+
*> RESULT(1) = | I - UV* | / ( n ulp )
8077
*> \endverbatim
8178
*>
8279
*> \param[in] UPLO
@@ -174,7 +171,7 @@
174171
*> \verbatim
175172
*> TAU is COMPLEX*16 array, dimension (N)
176173
*> If ITYPE >= 2, then TAU(j) is the scalar factor of
177-
*> v(j) v(j)**H in the Householder transformation H(j) of
174+
*> v(j) v(j)* in the Householder transformation H(j) of
178175
*> the product U = H(1)...H(n-2)
179176
*> If ITYPE < 2, then TAU is not referenced.
180177
*> \endverbatim
@@ -297,7 +294,7 @@ SUBROUTINE ZHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
297294
*
298295
IF( ITYPE.EQ.1 ) THEN
299296
*
300-
* ITYPE=1: error = A - U S U**H
297+
* ITYPE=1: error = A - U S U*
301298
*
302299
CALL ZLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
303300
CALL ZLACPY( CUPLO, N, N, A, LDA, WORK, N )
@@ -307,7 +304,8 @@ SUBROUTINE ZHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
307304
10 CONTINUE
308305
*
309306
IF( N.GT.1 .AND. KBAND.EQ.1 ) THEN
310-
DO 20 J = 1, N - 1
307+
CMK DO 20 J = 1, N - 1
308+
DO 20 J = 2, N - 1
311309
CALL ZHER2( CUPLO, N, -DCMPLX( E( J ) ), U( 1, J ), 1,
312310
$ U( 1, J-1 ), 1, WORK, N )
313311
20 CONTINUE
@@ -316,7 +314,7 @@ SUBROUTINE ZHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
316314
*
317315
ELSE IF( ITYPE.EQ.2 ) THEN
318316
*
319-
* ITYPE=2: error = V S V**H - A
317+
* ITYPE=2: error = V S V* - A
320318
*
321319
CALL ZLASET( 'Full', N, N, CZERO, CZERO, WORK, N )
322320
*
@@ -373,7 +371,7 @@ SUBROUTINE ZHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
373371
*
374372
ELSE IF( ITYPE.EQ.3 ) THEN
375373
*
376-
* ITYPE=3: error = U V**H - I
374+
* ITYPE=3: error = U V* - I
377375
*
378376
IF( N.LT.2 )
379377
$ RETURN
@@ -409,7 +407,7 @@ SUBROUTINE ZHET21( ITYPE, UPLO, N, KBAND, A, LDA, D, E, U, LDU, V,
409407
*
410408
* Do Test 2
411409
*
412-
* Compute U U**H - I
410+
* Compute UU* - I
413411
*
414412
IF( ITYPE.EQ.1 ) THEN
415413
CALL ZGEMM( 'N', 'C', N, N, N, CONE, U, LDU, U, LDU, CZERO,

0 commit comments

Comments
 (0)