Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with variable ValueType and IndexType #32

Closed
gflegar opened this issue Apr 4, 2018 · 0 comments · Fixed by #448
Closed

Tests with variable ValueType and IndexType #32

gflegar opened this issue Apr 4, 2018 · 0 comments · Fixed by #448
Assignees
Labels
is:enhancement An improvement of an existing feature. is:new-feature A request or implementation of a feature that does not exist yet.

Comments

@gflegar
Copy link
Member

gflegar commented Apr 4, 2018

Currently we only test the default configuration of ValueType = double, IndexType = int32.
We should modify our tests to use Type-parameterized tests to check for other combinations.

@gflegar gflegar added is:enhancement An improvement of an existing feature. is:new-feature A request or implementation of a feature that does not exist yet. labels Apr 4, 2018
@gflegar gflegar changed the title Testing with different ValueType and IndexType Tests with variable ValueType and IndexType Apr 4, 2018
@tcojean tcojean self-assigned this Jan 16, 2020
tcojean added a commit that referenced this issue Mar 4, 2020
This adds multiprecision tests for the core and reference modules. In addition to this, all non matrix, solver and preconditioners in the OpenMP module also have multiprecision tests.
### Summary of changes
+ All core tests rewrote for multiple precisions
+ All reference tests rewrote for multiple precisions
+ Extra OpenMP tests rewrote for multiple precisions (non matrix, solver or preconditioner).
+ codecov is put back into Ginkgo, and our coverage significantly improved thanks to the templated tests
+ In `core/test/utils.hpp`, a bunch of declarations were provided for default values we want to tests, and other tools used when doing multiprecision tests.
+ In `core/test/utils/assertions.hpp`, `get_relative_error` and other commonly used functions from the assertions were extended for the complex value case (using `gko::remove_complex` most of the time). A new assertion was added for comparing values of complex type (`GKO_ASSERT_NEAR`, which extends the basic gtest one `ASSERT_NEAR`).
+ Papi required some fixes (counting the instances of Papi loggers globally instead of per template valuetype).
+ `Ilu` required some fixes (using `gko::remove_complex` and removing default valuetype use of `<>`).

### How to write templated tests
`core/tests/utils.hpp` always needs to be included because it provides required definitions.
In general, if only one kind of precision (e.g. `value_type`) is required, then normal templating can be used, otherwise, due to the use of the macro for declaring the templated values to try, a tuple which contains all the elements need to be defined, see the `reference/test/matrix/csr_kernels.cpp` for example.
```cpp
template <typename ValueIndexType>
class Csr : public ::testing::Test {
protected:
    using value_type =
        typename std::tuple_element<0, decltype(ValueIndexType())>::type;
    using index_type =
        typename std::tuple_element<1, decltype(ValueIndexType())>::type;
};
```

Afterwards, the class needs to be instantiated for all precisions, which is done such as in the following way:
```cpp
TYPED_TEST_CASE(Csr, gko::test::ValueIndexTypes);
```
Note that `ValueIndexTypes` is provided by `utils.hpp` and contains tuples of all valuetype and index type combinations.

As a requirement, the tests now need to use the macro `TYPED_TEST` instead of `TEST_F`. This has multiple implications:
+ All member objects/functions have to be accessed with `this->`.
+ All member definitions such as `using` need to be accessed through `TestFixture::Mtx` for example. The approach I used is to add to every test the required `using` shortcut to make the tests look nicer.
+ A variable `TypeParam` is provided which is the template type of the test.
+ Due to complexes being able to be built with `{real, img}` notation, our initializations of the form `{{1.0, 2.0}, {3.0, 4.0}}` are ambiguous (the second `{`). I provided a shortcut `I<type>` for stating that this is actually an initializer list of type T, and not a complex construction. So the following example would be replaced with:  
```cpp
using T = typename TestFixture::value_type;
auto mtx = gko::initialize({I<T>{1.0, 2.0}, I<T>{3.0, 4.0}}, this->exec);
```

Finally, I implemented a shortcut `r<value_type>::value` for providing depending on the type of the value a proper precision (`1e-7` for `float` and `std::complex<float>`, and `1e-14` for `double` variants).


### Closes: #32
### Related PR: #448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:enhancement An improvement of an existing feature. is:new-feature A request or implementation of a feature that does not exist yet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants