Skip to content

Commit e48627c

Browse files
authored
Add tests for ZSCAL with NaN and Inf arguments
1 parent 1412d2d commit e48627c

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

utest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ else ()
1515
test_dsdot.c
1616
test_dnrm2.c
1717
test_swap.c
18+
test_zscal.c
1819
)
1920
endif ()
2021

utest/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ UTESTBIN=openblas_utest
1111

1212
include $(TOPDIR)/Makefile.system
1313

14-
OBJS=utest_main.o test_min.o test_amax.o test_ismin.o test_rotmg.o test_axpy.o test_dotu.o test_dsdot.o test_swap.o test_rot.o test_dnrm2.o
14+
OBJS=utest_main.o test_min.o test_amax.o test_ismin.o test_rotmg.o test_axpy.o test_dotu.o test_dsdot.o test_swap.o test_rot.o test_dnrm2.o test_zscal.o
1515
#test_rot.o test_swap.o test_axpy.o test_dotu.o test_dsdot.o test_fork.o
1616

1717
ifneq ($(NO_LAPACK), 1)

utest/test_zscal.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "openblas_utest.h"
2+
#include <cblas.h>
3+
#ifdef BUILD_COMPLEX16
4+
5+
CTEST(zscal, i_nan)
6+
{
7+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
8+
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
9+
cblas_zscal(9, i, &nan, 1);
10+
ASSERT_TRUE(isnan(nan[0]));
11+
ASSERT_TRUE(isnan(nan[1]));
12+
ASSERT_TRUE(isnan(nan[16]));
13+
ASSERT_TRUE(isnan(nan[17]));
14+
}
15+
16+
CTEST(zscal, nan_i)
17+
{
18+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
19+
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
20+
cblas_zscal(9, &nan, &i, 1);
21+
ASSERT_TRUE(isnan(i[0]));
22+
ASSERT_TRUE(isnan(i[1]));
23+
ASSERT_TRUE(isnan(i[16]));
24+
ASSERT_TRUE(isnan(i[17]));
25+
}
26+
27+
CTEST(zscal, i_inf)
28+
{
29+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
30+
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
31+
cblas_zscal(9, i, &inf, 1);
32+
ASSERT_TRUE(isnan(inf[0]));
33+
ASSERT_TRUE(isinf(inf[1]));
34+
ASSERT_TRUE(isnan(inf[16]));
35+
ASSERT_TRUE(isinf(inf[17]));
36+
}
37+
38+
CTEST(zscal, inf_i)
39+
{
40+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
41+
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
42+
cblas_zscal(9, &inf, &i, 1);
43+
ASSERT_TRUE(isnan(i[0]));
44+
ASSERT_TRUE(isinf(i[1]));
45+
ASSERT_TRUE(isnan(i[16]));
46+
ASSERT_TRUE(isinf(i[17]));
47+
}
48+
49+
#endif

utest/utest_main2.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,51 @@ CTEST(max, smax_zero){
617617
ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
618618
}
619619

620+
621+
CTEST(zscal, i_nan)
622+
{
623+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
624+
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
625+
cblas_zscal(9, i, &nan, 1);
626+
ASSERT(isnan(nan[0]);
627+
ASSERT(isnan(nan[1]);
628+
ASSERT(isnan(nan[16]);
629+
ASSERT(isnan(nan[17]);
630+
}
631+
632+
CTEST(zscal, nan_i)
633+
{
634+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
635+
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
636+
cblas_zscal(9, &nan, &i, 1);
637+
ASSERT(isnan(i[0]);
638+
ASSERT(isnan(i[1]);
639+
ASSERT(isnan(i[16]);
640+
ASSERT(isnan(i[17]);
641+
}
642+
643+
CTEST(zscal, i_inf)
644+
{
645+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
646+
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
647+
cblas_zscal(9, i, &inf, 1);
648+
ASSERT(isnan(inf[0]);
649+
ASSERT(isinf(inf[1]);
650+
ASSERT(isnan(inf[16]);
651+
ASSERT(isinf(inf[17]);
652+
}
653+
654+
CTEST(zscal, inf_i)
655+
{
656+
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
657+
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
658+
cblas_zscal(9, &inf, &i, 1);
659+
ASSERT(isnan(i[0]);
660+
ASSERT(isinf(i[1]);
661+
ASSERT(isnan(i[16]);
662+
ASSERT(isinf(i[17]);
663+
}
664+
620665
int main(int argc, const char ** argv){
621666

622667
CTEST_ADD (amax, samax);
@@ -648,7 +693,10 @@ int main(int argc, const char ** argv){
648693
CTEST_ADD (swap,zswap_inc_0);
649694
CTEST_ADD (swap,sswap_inc_0);
650695
CTEST_ADD (swap,cswap_inc_0);
651-
696+
CTEST_ADD (zscal, i_nan);
697+
CTEST_ADD (zscal, nan_i);
698+
CTEST_ADD (zscal, i_inf);
699+
CTEST_ADD (zscal, inf_i);
652700
int num_fail=0;
653701

654702
num_fail=ctest_main(argc, argv);

0 commit comments

Comments
 (0)