Skip to content

Commit 1a2367b

Browse files
Tests now check for multiple input sizes.
1 parent 4c2ed57 commit 1a2367b

374 files changed

Lines changed: 2675 additions & 2325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BLAS/docs/TOLERANCES.md

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,45 @@
11
# Differentiation test tolerances
22

3-
Tolerances and step sizes used for finite-difference checks in BLAS differentiation tests (scalar/vector, forward/reverse). All modes use the same precision-based scheme unless a mixed-precision override applies.
3+
Tolerances and step sizes for finite-difference derivative checks in the BLAS differentiation test generator.
44

55
---
66

7-
## Base tolerances by precision
7+
## Defaults
88

9-
| Family | Description | rtol | atol |
10-
|--------|-----------------------|---------|---------|
11-
| S | single real (`S*`) | 2.0e-3 | 2.0e-3 |
12-
| C | single complex (`C*`) | 1.0e-3 | 1.0e-3 |
13-
| D | double real (`D*`) | 1.0e-5 | 1.0e-5 |
14-
| Z | double complex (`Z*`) | 1.0e-5 | 1.0e-5 |
9+
### rtol/atol by precision family
1510

16-
These values are used in:
11+
| Family | Meaning | rtol | atol |
12+
|--------|---------|------|------|
13+
| S | `S*` (single real) | 2.0e-3 | 2.0e-3 |
14+
| C | `C*` (single complex) | 1.0e-3 | 1.0e-3 |
15+
| D | `D*` (double real) | 1.0e-5 | 1.0e-5 |
16+
| Z | `Z*` (double complex) | 1.0e-5 | 1.0e-5 |
1717

18-
- Scalar forward
19-
- Scalar reverse
20-
- Vector forward
21-
- Vector reverse
18+
### step size h by precision family
2219

23-
---
24-
25-
## Step size (h)
26-
27-
For non–mixed-precision functions:
28-
29-
| Precision | h |
30-
|------------|----------|
31-
| S*, C* | 1.0e-3 |
32-
| D*, Z* | 1.0e-7 |
33-
34-
(≈ 10·√ε for double precision.)
20+
| Family | h |
21+
|--------|---|
22+
| S, C | 1.0e-3 |
23+
| D, Z | 1.0e-7 |
3524

3625
---
3726

38-
## Mixed-precision override
39-
40-
For routines whose **output is double precision** but whose **first differentiable input** is **single precision** (e.g. `DSDOT`), the generator uses single-precision–style settings so the finite-difference check matches the conditioning of the inputs:
27+
## Overrides
4128

42-
- **h** = 1.0e-3
43-
- **rtol** = 2.0e-3
44-
- **atol** = 2.0e-3
29+
### Mixed-precision D* (single-precision first differentiable input)
4530

46-
This override is applied in:
31+
Applies when the routine behaves like “double output, but first differentiable input is single precision” (e.g. `DSDOT` with **SX** first; the generator also treats **SY** and **SB** as single-precision inputs for `D*`).
4732

48-
- Scalar reverse
49-
- Vector forward
50-
- Vector reverse
33+
- **Scalar forward**: override **h = 1.0e-3** (rtol/atol remain `D*` base = 1.0e-5)
34+
- **Scalar reverse / vector forward / vector reverse**: override **h = 1.0e-3**, **rtol = atol = 2.0e-3**
5135

52-
Detection: `precision_type == real(8)` and the first entry in the `inputs` list has `get_param_precision(first_input, func_name, param_types) == "real(4)"`. In the generator, `get_param_precision` returns `real(4)` for **D\*** functions when the parameter is one of **SX**, **SY**, **SB**.
53-
54-
---
55-
56-
## Mixed-precision tests (list)
57-
58-
A test is treated as mixed-precision if it is for a **D\*** (or **Z\***) routine and the **first differentiable input** is single precision. The generator explicitly treats **SX**, **SY**, and **SB** as single precision for **D\*** routines.
59-
60-
**Routines that use the mixed-precision override** (when present in the suite and documented with that input order):
61-
62-
| Routine | First input(s) | Modes using override |
63-
|---------|----------------|-----------------------------|
64-
| **DSDOT** | SX (then SY) | Scalar reverse, vector forward, vector reverse |
65-
66-
**Note:** Any other **D\*** routine whose first `\param[in]` is **SX**, **SY**, or **SB** will also get the override. There is no **Z\*** branch for single-precision inputs in `get_param_precision`, so currently only **D\*** routines can be mixed-precision in this sense. If you add a **D\*** (or in future **Z\***) routine with a single-precision first input, it will automatically receive the same h and tolerances as above.
67-
68-
---
36+
### Relaxed C* tolerance in vector reverse
6937

70-
## Summary table (all modes)
38+
Only for **single-precision complex** (`C*`) **vector reverse** tests:
7139

72-
| Mode | S* / C* (h) | D* / Z* (h) | Mixed-precision (h, rtol, atol) |
73-
|------------------|-------------|-------------|---------------------------------------|
74-
| Scalar forward | 1e-3 / 2e-3 or 1e-3 | 1e-7 / 1e-5 | h = 1e-3 only (rtol/atol stay 1e-5) |
75-
| Scalar reverse | 1e-3 / 2e-3 or 1e-3 | 1e-7 / 1e-5 | 1e-3, 2e-3, 2e-3 |
76-
| Vector forward | 1e-3 / 2e-3 or 1e-3 | 1e-7 / 1e-5 | 1e-3, 2e-3, 2e-3 |
77-
| Vector reverse | 1e-3 / 2e-3 or 1e-3 | 1e-7 / 1e-5 | 1e-3, 2e-3, 2e-3 |
40+
| Routine family (examples) | rtol/atol |
41+
|---------------------------|-----------|
42+
| DOT (e.g. `CDOTC`) | 2.5e-2 |
43+
| BLAS3 (e.g. `CGEMM`, `CSYMM`, `CHEMM`) | 1.0e-2 |
7844

79-
(Base tolerances for S/C/D/Z are as in the first table; mixed-precision replaces h and rtol/atol only where indicated. In scalar forward, mixed-precision only changes the step size h to 1e-3; rtol/atol remain 1e-5.)
45+
All other `C*` modes use the base tolerance (1.0e-3). `Z*` does not use relaxed tolerances.

BLAS/test/test_caxpy.f90

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ program test_caxpy
1111

1212
integer :: n_test
1313
integer :: seed_array(33)
14-
integer :: test_sizes(1)
14+
integer :: test_sizes(3)
1515
integer :: i
1616
logical :: passed, all_passed
1717

1818
seed_array = 42
1919
call random_seed(put=seed_array)
2020

21-
test_sizes = (/ 4 /)
21+
test_sizes = (/ 4, 10, 25 /)
2222
write(*,*) 'Testing CAXPY (multi-size: n = 4)'
2323
all_passed = .true.
24-
do i = 1, 1
24+
do i = 1, 3
2525
n_test = test_sizes(i)
2626
call run_test_for_size(n_test, passed)
2727
all_passed = all_passed .and. passed
@@ -48,13 +48,13 @@ subroutine run_test_for_size(n, passed)
4848

4949
! Derivative variables
5050
complex(4), dimension(n) :: cx_d
51-
complex(4), dimension(n) :: cy_d
5251
complex(4) :: ca_d
52+
complex(4), dimension(n) :: cy_d
5353

5454
! Array restoration and derivative storage
5555
complex(4), dimension(n) :: cx_orig, cx_d_orig
56-
complex(4), dimension(n) :: cy_orig, cy_d_orig
5756
complex(4) :: ca_orig, ca_d_orig
57+
complex(4), dimension(n) :: cy_orig, cy_d_orig
5858
real(4) :: temp_re, temp_im ! For complex random init
5959
integer :: i, j
6060

@@ -82,42 +82,44 @@ subroutine run_test_for_size(n, passed)
8282
call random_number(temp_im)
8383
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8484
end do
85+
call random_number(temp_re)
86+
call random_number(temp_im)
87+
ca_d = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8588
do i = 1, n
8689
call random_number(temp_re)
8790
call random_number(temp_im)
8891
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8992
end do
90-
call random_number(temp_re)
91-
call random_number(temp_im)
92-
ca_d = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
9393

9494
! Store _orig and _d_orig
9595
cx_d_orig = cx_d
96-
cy_d_orig = cy_d
9796
ca_d_orig = ca_d
97+
cy_d_orig = cy_d
9898
cx_orig = cx
99-
cy_orig = cy
10099
ca_orig = ca
100+
cy_orig = cy
101101

102102
write(*,*) 'Testing CAXPY (n =', n, ')'
103103
cy_orig = cy
104104

105105
! Call the differentiated function
106106
call caxpy_d(nsize, ca, ca_d, cx, cx_d, 1, cy, cy_d, 1)
107+
cx_d = cx_d_orig
108+
ca_d = ca_d_orig
107109

108110
write(*,*) 'Function calls completed successfully'
109111

110112
! Numerical differentiation check
111-
call check_derivatives_numerically(n, nsize, cx_orig, cy_orig, ca_orig, cx_d_orig, cy_d_orig, ca_d_orig, cy_d, passed)
113+
call check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy_d_orig, cx_d_orig, ca_d_orig, cy_d, passed)
112114

113115
end subroutine run_test_for_size
114116

115-
subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, ca_orig, cx_d_orig, cy_d_orig, ca_d_orig, cy_d, passed)
117+
subroutine check_derivatives_numerically(n, nsize, cy_orig, cx_orig, ca_orig, cy_d_orig, cx_d_orig, ca_d_orig, cy_d, passed)
116118
implicit none
117119
integer, intent(in) :: n
118120
integer, intent(in) :: nsize
119-
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
120121
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
122+
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
121123
complex(4), intent(in) :: ca_orig, ca_d_orig
122124
complex(4), intent(in) :: cy_d(n)
123125
logical, intent(out) :: passed
@@ -129,8 +131,8 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, ca_orig, cx
129131
logical :: has_large_errors
130132
complex(4), dimension(n) :: cy_forward, cy_backward
131133
integer :: i, j
132-
complex(4), dimension(n) :: cx
133134
complex(4), dimension(n) :: cy
135+
complex(4), dimension(n) :: cx
134136
complex(4) :: ca
135137

136138
max_error = 0.0e0
@@ -140,15 +142,15 @@ subroutine check_derivatives_numerically(n, nsize, cx_orig, cy_orig, ca_orig, cx
140142
write(*,*) 'Step size h =', h
141143

142144
! Forward perturbation: f(x + h)
143-
cx = cx_orig + h * cx_d_orig
144145
cy = cy_orig + h * cy_d_orig
146+
cx = cx_orig + h * cx_d_orig
145147
ca = ca_orig + h * ca_d_orig
146148
call caxpy(nsize, ca, cx, 1, cy, 1)
147149
cy_forward = cy
148150

149151
! Backward perturbation: f(x - h)
150-
cx = cx_orig - h * cx_d_orig
151152
cy = cy_orig - h * cy_d_orig
153+
cx = cx_orig - h * cx_d_orig
152154
ca = ca_orig - h * ca_d_orig
153155
call caxpy(nsize, ca, cx, 1, cy, 1)
154156
cy_backward = cy

BLAS/test/test_caxpy_reverse.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ program test_caxpy_reverse
1111

1212
integer :: n_test
1313
integer :: seed_array(33)
14-
integer :: test_sizes(1)
14+
integer :: test_sizes(3)
1515
integer :: i
1616
logical :: passed, all_passed
1717

1818
seed_array = 42
1919
call random_seed(put=seed_array)
2020

21-
test_sizes = (/ 4 /)
21+
test_sizes = (/ 4, 10, 25 /)
2222
write(*,*) 'Testing CAXPY (multi-size: n = 4)'
2323
all_passed = .true.
24-
do i = 1, 1
24+
do i = 1, 3
2525
n_test = test_sizes(i)
2626
call run_test_for_size(n_test, passed)
2727
all_passed = all_passed .and. passed

BLAS/test/test_caxpy_vector_forward.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ program test_caxpy_vector_forward
1212
integer :: nbdirs
1313
integer :: n_test
1414
integer :: seed_array(33)
15-
integer :: test_sizes(1)
15+
integer :: test_sizes(3)
1616
integer :: i
1717
logical :: passed, all_passed
1818

1919
seed_array = 42
2020
call random_seed(put=seed_array)
2121

22-
test_sizes = (/ 4 /)
22+
test_sizes = (/ 4, 10, 25 /)
2323
write(*,*) 'Testing CAXPY (Vector Forward, multi-size: n = 4)'
2424
all_passed = .true.
25-
do i = 1, 1
25+
do i = 1, 3
2626
n_test = test_sizes(i)
2727
nbdirs = test_sizes(i)
2828
call run_test_for_size(n_test, passed, nbdirs)

BLAS/test/test_caxpy_vector_reverse.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ program test_caxpy_vector_reverse
1212
integer :: nbdirs
1313
integer :: n_test
1414
integer :: seed_array(33)
15-
integer :: test_sizes(1)
15+
integer :: test_sizes(3)
1616
integer :: i
1717
logical :: passed, all_passed
1818

1919
seed_array = 42
2020
call random_seed(put=seed_array)
2121

22-
test_sizes = (/ 4 /)
22+
test_sizes = (/ 4, 10, 25 /)
2323
write(*,*) 'Testing CAXPY (Vector Reverse, multi-size: n =', test_sizes(1), ')'
2424
all_passed = .true.
25-
do i = 1, 1
25+
do i = 1, 3
2626
n_test = test_sizes(i)
2727
nbdirs = test_sizes(i)
2828
call run_test_for_size(n_test, passed, nbdirs)

BLAS/test/test_ccopy.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ program test_ccopy
1111

1212
integer :: n_test
1313
integer :: seed_array(33)
14-
integer :: test_sizes(1)
14+
integer :: test_sizes(3)
1515
integer :: i
1616
logical :: passed, all_passed
1717

1818
seed_array = 42
1919
call random_seed(put=seed_array)
2020

21-
test_sizes = (/ 4 /)
21+
test_sizes = (/ 4, 10, 25 /)
2222
write(*,*) 'Testing CCOPY (multi-size: n = 4)'
2323
all_passed = .true.
24-
do i = 1, 1
24+
do i = 1, 3
2525
n_test = test_sizes(i)
2626
call run_test_for_size(n_test, passed)
2727
all_passed = all_passed .and. passed
@@ -96,6 +96,7 @@ subroutine run_test_for_size(n, passed)
9696

9797
! Call the differentiated function
9898
call ccopy_d(nsize, cx, cx_d, 1, cy, cy_d, 1)
99+
cx_d = cx_d_orig
99100

100101
! Reset ISIZE globals to uninitialized (-1)
101102
call set_ISIZE1OFCy(-1)

BLAS/test/test_ccopy_reverse.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ program test_ccopy_reverse
1111

1212
integer :: n_test
1313
integer :: seed_array(33)
14-
integer :: test_sizes(1)
14+
integer :: test_sizes(3)
1515
integer :: i
1616
logical :: passed, all_passed
1717

1818
seed_array = 42
1919
call random_seed(put=seed_array)
2020

21-
test_sizes = (/ 4 /)
21+
test_sizes = (/ 4, 10, 25 /)
2222
write(*,*) 'Testing CCOPY (multi-size: n = 4)'
2323
all_passed = .true.
24-
do i = 1, 1
24+
do i = 1, 3
2525
n_test = test_sizes(i)
2626
call run_test_for_size(n_test, passed)
2727
all_passed = all_passed .and. passed

BLAS/test/test_ccopy_vector_forward.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ program test_ccopy_vector_forward
1212
integer :: nbdirs
1313
integer :: n_test
1414
integer :: seed_array(33)
15-
integer :: test_sizes(1)
15+
integer :: test_sizes(3)
1616
integer :: i
1717
logical :: passed, all_passed
1818

1919
seed_array = 42
2020
call random_seed(put=seed_array)
2121

22-
test_sizes = (/ 4 /)
22+
test_sizes = (/ 4, 10, 25 /)
2323
write(*,*) 'Testing CCOPY (Vector Forward, multi-size: n = 4)'
2424
all_passed = .true.
25-
do i = 1, 1
25+
do i = 1, 3
2626
n_test = test_sizes(i)
2727
nbdirs = test_sizes(i)
2828
call run_test_for_size(n_test, passed, nbdirs)

BLAS/test/test_ccopy_vector_reverse.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ program test_ccopy_vector_reverse
1212
integer :: nbdirs
1313
integer :: n_test
1414
integer :: seed_array(33)
15-
integer :: test_sizes(1)
15+
integer :: test_sizes(3)
1616
integer :: i
1717
logical :: passed, all_passed
1818

1919
seed_array = 42
2020
call random_seed(put=seed_array)
2121

22-
test_sizes = (/ 4 /)
22+
test_sizes = (/ 4, 10, 25 /)
2323
write(*,*) 'Testing CCOPY (Vector Reverse, multi-size: n =', test_sizes(1), ')'
2424
all_passed = .true.
25-
do i = 1, 1
25+
do i = 1, 3
2626
n_test = test_sizes(i)
2727
nbdirs = test_sizes(i)
2828
call run_test_for_size(n_test, passed, nbdirs)

0 commit comments

Comments
 (0)