1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
     180
     181
     182
     183
     184
     185
     186
     187
     188
     189
     190
     191
     192
     193
     194
     195
     196
     197
     198
     199
     200
     201
     202
     203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
     241
     242
     243
     244
     245
     246
     247
     248
     249
     250
     251
     252
     253
     254
     255
     256
     257
     258
     259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270
     271
     272
     273
     274
     275
     276
     277
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
     410
     411
     412
     413
     414
     415
     416
     417
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
     432
     433
     434
     435
     436
     437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
     510
     511
     512
     513
     514
     515
     516
     517
     518
     519
     520
     521
     522
     523
     524
     525
     526
     527
     528
     529
     530
     531
     532
     533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
     553
     554
     555
     556
     557
     558
     559
     560
     561
     562
     563
     564
     565
     566
     567
     568
     569
     570
     571
     572
     573
     574
     575
     576
     577
     578
     579
     580
     581
     582
     583
     584
     585
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
     596
     597
     598
     599
     600
     601
     602
     603
     604
     605
     606
     607
     608
     609
     610
     611
     612
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
     628
     629
     630
     631
     632
     633
     634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
     746
     747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
     783
     784
     785
     786
     787
     788
     789
     790
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
     889
     890
     891
     892
     893
     894
     895
     896
     897
     898
     899
     900
     901
     902
     903
     904
     905
     906
     907
     908
     909
     910
     911
     912
     913
     914
     915
     916
     917
     918
     919
     920
     921
     922
     923
     924
     925
     926
     927
     928
     929
     930
     931
     932
     933
     934
     935
     936
     937
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
     965
     966
     967
     968
      SUBROUTINE DCHKBDNSIZESMVALNVALNTYPESDOTYPENRHS,
     $                   ISEEDTHRESHALDABDBES1S2XLDX,
     $                   YZQLDQPTLDPTUVTWORKLWORK,
     $                   IWORKNOUTINFO )
*
*  -- LAPACK test routine (version 3.1) --
*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
*     November 2006
*
*     .. Scalar Arguments ..
      INTEGER            INFOLDALDPTLDQLDXLWORKNOUTNRHS,
     $                   NSIZESNTYPES
      DOUBLE PRECISION   THRESH
*     ..
*     .. Array Arguments ..
      LOGICAL            DOTYPE* )
      INTEGER            ISEED4 ), IWORK* ), MVAL* ), NVAL* )
      DOUBLE PRECISION   ALDA* ), BD* ), BE* ), PTLDPT* ),
     $                   QLDQ* ), S1* ), S2* ), ULDPT* ),
     $                   VTLDPT* ), WORK* ), XLDX* ),
     $                   YLDX* ), ZLDX* )
*     ..
*
*  Purpose
*  =======
*
*  DCHKBD checks the singular value decomposition (SVD) routines.
*
*  DGEBRD reduces a real general m by n matrix A to upper or lower
*  bidiagonal form B by an orthogonal transformation:  Q' * A * P = B
*  (or A = Q * B * P').  The matrix B is upper bidiagonal if m >= n
*  and lower bidiagonal if m < n.
*
*  DORGBR generates the orthogonal matrices Q and P' from DGEBRD.
*  Note that Q and P are not necessarily square.
*
*  DBDSQR computes the singular value decomposition of the bidiagonal
*  matrix B as B = U S V'.  It is called three times to compute
*     1)  B = U S1 V', where S1 is the diagonal matrix of singular
*         values and the columns of the matrices U and V are the left
*         and right singular vectors, respectively, of B.
*     2)  Same as 1), but the singular values are stored in S2 and the
*         singular vectors are not computed.
*     3)  A = (UQ) S (P'V'), the SVD of the original matrix A.
*  In addition, DBDSQR has an option to apply the left orthogonal matrix
*  U to a matrix X, useful in least squares applications.
*
*  DBDSDC computes the singular value decomposition of the bidiagonal
*  matrix B as B = U S V' using divide-and-conquer. It is called twice
*  to compute
*     1) B = U S1 V', where S1 is the diagonal matrix of singular
*         values and the columns of the matrices U and V are the left
*         and right singular vectors, respectively, of B.
*     2) Same as 1), but the singular values are stored in S2 and the
*         singular vectors are not computed.
*
*  For each pair of matrix dimensions (M,N) and each selected matrix
*  type, an M by N matrix A and an M by NRHS matrix X are generated.
*  The problem dimensions are as follows
*     A:          M x N
*     Q:          M x min(M,N) (but M x M if NRHS > 0)
*     P:          min(M,N) x N
*     B:          min(M,N) x min(M,N)
*     U, V:       min(M,N) x min(M,N)
*     S1, S2      diagonal, order min(M,N)
*     X:          M x NRHS
*
*  For each generated matrix, 14 tests are performed:
*
*  Test DGEBRD and DORGBR
*
*  (1)   | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P'
*
*  (2)   | I - Q' Q | / ( M ulp )
*
*  (3)   | I - PT PT' | / ( N ulp )
*
*  Test DBDSQR on bidiagonal matrix B
*
*  (4)   | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'
*
*  (5)   | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X
*                                                   and   Z = U' Y.
*  (6)   | I - U' U | / ( min(M,N) ulp )
*
*  (7)   | I - VT VT' | / ( min(M,N) ulp )
*
*  (8)   S1 contains min(M,N) nonnegative values in decreasing order.
*        (Return 0 if true, 1/ULP if false.)
*
*  (9)   | S1 - S2 | / ( |S1| ulp ), where S2 is computed without
*                                    computing U and V.
*
*  (10)  0 if the true singular values of B are within THRESH of
*        those in S1.  2*THRESH if they are not.  (Tested using
*        DSVDCH)
*
*  Test DBDSQR on matrix A
*
*  (11)  | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp )
*
*  (12)  | X - (QU) Z | / ( |X| max(M,k) ulp )
*
*  (13)  | I - (QU)'(QU) | / ( M ulp )
*
*  (14)  | I - (VT PT) (PT'VT') | / ( N ulp )
*
*  Test DBDSDC on bidiagonal matrix B
*
*  (15)  | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V'
*
*  (16)  | I - U' U | / ( min(M,N) ulp )
*
*  (17)  | I - VT VT' | / ( min(M,N) ulp )
*
*  (18)  S1 contains min(M,N) nonnegative values in decreasing order.
*        (Return 0 if true, 1/ULP if false.)
*
*  (19)  | S1 - S2 | / ( |S1| ulp ), where S2 is computed without
*                                    computing U and V.
*  The possible matrix types are
*
*  (1)  The zero matrix.
*  (2)  The identity matrix.
*
*  (3)  A diagonal matrix with evenly spaced entries
*       1, ..., ULP  and random signs.
*       (ULP = (first number larger than 1) - 1 )
*  (4)  A diagonal matrix with geometrically spaced entries
*       1, ..., ULP  and random signs.
*  (5)  A diagonal matrix with "clustered" entries 1, ULP, ..., ULP
*       and random signs.
*
*  (6)  Same as (3), but multiplied by SQRT( overflow threshold )
*  (7)  Same as (3), but multiplied by SQRT( underflow threshold )
*
*  (8)  A matrix of the form  U D V, where U and V are orthogonal and
*       D has evenly spaced entries 1, ..., ULP with random signs
*       on the diagonal.
*
*  (9)  A matrix of the form  U D V, where U and V are orthogonal and
*       D has geometrically spaced entries 1, ..., ULP with random
*       signs on the diagonal.
*
*  (10) A matrix of the form  U D V, where U and V are orthogonal and
*       D has "clustered" entries 1, ULP,..., ULP with random
*       signs on the diagonal.
*
*  (11) Same as (8), but multiplied by SQRT( overflow threshold )
*  (12) Same as (8), but multiplied by SQRT( underflow threshold )
*
*  (13) Rectangular matrix with random entries chosen from (-1,1).
*  (14) Same as (13), but multiplied by SQRT( overflow threshold )
*  (15) Same as (13), but multiplied by SQRT( underflow threshold )
*
*  Special case:
*  (16) A bidiagonal matrix with random entries chosen from a
*       logarithmic distribution on [ulp^2,ulp^(-2)]  (I.e., each
*       entry is  e^x, where x is chosen uniformly on
*       [ 2 log(ulp), -2 log(ulp) ] .)  For *this* type:
*       (a) DGEBRD is not called to reduce it to bidiagonal form.
*       (b) the bidiagonal is  min(M,N) x min(M,N); if M
*           matrix will be lower bidiagonal, otherwise upper.
*       (c) only tests 5--8 and 14 are performed.
*
*  A subset of the full set of matrix types may be selected through
*  the logical array DOTYPE.
*
*  Arguments
*  ==========
*
*  NSIZES  (input) INTEGER
*          The number of values of M and N contained in the vectors
*          MVAL and NVAL.  The matrix sizes are used in pairs (M,N).
*
*  MVAL    (input) INTEGER array, dimension (NM)
*          The values of the matrix row dimension M.
*
*  NVAL    (input) INTEGER array, dimension (NM)
*          The values of the matrix column dimension N.
*
*  NTYPES  (input) INTEGER
*          The number of elements in DOTYPE.   If it is zero, DCHKBD
*          does nothing.  It must be at least zero.  If it is MAXTYP+1
*          and NSIZES is 1, then an additional type, MAXTYP+1 is
*          defined, which is to use whatever matrices are in A and B.
*          This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and
*          DOTYPE(MAXTYP+1) is .TRUE. .
*
*  DOTYPE  (input) LOGICAL array, dimension (NTYPES)
*          If DOTYPE(j) is .TRUE., then for each size (m,n), a matrix
*          of type j will be generated.  If NTYPES is smaller than the
*          maximum number of types defined (PARAMETER MAXTYP), then
*          types NTYPES+1 through MAXTYP will not be generated.  If
*          NTYPES is larger than MAXTYP, DOTYPE(MAXTYP+1) through
*          DOTYPE(NTYPES) will be ignored.
*
*  NRHS    (input) INTEGER
*          The number of columns in the "right-hand side" matrices X, Y,
*          and Z, used in testing DBDSQR.  If NRHS = 0, then the
*          operations on the right-hand side will not be tested.
*          NRHS must be at least 0.
*
*  ISEED   (input/output) INTEGER array, dimension (4)
*          On entry ISEED specifies the seed of the random number
*          generator. The array elements should be between 0 and 4095;
*          if not they will be reduced mod 4096.  Also, ISEED(4) must
*          be odd.  The values of ISEED are changed on exit, and can be
*          used in the next call to DCHKBD to continue the same random
*          number sequence.
*
*  THRESH  (input) DOUBLE PRECISION
*          The threshold value for the test ratios.  A result is
*          included in the output file if RESULT >= THRESH.  To have
*          every test ratio printed, use THRESH = 0.  Note that the
*          expected value of the test ratios is O(1), so THRESH should
*          be a reasonably small multiple of 1, e.g., 10 or 100.
*
*  A       (workspace) DOUBLE PRECISION array, dimension (LDA,NMAX)
*          where NMAX is the maximum value of N in NVAL.
*
*  LDA     (input) INTEGER
*          The leading dimension of the array A.  LDA >= max(1,MMAX),
*          where MMAX is the maximum value of M in MVAL.
*
*  BD      (workspace) DOUBLE PRECISION array, dimension
*                      (max(min(MVAL(j),NVAL(j))))
*
*  BE      (workspace) DOUBLE PRECISION array, dimension
*                      (max(min(MVAL(j),NVAL(j))))
*
*  S1      (workspace) DOUBLE PRECISION array, dimension
*                      (max(min(MVAL(j),NVAL(j))))
*
*  S2      (workspace) DOUBLE PRECISION array, dimension
*                      (max(min(MVAL(j),NVAL(j))))
*
*  X       (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
*  LDX     (input) INTEGER
*          The leading dimension of the arrays X, Y, and Z.
*          LDX >= max(1,MMAX)
*
*  Y       (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
*  Z       (workspace) DOUBLE PRECISION array, dimension (LDX,NRHS)
*
*  Q       (workspace) DOUBLE PRECISION array, dimension (LDQ,MMAX)
*
*  LDQ     (input) INTEGER
*          The leading dimension of the array Q.  LDQ >= max(1,MMAX).
*
*  PT      (workspace) DOUBLE PRECISION array, dimension (LDPT,NMAX)
*
*  LDPT    (input) INTEGER
*          The leading dimension of the arrays PT, U, and V.
*          LDPT >= max(1, max(min(MVAL(j),NVAL(j)))).
*
*  U       (workspace) DOUBLE PRECISION array, dimension
*                      (LDPT,max(min(MVAL(j),NVAL(j))))
*
*  V       (workspace) DOUBLE PRECISION array, dimension
*                      (LDPT,max(min(MVAL(j),NVAL(j))))
*
*  WORK    (workspace) DOUBLE PRECISION array, dimension (LWORK)
*
*  LWORK   (input) INTEGER
*          The number of entries in WORK.  This must be at least
*          3(M+N) and  M(M + max(M,N,k) + 1) + N*min(M,N)  for all
*          pairs  (M,N)=(MM(j),NN(j))
*
*  IWORK   (workspace) INTEGER array, dimension at least 8*min(M,N)
*
*  NOUT    (input) INTEGER
*          The FORTRAN unit number for printing out error messages
*          (e.g., if a routine returns IINFO not equal to 0.)
*
*  INFO    (output) INTEGER
*          If 0, then everything ran OK.
*           -1: NSIZES < 0
*           -2: Some MM(j) < 0
*           -3: Some NN(j) < 0
*           -4: NTYPES < 0
*           -6: NRHS  < 0
*           -8: THRESH < 0
*          -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ).
*          -17: LDB < 1 or LDB < MMAX.
*          -21: LDQ < 1 or LDQ < MMAX.
*          -23: LDPT< 1 or LDPT< MNMAX.
*          -27: LWORK too small.
*          If  DLATMR, SLATMS, DGEBRD, DORGBR, or DBDSQR,
*              returns an error code, the
*              absolute value of it is returned.
*
*-----------------------------------------------------------------------
*
*     Some Local Variables and Parameters:
*     ---- ----- --------- --- ----------
*
*     ZERO, ONE       Real 0 and 1.
*     MAXTYP          The number of types defined.
*     NTEST           The number of tests performed, or which can
*                     be performed so far, for the current matrix.
*     MMAX            Largest value in NN.
*     NMAX            Largest value in NN.
*     MNMIN           min(MM(j), NN(j)) (the dimension of the bidiagonal
*                     matrix.)
*     MNMAX           The maximum value of MNMIN for j=1,...,NSIZES.
*     NFAIL           The number of tests which have exceeded THRESH
*     COND, IMODE     Values to be passed to the matrix generators.
*     ANORM           Norm of A; passed to matrix generators.
*
*     OVFL, UNFL      Overflow and underflow thresholds.
*     RTOVFL, RTUNFL  Square roots of the previous 2 values.
*     ULP, ULPINV     Finest relative precision and its inverse.
*
*             The following four arrays decode JTYPE:
*     KTYPE(j)        The general type (1-10) for type "j".
*     KMODE(j)        The MODE value to be passed to the matrix
*                     generator for type "j".
*     KMAGN(j)        The order of magnitude ( O(1),
*                     O(overflow^(1/2) ), O(underflow^(1/2) )
*
* ======================================================================
*
*     .. Parameters ..
      DOUBLE PRECISION   ZEROONETWOHALF
      PARAMETER          ( ZERO = 0.0D0ONE = 1.0D0TWO = 2.0D0,
     $                   HALF = 0.5D0 )
      INTEGER            MAXTYP
      PARAMETER          ( MAXTYP = 16 )
*     ..
*     .. Local Scalars ..
      LOGICAL            BADMMBADNNBIDIAG
      CHARACTER          UPLO
      CHARACTER*3        PATH
      INTEGER            IIINFOIMODEITYPEJJCOLJSIZEJTYPE,
     $                   LOG2UIMMINWRKMMAXMNMAXMNMINMQ,
     $                   MTYPESNNFAILNMAXNTEST
      DOUBLE PRECISION   AMNINVANORMCONDOVFLRTOVFLRTUNFL,
     $                   TEMP1TEMP2ULPULPINVUNFL
*     ..
*     .. Local Arrays ..
      INTEGER            IDUM1 ), IOLDSD4 ), KMAGNMAXTYP ),
     $                   KMODEMAXTYP ), KTYPEMAXTYP )
      DOUBLE PRECISION   DUM1 ), DUMMA1 ), RESULT19 )
*     ..
*     .. External Functions ..
      DOUBLE PRECISION   DLAMCHDLARND
      EXTERNAL           DLAMCHDLARND
*     ..
*     .. External Subroutines ..
      EXTERNAL           ALASUMDBDSDCDBDSQRDBDT01DBDT02DBDT03,
     $                   DCOPYDGEBRDDGEMMDLABADDLACPYDLAHD2,
     $                   DLASETDLATMRDLATMSDORGBRDORT01XERBLA
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC          ABSEXPINTLOGMAXMINSQRT
*     ..
*     .. Scalars in Common ..
      LOGICAL            LERROK
      CHARACTER*32       SRNAMT
      INTEGER            INFOTNUNIT
*     ..
*     .. Common blocks ..
      COMMON             / INFOC / INFOTNUNITOKLERR
      COMMON             / SRNAMC / SRNAMT
*     ..
*     .. Data statements ..
      DATA               KTYPE / 125*45*63*910 /
      DATA               KMAGN / 2*13*1233*1231230 /
      DATA               KMODE / 2*043144431440,
     $                   000 /
*     ..
*     .. Executable Statements ..
*
*     Check for errors
*
      INFO = 0
*
      BADMM = .FALSE.
      BADNN = .FALSE.
      MMAX = 1
      NMAX = 1
      MNMAX = 1
      MINWRK = 1
      DO 10 J = 1NSIZES
         MMAX = MAXMMAXMVALJ ) )
         IFMVALJ ).LT.0 )
     $      BADMM = .TRUE.
         NMAX = MAXNMAXNVALJ ) )
         IFNVALJ ).LT.0 )
     $      BADNN = .TRUE.
         MNMAX = MAXMNMAXMINMVALJ ), NVALJ ) ) )
         MINWRK = MAXMINWRK3*MVALJ )+NVALJ ) ),
     $            MVALJ )*MVALJ )+MAXMVALJ ), NVALJ ),
     $            NRHS )+1 )+NVALJ )*MINNVALJ ), MVALJ ) ) )
   10 CONTINUE
*
*     Check for errors
*
      IFNSIZES.LT.0 ) THEN
         INFO = -1
      ELSE IFBADMM ) THEN
         INFO = -2
      ELSE IFBADNN ) THEN
         INFO = -3
      ELSE IFNTYPES.LT.0 ) THEN
         INFO = -4
      ELSE IFNRHS.LT.0 ) THEN
         INFO = -6
      ELSE IFLDA.LT.MMAX ) THEN
         INFO = -11
      ELSE IFLDX.LT.MMAX ) THEN
         INFO = -17
      ELSE IFLDQ.LT.MMAX ) THEN
         INFO = -21
      ELSE IFLDPT.LT.MNMAX ) THEN
         INFO = -23
      ELSE IFMINWRK.GT.LWORK ) THEN
         INFO = -27
      END IF
*
      IFINFO.NE.0 ) THEN
         CALL XERBLA'DCHKBD'-INFO )
         RETURN
      END IF
*
*     Initialize constants
*
      PATH11 ) = 'Double precision'
      PATH23 ) = 'BD'
      NFAIL = 0
      NTEST = 0
      UNFL = DLAMCH'Safe minimum' )
      OVFL = DLAMCH'Overflow' )
      CALL DLABADUNFLOVFL )
      ULP = DLAMCH'Precision' )
      ULPINV = ONE / ULP
      LOG2UI = INTLOGULPINV ) / LOGTWO ) )
      RTUNFL = SQRTUNFL )
      RTOVFL = SQRTOVFL )
      INFOT = 0
*
*     Loop over sizes, types
*
      DO 200 JSIZE = 1NSIZES
         M = MVALJSIZE )
         N = NVALJSIZE )
         MNMIN = MINMN )
         AMNINV = ONE / MAXMN1 )
*
         IFNSIZES.NE.1 ) THEN
            MTYPES = MINMAXTYPNTYPES )
         ELSE
            MTYPES = MINMAXTYP+1NTYPES )
         END IF
*
         DO 190 JTYPE = 1MTYPES
            IF.NOT.DOTYPEJTYPE ) )
     $         GO TO 190
*
            DO 20 J = 14
               IOLDSDJ ) = ISEEDJ )
   20       CONTINUE
*
            DO 30 J = 114
               RESULTJ ) = -ONE
   30       CONTINUE
*
            UPLO = ' '
*
*           Compute "A"
*
*           Control parameters:
*
*           KMAGN  KMODE        KTYPE
*       =1  O(1)   clustered 1  zero
*       =2  large  clustered 2  identity
*       =3  small  exponential  (none)
*       =4         arithmetic   diagonal, (w/ eigenvalues)
*       =5         random       symmetric, w/ eigenvalues
*       =6                      nonsymmetric, w/ singular values
*       =7                      random diagonal
*       =8                      random symmetric
*       =9                      random nonsymmetric
*       =10                     random bidiagonal (log. distrib.)
*
            IFMTYPES.GT.MAXTYP )
     $         GO TO 100
*
            ITYPE = KTYPEJTYPE )
            IMODE = KMODEJTYPE )
*
*           Compute norm
*
            GO TO ( 405060 )KMAGNJTYPE )
*
   40       CONTINUE
            ANORM = ONE
            GO TO 70
*
   50       CONTINUE
            ANORM = ( RTOVFL*ULP )*AMNINV
            GO TO 70
*
   60       CONTINUE
            ANORM = RTUNFL*MAXMN )*ULPINV
            GO TO 70
*
   70       CONTINUE
*
            CALL DLASET'Full'LDANZEROZEROALDA )
            IINFO = 0
            COND = ULPINV
*
            BIDIAG = .FALSE.
            IFITYPE.EQ.1 ) THEN
*
*              Zero matrix
*
               IINFO = 0
*
            ELSE IFITYPE.EQ.2 ) THEN
*
*              Identity
*
               DO 80 JCOL = 1MNMIN
                  AJCOLJCOL ) = ANORM
   80          CONTINUE
*
            ELSE IFITYPE.EQ.4 ) THEN
*
*              Diagonal Matrix, [Eigen]values Specified
*
               CALL DLATMSMNMINMNMIN'S'ISEED'N'WORKIMODE,
     $                      CONDANORM00'N'ALDA,
     $                      WORKMNMIN+1 ), IINFO )
*
            ELSE IFITYPE.EQ.5 ) THEN
*
*              Symmetric, eigenvalues specified
*
               CALL DLATMSMNMINMNMIN'S'ISEED'S'WORKIMODE,
     $                      CONDANORMMN'N'ALDA,
     $                      WORKMNMIN+1 ), IINFO )
*
            ELSE IFITYPE.EQ.6 ) THEN
*
*              Nonsymmetric, singular values specified
*
               CALL DLATMSMN'S'ISEED'N'WORKIMODECOND,
     $                      ANORMMN'N'ALDAWORKMNMIN+1 ),
     $                      IINFO )
*
            ELSE IFITYPE.EQ.7 ) THEN
*
*              Diagonal, random entries
*
               CALL DLATMRMNMINMNMIN'S'ISEED'N'WORK6ONE,
     $                      ONE'T''N'WORKMNMIN+1 ), 1ONE,
     $                      WORK2*MNMIN+1 ), 1ONE'N'IWORK00,
     $                      ZEROANORM'NO'ALDAIWORKIINFO )
*
            ELSE IFITYPE.EQ.8 ) THEN
*
*              Symmetric, random entries
*
               CALL DLATMRMNMINMNMIN'S'ISEED'S'WORK6ONE,
     $                      ONE'T''N'WORKMNMIN+1 ), 1ONE,
     $                      WORKM+MNMIN+1 ), 1ONE'N'IWORKMN,
     $                      ZEROANORM'NO'ALDAIWORKIINFO )
*
            ELSE IFITYPE.EQ.9 ) THEN
*
*              Nonsymmetric, random entries
*
               CALL DLATMRMN'S'ISEED'N'WORK6ONEONE,
     $                      'T''N'WORKMNMIN+1 ), 1ONE,
     $                      WORKM+MNMIN+1 ), 1ONE'N'IWORKMN,
     $                      ZEROANORM'NO'ALDAIWORKIINFO )
*
            ELSE IFITYPE.EQ.10 ) THEN
*
*              Bidiagonal, random entries
*
               TEMP1 = -TWO*LOGULP )
               DO 90 J = 1MNMIN
                  BDJ ) = EXPTEMP1*DLARND2ISEED ) )
                  IFJ.LT.MNMIN )
     $               BEJ ) = EXPTEMP1*DLARND2ISEED ) )
   90          CONTINUE
*
               IINFO = 0
               BIDIAG = .TRUE.
               IFM.GE.N ) THEN
                  UPLO = 'U'
               ELSE
                  UPLO = 'L'
               END IF
            ELSE
               IINFO = 1
            END IF
*
            IFIINFO.EQ.0 ) THEN
*
*              Generate Right-Hand Side
*
               IFBIDIAG ) THEN
                  CALL DLATMRMNMINNRHS'S'ISEED'N'WORK6,
     $                         ONEONE'T''N'WORKMNMIN+1 ), 1,
     $                         ONEWORK2*MNMIN+1 ), 1ONE'N',
     $                         IWORKMNMINNRHSZEROONE'NO'Y,
     $                         LDXIWORKIINFO )
               ELSE
                  CALL DLATMRMNRHS'S'ISEED'N'WORK6ONE,
     $                         ONE'T''N'WORKM+1 ), 1ONE,
     $                         WORK2*M+1 ), 1ONE'N'IWORKM,
     $                         NRHSZEROONE'NO'XLDXIWORK,
     $                         IINFO )
               END IF
            END IF
*
*           Error Exit
*
            IFIINFO.NE.0 ) THEN
               WRITENOUT, FMT = 9998 )'Generator', IINFO, M, N,
     $            JTYPE, IOLDSD
               INFO = ABSIINFO )
               RETURN
            END IF
*
  100       CONTINUE
*
*           Call DGEBRD and DORGBR to compute B, Q, and P, do tests.
*
            IF.NOT.BIDIAG ) THEN
*
*              Compute transformations to reduce A to bidiagonal form:
*              B := Q' * A * P.
*
               CALL DLACPY' 'MNALDAQLDQ )
               CALL DGEBRDMNQLDQBDBEWORKWORKMNMIN+1 ),
     $                      WORK2*MNMIN+1 ), LWORK-2*MNMINIINFO )
*
*              Check error code from DGEBRD.
*
               IFIINFO.NE.0 ) THEN
                  WRITENOUT, FMT = 9998 )'DGEBRD', IINFO, M, N,
     $               JTYPE, IOLDSD
                  INFO = ABSIINFO )
                  RETURN
               END IF
*
               CALL DLACPY' 'MNQLDQPTLDPT )
               IFM.GE.N ) THEN
                  UPLO = 'U'
               ELSE
                  UPLO = 'L'
               END IF
*
*              Generate Q
*
               MQ = M
               IFNRHS.LE.0 )
     $            MQ = MNMIN
               CALL DORGBR'Q'MMQNQLDQWORK,
     $                      WORK2*MNMIN+1 ), LWORK-2*MNMINIINFO )
*
*              Check error code from DORGBR.
*
               IFIINFO.NE.0 ) THEN
                  WRITENOUT, FMT = 9998 )'DORGBR(Q)', IINFO, M, N,
     $               JTYPE, IOLDSD
                  INFO = ABSIINFO )
                  RETURN
               END IF
*
*              Generate P'
*
               CALL DORGBR'P'MNMINNMPTLDPTWORKMNMIN+1 ),
     $                      WORK2*MNMIN+1 ), LWORK-2*MNMINIINFO )
*
*              Check error code from DORGBR.
*
               IFIINFO.NE.0 ) THEN
                  WRITENOUT, FMT = 9998 )'DORGBR(P)', IINFO, M, N,
     $               JTYPE, IOLDSD
                  INFO = ABSIINFO )
                  RETURN
               END IF
*
*              Apply Q' to an M by NRHS matrix X:  Y := Q' * X.
*
               CALL DGEMM'Transpose''No transpose'MNRHSMONE,
     $                     QLDQXLDXZEROYLDX )
*
*              Test 1:  Check the decomposition A := Q * B * PT
*                   2:  Check the orthogonality of Q
*                   3:  Check the orthogonality of PT
*
               CALL DBDT01MN1ALDAQLDQBDBEPTLDPT,
     $                      WORKRESULT1 ) )
               CALL DORT01'Columns'MMQQLDQWORKLWORK,
     $                      RESULT2 ) )
               CALL DORT01'Rows'MNMINNPTLDPTWORKLWORK,
     $                      RESULT3 ) )
            END IF
*
*           Use DBDSQR to form the SVD of the bidiagonal matrix B:
*           B := U * S1 * VT, and compute Z = U' * Y.
*
            CALL DCOPYMNMINBD1S11 )
            IFMNMIN.GT.0 )
     $         CALL DCOPYMNMIN-1BE1WORK1 )
            CALL DLACPY' 'MNRHSYLDXZLDX )
            CALL DLASET'Full'MNMINMNMINZEROONEULDPT )
            CALL DLASET'Full'MNMINMNMINZEROONEVTLDPT )
*
            CALL DBDSQRUPLOMNMINMNMINMNMINNRHSS1WORKVT,
     $                   LDPTULDPTZLDXWORKMNMIN+1 ), IINFO )
*
*           Check error code from DBDSQR.
*
            IFIINFO.NE.0 ) THEN
               WRITENOUT, FMT = 9998 )'DBDSQR(vects)', IINFO, M, N,
     $            JTYPE, IOLDSD
               INFO = ABSIINFO )
               IFIINFO.LT.0 ) THEN
                  RETURN
               ELSE
                  RESULT4 ) = ULPINV
                  GO TO 170
               END IF
            END IF
*
*           Use DBDSQR to compute only the singular values of the
*           bidiagonal matrix B;  U, VT, and Z should not be modified.
*
            CALL DCOPYMNMINBD1S21 )
            IFMNMIN.GT.0 )
     $         CALL DCOPYMNMIN-1BE1WORK1 )
*
            CALL DBDSQRUPLOMNMIN000S2WORKVTLDPTU,
     $                   LDPTZLDXWORKMNMIN+1 ), IINFO )
*
*           Check error code from DBDSQR.
*
            IFIINFO.NE.0 ) THEN
               WRITENOUT, FMT = 9998 )'DBDSQR(values)', IINFO, M, N,
     $            JTYPE, IOLDSD
               INFO = ABSIINFO )
               IFIINFO.LT.0 ) THEN
                  RETURN
               ELSE
                  RESULT9 ) = ULPINV
                  GO TO 170
               END IF
            END IF
*
*           Test 4:  Check the decomposition B := U * S1 * VT
*                5:  Check the computation Z := U' * Y
*                6:  Check the orthogonality of U
*                7:  Check the orthogonality of VT
*
            CALL DBDT03UPLOMNMIN1BDBEULDPTS1VTLDPT,
     $                   WORKRESULT4 ) )
            CALL DBDT02MNMINNRHSYLDXZLDXULDPTWORK,
     $                   RESULT5 ) )
            CALL DORT01'Columns'MNMINMNMINULDPTWORKLWORK,
     $                   RESULT6 ) )
            CALL DORT01'Rows'MNMINMNMINVTLDPTWORKLWORK,
     $                   RESULT7 ) )
*
*           Test 8:  Check that the singular values are sorted in
*                    non-increasing order and are non-negative
*
            RESULT8 ) = ZERO
            DO 110 I = 1MNMIN - 1
               IFS1I ).LT.S1I+1 ) )
     $            RESULT8 ) = ULPINV
               IFS1I ).LT.ZERO )
     $            RESULT8 ) = ULPINV
  110       CONTINUE
            IFMNMIN.GE.1 ) THEN
               IFS1MNMIN ).LT.ZERO )
     $            RESULT8 ) = ULPINV
            END IF
*
*           Test 9:  Compare DBDSQR with and without singular vectors
*
            TEMP2 = ZERO
*
            DO 120 J = 1MNMIN
               TEMP1 = ABSS1J )-S2J ) ) /
     $                 MAXSQRTUNFL )*MAXS11 ), ONE ),
     $                 ULP*MAXABSS1J ) ), ABSS2J ) ) ) )
               TEMP2 = MAXTEMP1TEMP2 )
  120       CONTINUE
*
            RESULT9 ) = TEMP2
*
*           Test 10:  Sturm sequence test of singular values
*                     Go up by factors of two until it succeeds
*
            TEMP1 = THRESH*HALF-ULP )
*
            DO 130 J = 0LOG2UI
*               CALL DSVDCH( MNMIN, BD, BE, S1, TEMP1, IINFO )
               IFIINFO.EQ.0 )
     $            GO TO 140
               TEMP1 = TEMP1*TWO
  130       CONTINUE
*
  140       CONTINUE
            RESULT10 ) = TEMP1
*
*           Use DBDSQR to form the decomposition A := (QU) S (VT PT)
*           from the bidiagonal form A := Q B PT.
*
            IF.NOT.BIDIAG ) THEN
               CALL DCOPYMNMINBD1S21 )
               IFMNMIN.GT.0 )
     $            CALL DCOPYMNMIN-1BE1WORK1 )
*
               CALL DBDSQRUPLOMNMINNMNRHSS2WORKPTLDPT,
     $                      QLDQYLDXWORKMNMIN+1 ), IINFO )
*
*              Test 11:  Check the decomposition A := Q*U * S2 * VT*PT
*                   12:  Check the computation Z := U' * Q' * X
*                   13:  Check the orthogonality of Q*U
*                   14:  Check the orthogonality of VT*PT
*
               CALL DBDT01MN0ALDAQLDQS2DUMMAPT,
     $                      LDPTWORKRESULT11 ) )
               CALL DBDT02MNRHSXLDXYLDXQLDQWORK,
     $                      RESULT12 ) )
               CALL DORT01'Columns'MMQQLDQWORKLWORK,
     $                      RESULT13 ) )
               CALL DORT01'Rows'MNMINNPTLDPTWORKLWORK,
     $                      RESULT14 ) )
            END IF
*
*           Use DBDSDC to form the SVD of the bidiagonal matrix B:
*           B := U * S1 * VT
*
            CALL DCOPYMNMINBD1S11 )
            IFMNMIN.GT.0 )
     $         CALL DCOPYMNMIN-1BE1WORK1 )
            CALL DLASET'Full'MNMINMNMINZEROONEULDPT )
            CALL DLASET'Full'MNMINMNMINZEROONEVTLDPT )
*
            CALL DBDSDCUPLO'I'MNMINS1WORKULDPTVTLDPT,
     $                   DUMIDUMWORKMNMIN+1 ), IWORKIINFO )
*
*           Check error code from DBDSDC.
*
            IFIINFO.NE.0 ) THEN
               WRITENOUT, FMT = 9998 )'DBDSDC(vects)', IINFO, M, N,
     $            JTYPE, IOLDSD
               INFO = ABSIINFO )
               IFIINFO.LT.0 ) THEN
                  RETURN
               ELSE
                  RESULT15 ) = ULPINV
                  GO TO 170
               END IF
            END IF
*
*           Use DBDSDC to compute only the singular values of the
*           bidiagonal matrix B;  U and VT should not be modified.
*
            CALL DCOPYMNMINBD1S21 )
            IFMNMIN.GT.0 )
     $         CALL DCOPYMNMIN-1BE1WORK1 )
*
            CALL DBDSDCUPLO'N'MNMINS2WORKDUM1DUM1,
     $                   DUMIDUMWORKMNMIN+1 ), IWORKIINFO )
*
*           Check error code from DBDSDC.
*
            IFIINFO.NE.0 ) THEN
               WRITENOUT, FMT = 9998 )'DBDSDC(values)', IINFO, M, N,
     $            JTYPE, IOLDSD
               INFO = ABSIINFO )
               IFIINFO.LT.0 ) THEN
                  RETURN
               ELSE
                  RESULT18 ) = ULPINV
                  GO TO 170
               END IF
            END IF
*
*           Test 15:  Check the decomposition B := U * S1 * VT
*                16:  Check the orthogonality of U
*                17:  Check the orthogonality of VT
*
            CALL DBDT03UPLOMNMIN1BDBEULDPTS1VTLDPT,
     $                   WORKRESULT15 ) )
            CALL DORT01'Columns'MNMINMNMINULDPTWORKLWORK,
     $                   RESULT16 ) )
            CALL DORT01'Rows'MNMINMNMINVTLDPTWORKLWORK,
     $                   RESULT17 ) )
*
*           Test 18:  Check that the singular values are sorted in
*                     non-increasing order and are non-negative
*
            RESULT18 ) = ZERO
            DO 150 I = 1MNMIN - 1
               IFS1I ).LT.S1I+1 ) )
     $            RESULT18 ) = ULPINV
               IFS1I ).LT.ZERO )
     $            RESULT18 ) = ULPINV
  150       CONTINUE
            IFMNMIN.GE.1 ) THEN
               IFS1MNMIN ).LT.ZERO )
     $            RESULT18 ) = ULPINV
            END IF
*
*           Test 19:  Compare DBDSQR with and without singular vectors
*
            TEMP2 = ZERO
*
            DO 160 J = 1MNMIN
               TEMP1 = ABSS1J )-S2J ) ) /
     $                 MAXSQRTUNFL )*MAXS11 ), ONE ),
     $                 ULP*MAXABSS11 ) ), ABSS21 ) ) ) )
               TEMP2 = MAXTEMP1TEMP2 )
  160       CONTINUE
*
            RESULT19 ) = TEMP2
*
*           End of Loop -- Check for RESULT(j) > THRESH
*
  170       CONTINUE
            DO 180 J = 119
               IFRESULTJ ).GE.THRESH ) THEN
                  IFNFAIL.EQ.0 )
     $               CALL DLAHD2NOUTPATH )
                  WRITENOUT, FMT = 9999 )M, N, JTYPE, IOLDSD, J,
     $               RESULT( J )
                  NFAIL = NFAIL + 1
               END IF
  180       CONTINUE
            IF.NOT.BIDIAG ) THEN
               NTEST = NTEST + 19
            ELSE
               NTEST = NTEST + 5
            END IF
*
  190    CONTINUE
  200 CONTINUE
*
*     Summary
*
      CALL ALASUMPATHNOUTNFAILNTEST0 )
*
      RETURN
*
*     End of DCHKBD
*
 9999 FORMAT( ' M=', I5, ', N=', I5, ', type ', I2, ', seed=',
     $      4( I4, ',' ), ' test(', I2, ')=', G11.4 )
 9998 FORMAT( ' DCHKBD: ', A, ' returned INFO=', I6, '.', / 9X, 'M=',
     $      I6, ', N=', I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ),
     $      I5, ')' )
*
      END