Skip to content

Commit

Permalink
Merge pull request OpenMathLib#4465 from XiWeiGu/utest-zscal
Browse files Browse the repository at this point in the history
utest: Add tests for zscal
  • Loading branch information
martin-frbg authored Jan 31, 2024
2 parents 98c9ff3 + 969601a commit d134330
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 43 deletions.
91 changes: 50 additions & 41 deletions kernel/x86_64/zscal.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ static void zscal_kernel_8( BLASLONG n, FLOAT *alpha , FLOAT *x )

for( i=0; i<n; i+=4 )
{
t0 = da_r *x[0] - da_i *x[1];
t1 = da_r *x[2] - da_i *x[3];
t2 = da_r *x[4] - da_i *x[5];
t3 = da_r *x[6] - da_i *x[7];
t0 = da_r *x[0] - da_i *x[1];
t1 = da_r *x[2] - da_i *x[3];
t2 = da_r *x[4] - da_i *x[5];
t3 = da_r *x[6] - da_i *x[7];

x[1] = da_r * x[1] + da_i * x[0];
x[3] = da_r * x[3] + da_i * x[2];
x[5] = da_r * x[5] + da_i * x[4];
x[7] = da_r * x[7] + da_i * x[6];

x[0] = t0;
x[2] = t1;
x[4] = t2;
Expand All @@ -99,16 +99,16 @@ static void zscal_kernel_8_zero_r( BLASLONG n, FLOAT *alpha , FLOAT *x )

for( i=0; i<n; i+=4 )
{
t0 = - da_i *x[1];
t1 = - da_i *x[3];
t2 = - da_i *x[5];
t3 = - da_i *x[7];
t0 = - da_i *x[1];
t1 = - da_i *x[3];
t2 = - da_i *x[5];
t3 = - da_i *x[7];

x[1] = da_i * x[0];
x[3] = da_i * x[2];
x[5] = da_i * x[4];
x[7] = da_i * x[6];

x[0] = t0;
x[2] = t1;
x[4] = t2;
Expand All @@ -129,16 +129,16 @@ static void zscal_kernel_8_zero_i( BLASLONG n, FLOAT *alpha , FLOAT *x )

for( i=0; i<n; i+=4 )
{
t0 = da_r *x[0];
t1 = da_r *x[2];
t2 = da_r *x[4];
t3 = da_r *x[6];
t0 = da_r *x[0];
t1 = da_r *x[2];
t2 = da_r *x[4];
t3 = da_r *x[6];

x[1] = da_r * x[1];
x[3] = da_r * x[3];
x[5] = da_r * x[5];
x[7] = da_r * x[7];

x[0] = t0;
x[2] = t1;
x[4] = t2;
Expand All @@ -157,14 +157,14 @@ static void zscal_kernel_8_zero( BLASLONG n, FLOAT *alpha , FLOAT *x )
BLASLONG i;
for( i=0; i<n; i+=4 )
{
x[0] = 0.0;
x[1] = 0.0;
x[2] = 0.0;
x[3] = 0.0;
x[4] = 0.0;
x[5] = 0.0;
x[6] = 0.0;
x[7] = 0.0;
x[0] = 0.0;
x[1] = 0.0;
x[2] = 0.0;
x[3] = 0.0;
x[4] = 0.0;
x[5] = 0.0;
x[6] = 0.0;
x[7] = 0.0;
x+=8;
}

Expand All @@ -186,10 +186,10 @@ static void zscal_kernel_inc_8(BLASLONG n, FLOAT *alpha, FLOAT *x, BLASLONG inc_

for ( i=0; i<n; i+=4 )
{
t0 = da_r * x[0] - da_i *x[1];
t1 = da_r * x[inc_x] - da_i *x[inc_x + 1];
t2 = da_r * x[inc_x2] - da_i *x[inc_x2 + 1];
t3 = da_r * x[inc_x3] - da_i *x[inc_x3 + 1];
t0 = da_r * x[0] - da_i *x[1];
t1 = da_r * x[inc_x] - da_i *x[inc_x + 1];
t2 = da_r * x[inc_x2] - da_i *x[inc_x2 + 1];
t3 = da_r * x[inc_x3] - da_i *x[inc_x3 + 1];

x[1] = da_i * x[0] + da_r * x[1];
x[inc_x +1] = da_i * x[inc_x] + da_r * x[inc_x +1];
Expand Down Expand Up @@ -228,7 +228,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
{
while(j < n1)
{

x[i]=0.0;
x[i+1]=0.0;
x[i+inc_x]=0.0;
Expand All @@ -240,7 +240,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,

while(j < n)
{

x[i]=0.0;
x[i+1]=0.0;
i += inc_x ;
Expand All @@ -253,11 +253,17 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
{
while(j < n1)
{

temp0 = -da_i * x[i+1];

if (isnan(x[i]) || isinf(x[i]))
temp0 = NAN;
else
temp0 = -da_i * x[i+1];
x[i+1] = da_i * x[i];
x[i] = temp0;
temp1 = -da_i * x[i+1+inc_x];
if (isnan(x[i+inc_x]) || isinf(x[i+inc_x]))
temp1 = NAN;
else
temp1 = -da_i * x[i+1+inc_x];
x[i+1+inc_x] = da_i * x[i+inc_x];
x[i+inc_x] = temp1;
i += 2*inc_x ;
Expand All @@ -267,8 +273,11 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,

while(j < n)
{

temp0 = -da_i * x[i+1];

if (isnan(x[i]) || isinf(x[i]))
temp0 = NAN;
else
temp0 = -da_i * x[i+1];
x[i+1] = da_i * x[i];
x[i] = temp0;
i += inc_x ;
Expand All @@ -291,7 +300,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,

while(j < n1)
{

temp0 = da_r * x[i];
x[i+1] = da_r * x[i+1];
x[i] = temp0;
Expand All @@ -305,7 +314,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,

while(j < n)
{

temp0 = da_r * x[i];
x[i+1] = da_r * x[i+1];
x[i] = temp0;
Expand Down Expand Up @@ -368,7 +377,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
}
i = n1 << 1;
j = n1;

if ( da_r == 0.0 || da_r != da_r )
{
if ( da_i == 0.0 )
Expand All @@ -385,7 +394,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
}

}
else if (da_r < -FLT_MAX || da_r > FLT_MAX) {
else if (da_r < -FLT_MAX || da_r > FLT_MAX) {
while(j < n)
{
x[i]= NAN;
Expand All @@ -404,7 +413,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
if (x[i] < -FLT_MAX || x[i] > FLT_MAX)
temp0 = NAN;
x[i+1] = da_i * x[i];
if ( x[i] == x[i]) //preserve NaN
if ( x[i] == x[i]) //preserve NaN
x[i] = temp0;
i += 2 ;
j++;
Expand All @@ -420,7 +429,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,
{
while(j < n)
{

temp0 = da_r * x[i];
x[i+1] = da_r * x[i+1];
x[i] = temp0;
Expand All @@ -442,7 +451,7 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i,

}

}
}

}

Expand Down
52 changes: 50 additions & 2 deletions utest/test_zscal.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ CTEST(zscal, i_nan)
ASSERT_TRUE(isnan(nan[17]));
}

CTEST(zscal, i_nan_inc_2)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0,
NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
cblas_zscal(9, i, &nan, 2);
ASSERT_TRUE(isnan(nan[0]));
ASSERT_TRUE(isnan(nan[1]));
ASSERT_TRUE(isnan(nan[16]));
ASSERT_TRUE(isnan(nan[17]));
}

CTEST(zscal, nan_i)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
Expand All @@ -30,7 +42,19 @@ CTEST(zscal, nan_i)
ASSERT_TRUE(isnan(i[16]));
ASSERT_TRUE(isnan(i[17]));
}


CTEST(zscal, nan_i_inc_2)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1,
0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
cblas_zscal(9, &nan, &i, 2);
ASSERT_TRUE(isnan(i[0]));
ASSERT_TRUE(isnan(i[1]));
ASSERT_TRUE(isnan(i[16]));
ASSERT_TRUE(isnan(i[17]));
}

CTEST(zscal, i_inf)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
Expand All @@ -40,7 +64,19 @@ CTEST(zscal, i_inf)
ASSERT_TRUE(isinf(inf[1]));
ASSERT_TRUE(isnan(inf[16]));
ASSERT_TRUE(isinf(inf[17]));
}
}

CTEST(zscal, i_inf_inc_2)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0,
INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
cblas_zscal(9, i, &inf, 2);
ASSERT_TRUE(isnan(inf[0]));
ASSERT_TRUE(isinf(inf[1]));
ASSERT_TRUE(isnan(inf[16]));
ASSERT_TRUE(isinf(inf[17]));
}

CTEST(zscal, inf_i)
{
Expand All @@ -53,4 +89,16 @@ CTEST(zscal, inf_i)
ASSERT_TRUE(isinf(i[17]));
}

CTEST(zscal, inf_i_inc_2)
{
double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1,
0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
cblas_zscal(9, &inf, &i, 2);
ASSERT_TRUE(isnan(i[0]));
ASSERT_TRUE(isinf(i[1]));
ASSERT_TRUE(isnan(i[16]));
ASSERT_TRUE(isinf(i[17]));
}

#endif

0 comments on commit d134330

Please sign in to comment.