Skip to content

Commit 5bbe7ba

Browse files
Add more outlining
1 parent 6ef08c1 commit 5bbe7ba

338 files changed

Lines changed: 25480 additions & 55180 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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Differentiation test tolerances
2+
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.
4+
5+
---
6+
7+
## Base tolerances by precision
8+
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 |
15+
16+
These values are used in:
17+
18+
- Scalar forward
19+
- Scalar reverse
20+
- Vector forward
21+
- Vector reverse
22+
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.)
35+
36+
---
37+
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:
41+
42+
- **h** = 1.0e-3
43+
- **rtol** = 2.0e-3
44+
- **atol** = 2.0e-3
45+
46+
This override is applied in:
47+
48+
- Scalar reverse
49+
- Vector forward
50+
- Vector reverse
51+
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+
---
69+
70+
## Summary table (all modes)
71+
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 |
78+
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.)

BLAS/run_tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,13 @@ run_single_test() {
309309
local has_acceptable=false
310310
local has_outside_tolerance=false
311311

312-
if grep -q "FAIL: Large errors detected" "$output_file" 2>/dev/null; then
312+
# Any FAIL: line from the test indicates derivative or test failure -> outside tolerance
313+
if grep -q "FAIL:" "$output_file" 2>/dev/null; then
313314
has_outside_tolerance=true
314-
elif grep -q "PASS: Derivatives are accurate to machine precision" "$output_file" 2>/dev/null; then
315+
fi
316+
# Only check PASS/WARNING if no FAIL was found
317+
if [ "$has_outside_tolerance" = false ]; then
318+
if grep -q "PASS: Derivatives are accurate to machine precision" "$output_file" 2>/dev/null; then
315319
has_machine_precision=true
316320
elif grep -q "PASS: Vector derivatives are accurate to machine precision" "$output_file" 2>/dev/null; then
317321
has_machine_precision=true
@@ -328,6 +332,7 @@ run_single_test() {
328332
elif grep -q "WARNING: Vector derivatives may have significant errors" "$output_file" 2>/dev/null; then
329333
has_outside_tolerance=true
330334
fi
335+
fi
331336

332337
# Determine test result category and update counters
333338
if [ $exit_code -eq 0 ] && [ "$has_execution_failures" = false ]; then

BLAS/test/test_caxpy.f90

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ subroutine run_test_for_size(n, passed)
4747
integer :: incy
4848

4949
! Derivative variables
50+
complex(4), dimension(n) :: cy_d
5051
complex(4) :: ca_d
5152
complex(4), dimension(n) :: cx_d
52-
complex(4), dimension(n) :: cy_d
5353

5454
! Array restoration and derivative storage
55+
complex(4), dimension(n) :: cy_orig, cy_d_orig
5556
complex(4) :: ca_orig, ca_d_orig
5657
complex(4), dimension(n) :: cx_orig, cx_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

@@ -77,27 +77,27 @@ subroutine run_test_for_size(n, passed)
7777
end do
7878

7979
! Initialize input derivatives
80-
call random_number(temp_re)
81-
call random_number(temp_im)
82-
ca_d = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8380
do i = 1, n
8481
call random_number(temp_re)
8582
call random_number(temp_im)
86-
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
83+
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
8784
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)
8888
do i = 1, n
8989
call random_number(temp_re)
9090
call random_number(temp_im)
91-
cy_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
91+
cx_d(i) = cmplx(temp_re * 2.0 - 1.0, temp_im * 2.0 - 1.0, kind=4)
9292
end do
9393

9494
! Store _orig and _d_orig
95+
cy_d_orig = cy_d
9596
ca_d_orig = ca_d
9697
cx_d_orig = cx_d
97-
cy_d_orig = cy_d
98+
cy_orig = cy
9899
ca_orig = ca
99100
cx_orig = cx
100-
cy_orig = cy
101101

102102
write(*,*) 'Testing CAXPY (n =', n, ')'
103103
cy_orig = cy
@@ -108,17 +108,17 @@ subroutine run_test_for_size(n, passed)
108108
write(*,*) 'Function calls completed successfully'
109109

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

113113
end subroutine run_test_for_size
114114

115-
subroutine check_derivatives_numerically(n, nsize, ca_orig, cx_orig, cy_orig, ca_d_orig, cx_d_orig, cy_d_orig, cy_d, passed)
115+
subroutine check_derivatives_numerically(n, nsize, cy_orig, ca_orig, cx_orig, cy_d_orig, ca_d_orig, cx_d_orig, cy_d, passed)
116116
implicit none
117117
integer, intent(in) :: n
118118
integer, intent(in) :: nsize
119+
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
119120
complex(4), intent(in) :: ca_orig, ca_d_orig
120121
complex(4), intent(in) :: cx_orig(n), cx_d_orig(n)
121-
complex(4), intent(in) :: cy_orig(n), cy_d_orig(n)
122122
complex(4), intent(in) :: cy_d(n)
123123
logical, intent(out) :: passed
124124

@@ -129,9 +129,9 @@ subroutine check_derivatives_numerically(n, nsize, ca_orig, cx_orig, cy_orig, ca
129129
logical :: has_large_errors
130130
complex(4), dimension(n) :: cy_forward, cy_backward
131131
integer :: i, j
132+
complex(4), dimension(n) :: cy
132133
complex(4) :: ca
133134
complex(4), dimension(n) :: cx
134-
complex(4), dimension(n) :: cy
135135

136136
max_error = 0.0e0
137137
has_large_errors = .false.
@@ -140,16 +140,16 @@ subroutine check_derivatives_numerically(n, nsize, ca_orig, cx_orig, cy_orig, ca
140140
write(*,*) 'Step size h =', h
141141

142142
! Forward perturbation: f(x + h)
143+
cy = cy_orig + h * cy_d_orig
143144
ca = ca_orig + h * ca_d_orig
144145
cx = cx_orig + h * cx_d_orig
145-
cy = cy_orig + h * cy_d_orig
146146
call caxpy(nsize, ca, cx, 1, cy, 1)
147147
cy_forward = cy
148148

149149
! Backward perturbation: f(x - h)
150+
cy = cy_orig - h * cy_d_orig
150151
ca = ca_orig - h * ca_d_orig
151152
cx = cx_orig - h * cx_d_orig
152-
cy = cy_orig - h * cy_d_orig
153153
call caxpy(nsize, ca, cx, 1, cy, 1)
154154
cy_backward = cy
155155

0 commit comments

Comments
 (0)