@@ -394,3 +394,150 @@ CTEST(potrf, bug_695){
394
394
CTEST_ERR ("%s:%d got NaN" , __FILE__ , __LINE__ );
395
395
}
396
396
}
397
+
398
+
399
+ // Check potrf factorizes a small problem correctly
400
+ CTEST (potrf , smoketest_trivial ){
401
+ float A1s [4 ] = {2 , 0.3 , 0.3 , 3 };
402
+ double A1d [4 ] = {2 , 0.3 , 0.3 , 3 };
403
+ openblas_complex_float A1c [4 ] = {
404
+ openblas_make_complex_float (2 ,0 ),
405
+ openblas_make_complex_float (0.3 ,0.1 ),
406
+ openblas_make_complex_float (0.3 ,-0.1 ),
407
+ openblas_make_complex_float (3 ,0 )
408
+ };
409
+ openblas_complex_double A1z [4 ] = {
410
+ openblas_make_complex_double (2 ,0 ),
411
+ openblas_make_complex_double (0.3 ,0.1 ),
412
+ openblas_make_complex_double (0.3 ,-0.1 ),
413
+ openblas_make_complex_double (3 ,0 )
414
+ };
415
+ float zeros = 0 , ones = 1 ;
416
+ double zerod = 0 , oned = 1 ;
417
+ openblas_complex_float zeroc = openblas_make_complex_float (0 , 0 ),
418
+ onec = openblas_make_complex_float (1 , 0 );
419
+ openblas_complex_double zeroz = openblas_make_complex_double (0 , 0 ),
420
+ onez = openblas_make_complex_float (1 , 0 );
421
+
422
+ char uplo , trans1 , trans2 ;
423
+ blasint nv = 4 ;
424
+ blasint n = 2 ;
425
+ blasint inc = 1 ;
426
+ blasint info = 0 ;
427
+ int i , j , cycle ;
428
+
429
+ float As [4 ], Bs [4 ];
430
+ double Ad [4 ], Bd [4 ];
431
+ openblas_complex_float Ac [4 ], Bc [4 ];
432
+ openblas_complex_double Az [4 ], Bz [4 ];
433
+
434
+ for (cycle = 0 ; cycle < 2 ; ++ cycle ) {
435
+ if (cycle == 0 ) {
436
+ uplo = 'L' ;
437
+ }
438
+ else {
439
+ uplo = 'U' ;
440
+ }
441
+
442
+ BLASFUNC (scopy )(& nv , A1s , & inc , As , & inc );
443
+ BLASFUNC (dcopy )(& nv , A1d , & inc , Ad , & inc );
444
+ BLASFUNC (ccopy )(& nv , (float * )A1c , & inc , (float * )Ac , & inc );
445
+ BLASFUNC (zcopy )(& nv , (double * )A1z , & inc , (double * )Az , & inc );
446
+
447
+ BLASFUNC (spotrf )(& uplo , & n , As , & n , & info );
448
+ if (info != 0 ) {
449
+ CTEST_ERR ("%s:%d info != 0" , __FILE__ , __LINE__ );
450
+ }
451
+
452
+ BLASFUNC (dpotrf )(& uplo , & n , Ad , & n , & info );
453
+ if (info != 0 ) {
454
+ CTEST_ERR ("%s:%d info != 0" , __FILE__ , __LINE__ );
455
+ }
456
+
457
+ BLASFUNC (cpotrf )(& uplo , & n , (float * )Ac , & n , & info );
458
+ if (info != 0 ) {
459
+ CTEST_ERR ("%s:%d info != 0" , __FILE__ , __LINE__ );
460
+ }
461
+
462
+ BLASFUNC (zpotrf )(& uplo , & n , (double * )Az , & n , & info );
463
+ if (info != 0 ) {
464
+ CTEST_ERR ("%s:%d info != 0" , __FILE__ , __LINE__ );
465
+ }
466
+
467
+ /* Fill the other triangle */
468
+ if (uplo == 'L' ) {
469
+ for (i = 0 ; i < n ; ++ i ) {
470
+ for (j = i + 1 ; j < n ; ++ j ) {
471
+ As [i + n * j ] = 0 ;
472
+ Ad [i + n * j ] = 0 ;
473
+ Ac [i + n * j ] = zeroc ;
474
+ Az [i + n * j ] = zeroz ;
475
+ }
476
+ }
477
+ }
478
+ else {
479
+ for (i = 0 ; i < n ; ++ i ) {
480
+ for (j = 0 ; j < i ; ++ j ) {
481
+ As [i + n * j ] = 0 ;
482
+ Ad [i + n * j ] = 0 ;
483
+ Ac [i + n * j ] = zeroc ;
484
+ Az [i + n * j ] = zeroz ;
485
+ }
486
+ }
487
+ }
488
+
489
+ /* B = A A^H or A^H A */
490
+ if (uplo == 'L' ) {
491
+ trans1 = 'N' ;
492
+ trans2 = 'C' ;
493
+ }
494
+ else {
495
+ trans1 = 'C' ;
496
+ trans2 = 'N' ;
497
+ }
498
+
499
+ BLASFUNC (sgemm )(& trans1 , & trans2 , & n , & n , & n , & ones , As , & n , As , & n , & zeros , Bs , & n );
500
+ BLASFUNC (dgemm )(& trans1 , & trans2 , & n , & n , & n , & oned , Ad , & n , Ad , & n , & zerod , Bd , & n );
501
+ BLASFUNC (cgemm )(& trans1 , & trans2 , & n , & n , & n , (float * )& onec ,
502
+ (float * )Ac , & n , (float * )Ac , & n , (float * )& zeroc , (float * )Bc , & n );
503
+ BLASFUNC (zgemm )(& trans1 , & trans2 , & n , & n , & n , (double * )& onez ,
504
+ (double * )Az , & n , (double * )Az , & n , (double * )& zeroz , (double * )Bz , & n );
505
+
506
+ /* Check result is close to original */
507
+ for (i = 0 ; i < n ; ++ i ) {
508
+ for (j = 0 ; j < n ; ++ j ) {
509
+ double err ;
510
+
511
+ err = fabs (A1s [i + n * j ] - Bs [i + n * j ]);
512
+ if (err > 1e-5 ) {
513
+ CTEST_ERR ("%s:%d %c s(%d,%d) difference: %g" , __FILE__ , __LINE__ , uplo , i , j , err );
514
+ }
515
+
516
+ err = fabs (A1d [i + n * j ] - Bd [i + n * j ]);
517
+ if (err > 1e-12 ) {
518
+ CTEST_ERR ("%s:%d %c d(%d,%d) difference: %g" , __FILE__ , __LINE__ , uplo , i , j , err );
519
+ }
520
+
521
+ #ifdef OPENBLAS_COMPLEX_C99
522
+ err = cabsf (A1c [i + n * j ] - Bc [i + n * j ]);
523
+ #else
524
+ err = hypot (A1c [i + n * j ].real - Bc [i + n * j ].real ,
525
+ A1c [i + n * j ].imag - Bc [i + n * j ].imag );
526
+ #endif
527
+ if (err > 1e-5 ) {
528
+ CTEST_ERR ("%s:%d %c c(%d,%d) difference: %g" , __FILE__ , __LINE__ , uplo , i , j , err );
529
+ }
530
+
531
+ #ifdef OPENBLAS_COMPLEX_C99
532
+ err = cabs (A1z [i + n * j ] - Bz [i + n * j ]);
533
+ #else
534
+ err = hypot (A1z [i + n * j ].real - Bz [i + n * j ].real ,
535
+ A1z [i + n * j ].imag - Bz [i + n * j ].imag );
536
+ #endif
537
+ if (err > 1e-12 ) {
538
+ CTEST_ERR ("%s:%d %c z(%d,%d) difference: %g" , __FILE__ , __LINE__ , uplo , i , j , err );
539
+ }
540
+ }
541
+ }
542
+ }
543
+ }
0 commit comments