Add strategy to vectorize tests during data generation #1613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Main idea: in most cases, vectorization testing can be handled at data generation level. That is, the same test that asserts a particular case can be used to assert any of the possible combinations of (vectorized) inputs. Thus, data generation should handle the creation of all possible combinations.
Assumption: repeating a given input
n_reps
times and compare the repeated output against the non-repeated expected output repeatedn_reps
is a strong way of testing the vectorization correctness of a method.Examples
point = gs.ones(3)
and outputs itself. The possible input combinations are:point = gs.ones(3)
->out = gs.ones(3)
point = gs.ones(1, 3)
->out = gs.ones(3)
(due to the way geomstats handles single points)point = gs.ones(n_reps, 3)
->out = gs.ones(n_reps, 3)
How to set this case with the new strategy?
new_data
will contain all the mentioned combinations.point_a = gs.ones(3)
,point_b = gs.ones(3)
,out = gs.ones(3)
point_a = gs.ones(3)
,point_b = gs.ones(1, 3)
,out = gs.ones(3)
point_a = gs.ones(1, 3)
,point_b = gs.ones(3)
,out = gs.ones(3)
point_a = gs.ones(1, 3)
,point_b = gs.ones(1, 3)
,out = gs.ones(3)
point_a = gs.ones(3)
,point_b = gs.ones(n_reps, 3)
,out = gs.ones(n_reps, 3)
point_a = gs.ones(1, 3)
,point_b = gs.ones(n_reps, 3)
,out = gs.ones(n_reps, 3)
point_a = gs.ones(n_reps, 3)
,point_b = gs.ones(3)
,out = gs.ones(n_reps, 3)
point_a = gs.ones(n_reps, 3)
,point_b = gs.ones(1, 3)
,out = gs.ones(n_reps, 3)
point_a = gs.ones(n_reps, 3)
,point_b = gs.ones(n_reps, 3)
,out = gs.ones(n_reps, 3)
How to set this case with the new strategy?
new_data
will contain all the mentioned combinations.Additional cases
gs.ones(3)
->gs.ones(1, 3)
) can be ignored by settingcheck_expand=False
n_input=2
. Setvec_type='asym_left'
(first input is repeated, but not second) orvec_type='asym_right'
(second input is repeated, but not first)More information
Sometimes some vectorization tests can be set without an expected output (e.g. for output shape testing, the shape of the input is enough to infer the shape of the output). For this case, just keep
expected_name=None
.