Skip to content

Commit f2de5e7

Browse files
author
Kent Knox
committed
Merge pull request #39 from gicmo/nrm2osx
[OSX] Fix crash in nrm2 tests
2 parents 68cbd37 + c87d8c6 commit f2de5e7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/tests/correctness/blas-lapack.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,20 @@ void zdscal( int n, double alpha, doublecomplex *x, int incx)
630630

631631
float sdot( int n, float *x, int incx, float *y, int incy)
632632
{
633+
#ifdef __APPLE__
634+
return cblas_sdot(n, x, incx, y, incy);
635+
#else
633636
return sdot_(&n, x, &incx, y, &incy);
637+
#endif
634638
}
635639

636640
double ddot( int n, double *x, int incx, double *y, int incy)
637641
{
642+
#ifdef __APPLE__
643+
return cblas_ddot(n, x, incx, y, incy);
644+
#else
638645
return ddot_(&n, x, &incx, y, &incy);
646+
#endif
639647
}
640648

641649
complex cdotu( int n, complex *x, int incx, complex *y, int incy)
@@ -840,42 +848,94 @@ int izamax( int n, doublecomplex *x, int incx)
840848

841849
float snrm2( int n, float *x, int incx)
842850
{
851+
#ifdef __APPLE__
852+
//On OSX passing negative values for incx can lead to a
853+
//a crash, so we catch it here (cf. Github issue #37).
854+
if (n < 1 || incx < 1) {
855+
return 0;
856+
}
857+
return cblas_snrm2(n, x, incx);
858+
#else
843859
return snrm2_(&n, x, &incx);
860+
#endif
844861
}
845862

846863
double dnrm2( int n, double *x, int incx)
847864
{
865+
#ifdef __APPLE__
866+
//On OSX passing negative values for incx can lead to a
867+
//a crash, so we catch it here (cf. Github issue #37).
868+
if (n < 1 || incx < 1) {
869+
return 0;
870+
}
871+
return cblas_dnrm2(n, x, incx);
872+
#else
848873
return dnrm2_(&n, x, &incx);
874+
#endif
849875
}
850876

851877
float scnrm2( int n, complex *x, int incx)
852878
{
879+
#ifdef __APPLE__
880+
//On OSX passing negative values for incx can lead to a
881+
//a crash, so we catch it here (cf. Github issue #37).
882+
if (n < 1 || incx < 1) {
883+
return 0;
884+
}
885+
return cblas_scnrm2(n, x, incx);
886+
#else
853887
return scnrm2_(&n, x, &incx);
888+
#endif
854889
}
855890

856891
double dznrm2( int n, doublecomplex *x, int incx)
857892
{
893+
#ifdef __APPLE__
894+
//On OSX passing negative values for incx can lead to a
895+
//a crash, so we catch it here (cf. Github issue #37).
896+
if (n < 1 || incx < 1) {
897+
return 0;
898+
}
899+
return cblas_dznrm2(n, x, incx);
900+
#else
858901
return dznrm2_(&n, x, &incx);
902+
#endif
859903
}
860904

861905
float sasum( int n, float *x, int incx)
862906
{
907+
#ifdef __APPLE__
908+
return cblas_sasum(n, x, incx);
909+
#else
863910
return sasum_(&n, x, &incx);
911+
#endif
864912
}
865913

866914
double dasum( int n, double *x, int incx)
867915
{
916+
#ifdef __APPLE__
917+
return cblas_dasum(n, x, incx);
918+
#else
868919
return dasum_(&n, x, &incx);
920+
#endif
869921
}
870922

871923
float scasum( int n, complex *x, int incx)
872924
{
925+
#ifdef __APPLE__
926+
return cblas_scasum(n, x, incx);
927+
#else
873928
return scasum_(&n, x, &incx);
929+
#endif
874930
}
875931

876932
double dzasum( int n, doublecomplex *x, int incx)
877933
{
934+
#ifdef __APPLE__
935+
return cblas_dzasum(n, x, incx);
936+
#else
878937
return dzasum_(&n, x, &incx);
938+
#endif
879939
}
880940

881941
#endif

0 commit comments

Comments
 (0)