Skip to content

Commit 686e6d7

Browse files
authored
Merge pull request #3676 from martin-frbg/dnrm2-utest
Add DNRM2 regression test for issues 2998 and 3654
2 parents bf8998a + c5041ae commit 686e6d7

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

utest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ else ()
1313
test_rot.c
1414
test_axpy.c
1515
test_dsdot.c
16+
test_dnrm2.c
1617
test_swap.c
1718
)
1819
endif ()

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
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
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_dnrm2.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2022, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
**********************************************************************************/
33+
34+
#include "openblas_utest.h"
35+
#if defined(BUILD_DOUBLE)
36+
37+
#ifndef INFINITY
38+
#define INFINITY HUGE_VAL
39+
#endif
40+
41+
CTEST(dnrm2,dnrm2_inf)
42+
{
43+
int i;
44+
double x[29];
45+
blasint incx=1;
46+
blasint n=28;
47+
double res1=0.0f, res2=INFINITY;
48+
49+
for (i=0;i<n;i++)x[i]=0.0f;
50+
x[10]=-INFINITY;
51+
res1=BLASFUNC(dnrm2)(&n, x, &incx);
52+
ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
53+
54+
}
55+
CTEST(dnrm2,dnrm2_tiny)
56+
{
57+
int i;
58+
double x[29];
59+
blasint incx=1;
60+
blasint n=28;
61+
double res1=0.0f, res2=0.0f;
62+
63+
for (i=0;i<n;i++)x[i]=7.457008414e-310;
64+
res1=BLASFUNC(dnrm2)(&n, x, &incx);
65+
ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
66+
}
67+
#endif

utest/utest_main2.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,38 @@ CTEST(dsdot,dsdot_n_1)
369369

370370
}
371371

372+
#if defined(BUILD_DOUBLE)
373+
CTEST(dnrm2,dnrm2_inf)
374+
{
375+
#ifndef INFINITY
376+
#define INFINITY HUGE_VAL
377+
#endif
378+
int i;
379+
double x[29];
380+
blasint incx=1;
381+
blasint n=28;
382+
double res1=0.0f, res2=INFINITY;
383+
384+
for (i=0;i<n;i++)x[i]=0.0f;
385+
x[10]=-INFINITY;
386+
res1=BLASFUNC(dnrm2)(&n, x, &incx);
387+
ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
388+
389+
}
390+
CTEST(dnrm2,dnrm2_tiny)
391+
{
392+
int i;
393+
double x[29];
394+
blasint incx=1;
395+
blasint n=28;
396+
double res1=0.0f, res2=0.0f;
397+
398+
for (i=0;i<n;i++)x[i]=7.457008414e-310;
399+
res1=BLASFUNC(dnrm2)(&n, x, &incx);
400+
ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
401+
}
402+
#endif
403+
372404
CTEST(rot,drot_inc_0)
373405
{
374406
blasint i=0;
@@ -606,6 +638,8 @@ int main(int argc, const char ** argv){
606638
CTEST_ADD (zdotu,zdotu_n_1);
607639
CTEST_ADD (zdotu,zdotu_offset_1);
608640
CTEST_ADD (dsdot,dsdot_n_1);
641+
CTEST_ADD (dnrm2,dnrm2_inf);
642+
CTEST_ADD (dnrm2,dnrm2_tiny);
609643
CTEST_ADD (rot,drot_inc_0);
610644
CTEST_ADD (rot,zdrot_inc_0);
611645
CTEST_ADD (rot,srot_inc_0);

0 commit comments

Comments
 (0)