@@ -6,13 +6,13 @@ use libm::support::{Float, MinInt};
6
6
use crate :: domain:: get_domain;
7
7
use crate :: op:: OpITy ;
8
8
use crate :: run_cfg:: { int_range, iteration_count} ;
9
- use crate :: { CheckCtx , MathOp , linear_ints, logspace} ;
9
+ use crate :: { CheckCtx , GeneratorKind , MathOp , linear_ints, logspace} ;
10
10
11
11
/// Generate a sequence of inputs that eiher cover the domain in completeness (for smaller float
12
12
/// types and single argument functions) or provide evenly spaced inputs across the domain with
13
13
/// approximately `u32::MAX` total iterations.
14
14
pub trait SpacedInput < Op > {
15
- fn get_cases ( ctx : & CheckCtx ) -> ( impl Iterator < Item = Self > + Send , u64 ) ;
15
+ fn get_cases ( ctx : CheckCtx ) -> ( impl Iterator < Item = Self > + Send , u64 ) ;
16
16
}
17
17
18
18
/// Construct an iterator from `logspace` and also calculate the total number of steps expected
@@ -87,8 +87,8 @@ macro_rules! impl_spaced_input {
87
87
where
88
88
Op : MathOp <RustArgs = Self , FTy = $fty>,
89
89
{
90
- fn get_cases( ctx: & CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
91
- let max_steps0 = iteration_count( ctx, 0 ) ;
90
+ fn get_cases( ctx: CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
91
+ let max_steps0 = iteration_count( & ctx, 0 ) ;
92
92
// `f16` and `f32` can have exhaustive tests.
93
93
match value_count:: <Op :: FTy >( ) {
94
94
Some ( steps0) if steps0 <= max_steps0 => {
@@ -97,7 +97,7 @@ macro_rules! impl_spaced_input {
97
97
( EitherIter :: A ( iter0) , steps0)
98
98
}
99
99
_ => {
100
- let ( iter0, steps0) = logspace_steps:: <Op >( ctx, 0 , max_steps0) ;
100
+ let ( iter0, steps0) = logspace_steps:: <Op >( & ctx, 0 , max_steps0) ;
101
101
let iter0 = iter0. map( |v| ( v, ) ) ;
102
102
( EitherIter :: B ( iter0) , steps0)
103
103
}
@@ -109,9 +109,9 @@ macro_rules! impl_spaced_input {
109
109
where
110
110
Op : MathOp <RustArgs = Self , FTy = $fty>,
111
111
{
112
- fn get_cases( ctx: & CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
113
- let max_steps0 = iteration_count( ctx, 0 ) ;
114
- let max_steps1 = iteration_count( ctx, 1 ) ;
112
+ fn get_cases( ctx: CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
113
+ let max_steps0 = iteration_count( & ctx, 0 ) ;
114
+ let max_steps1 = iteration_count( & ctx, 1 ) ;
115
115
// `f16` can have exhaustive tests.
116
116
match value_count:: <Op :: FTy >( ) {
117
117
Some ( count) if count <= max_steps0 && count <= max_steps1 => {
@@ -120,8 +120,8 @@ macro_rules! impl_spaced_input {
120
120
( EitherIter :: A ( iter) , count. checked_mul( count) . unwrap( ) )
121
121
}
122
122
_ => {
123
- let ( iter0, steps0) = logspace_steps:: <Op >( ctx, 0 , max_steps0) ;
124
- let ( iter1, steps1) = logspace_steps:: <Op >( ctx, 1 , max_steps1) ;
123
+ let ( iter0, steps0) = logspace_steps:: <Op >( & ctx, 0 , max_steps0) ;
124
+ let ( iter1, steps1) = logspace_steps:: <Op >( & ctx, 1 , max_steps1) ;
125
125
let iter = iter0. flat_map( move |first| {
126
126
iter1. clone( ) . map( move |second| ( first, second) )
127
127
} ) ;
@@ -136,10 +136,10 @@ macro_rules! impl_spaced_input {
136
136
where
137
137
Op : MathOp <RustArgs = Self , FTy = $fty>,
138
138
{
139
- fn get_cases( ctx: & CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
140
- let max_steps0 = iteration_count( ctx, 0 ) ;
141
- let max_steps1 = iteration_count( ctx, 1 ) ;
142
- let max_steps2 = iteration_count( ctx, 2 ) ;
139
+ fn get_cases( ctx: CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
140
+ let max_steps0 = iteration_count( & ctx, 0 ) ;
141
+ let max_steps1 = iteration_count( & ctx, 1 ) ;
142
+ let max_steps2 = iteration_count( & ctx, 2 ) ;
143
143
// `f16` can be exhaustive tested if `LIBM_EXTENSIVE_TESTS` is incresed.
144
144
match value_count:: <Op :: FTy >( ) {
145
145
Some ( count)
@@ -153,9 +153,9 @@ macro_rules! impl_spaced_input {
153
153
( EitherIter :: A ( iter) , count. checked_pow( 3 ) . unwrap( ) )
154
154
}
155
155
_ => {
156
- let ( iter0, steps0) = logspace_steps:: <Op >( ctx, 0 , max_steps0) ;
157
- let ( iter1, steps1) = logspace_steps:: <Op >( ctx, 1 , max_steps1) ;
158
- let ( iter2, steps2) = logspace_steps:: <Op >( ctx, 2 , max_steps2) ;
156
+ let ( iter0, steps0) = logspace_steps:: <Op >( & ctx, 0 , max_steps0) ;
157
+ let ( iter1, steps1) = logspace_steps:: <Op >( & ctx, 1 , max_steps1) ;
158
+ let ( iter2, steps2) = logspace_steps:: <Op >( & ctx, 2 , max_steps2) ;
159
159
160
160
let iter = iter0
161
161
. flat_map( move |first| iter1. clone( ) . map( move |second| ( first, second) ) )
@@ -175,10 +175,10 @@ macro_rules! impl_spaced_input {
175
175
where
176
176
Op : MathOp <RustArgs = Self , FTy = $fty>,
177
177
{
178
- fn get_cases( ctx: & CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
179
- let range0 = int_range( ctx, 0 ) ;
180
- let max_steps0 = iteration_count( ctx, 0 ) ;
181
- let max_steps1 = iteration_count( ctx, 1 ) ;
178
+ fn get_cases( ctx: CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
179
+ let range0 = int_range( & ctx, 0 ) ;
180
+ let max_steps0 = iteration_count( & ctx, 0 ) ;
181
+ let max_steps1 = iteration_count( & ctx, 1 ) ;
182
182
match value_count:: <Op :: FTy >( ) {
183
183
Some ( count1) if count1 <= max_steps1 => {
184
184
let ( iter0, steps0) = linear_ints( range0, max_steps0) ;
@@ -188,7 +188,7 @@ macro_rules! impl_spaced_input {
188
188
}
189
189
_ => {
190
190
let ( iter0, steps0) = linear_ints( range0, max_steps0) ;
191
- let ( iter1, steps1) = logspace_steps:: <Op >( ctx, 1 , max_steps1) ;
191
+ let ( iter1, steps1) = logspace_steps:: <Op >( & ctx, 1 , max_steps1) ;
192
192
193
193
let iter = iter0. flat_map( move |first| {
194
194
iter1. clone( ) . map( move |second| ( first, second) )
@@ -205,10 +205,10 @@ macro_rules! impl_spaced_input {
205
205
where
206
206
Op : MathOp <RustArgs = Self , FTy = $fty>,
207
207
{
208
- fn get_cases( ctx: & CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
209
- let max_steps0 = iteration_count( ctx, 0 ) ;
210
- let range1 = int_range( ctx, 1 ) ;
211
- let max_steps1 = iteration_count( ctx, 1 ) ;
208
+ fn get_cases( ctx: CheckCtx ) -> ( impl Iterator <Item = Self >, u64 ) {
209
+ let max_steps0 = iteration_count( & ctx, 0 ) ;
210
+ let range1 = int_range( & ctx, 1 ) ;
211
+ let max_steps1 = iteration_count( & ctx, 1 ) ;
212
212
match value_count:: <Op :: FTy >( ) {
213
213
Some ( count0) if count0 <= max_steps0 => {
214
214
let ( iter1, steps1) = linear_ints( range1, max_steps1) ;
@@ -218,7 +218,7 @@ macro_rules! impl_spaced_input {
218
218
( EitherIter :: A ( iter) , count0. checked_mul( steps1) . unwrap( ) )
219
219
}
220
220
_ => {
221
- let ( iter0, steps0) = logspace_steps:: <Op >( ctx, 0 , max_steps0) ;
221
+ let ( iter0, steps0) = logspace_steps:: <Op >( & ctx, 0 , max_steps0) ;
222
222
let ( iter1, steps1) = linear_ints( range1, max_steps1) ;
223
223
224
224
let iter = iter0. flat_map( move |first| {
@@ -242,12 +242,11 @@ impl_spaced_input!(f64);
242
242
impl_spaced_input ! ( f128) ;
243
243
244
244
/// Create a test case iterator for extensive inputs. Also returns the total test case count.
245
- pub fn get_test_cases < Op > (
246
- ctx : & CheckCtx ,
247
- ) -> ( impl Iterator < Item = Op :: RustArgs > + Send + use < ' _ , Op > , u64 )
245
+ pub fn get_test_cases < Op > ( ctx : CheckCtx ) -> ( impl Iterator < Item = Op :: RustArgs > + Send , u64 )
248
246
where
249
247
Op : MathOp ,
250
248
Op :: RustArgs : SpacedInput < Op > ,
251
249
{
250
+ assert_eq ! ( ctx. gen_kind, GeneratorKind :: Spaced ) ;
252
251
Op :: RustArgs :: get_cases ( ctx)
253
252
}
0 commit comments