-
Notifications
You must be signed in to change notification settings - Fork 2
Gtest setUp to simplify tests #259
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
Open
Semyon1104
wants to merge
9
commits into
main
Choose a base branch
from
Semyon1104/TestsSetUp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
521c4fb
add fixture
Semyon1104 3faf111
ew
Semyon1104 cf8cd42
clang:
Semyon1104 6aff99b
parametrized in pooling
Semyon1104 7b319f3
add ew tests
Semyon1104 7e008ad
conflict
Semyon1104 7c4c6e2
add conv tests
Semyon1104 b0c79b3
fix bias_data
Semyon1104 c4d4fa6
clang
Semyon1104 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| #pragma once | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <algorithm> | ||
| #include <random> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "layers/Layer.hpp" | ||
|
|
||
| using namespace it_lab_ai; | ||
|
|
||
| class BaseTestFixture : public ::testing::Test { | ||
| public: | ||
| void SetUp() override { | ||
| defaultOptions.backend = Backend::kNaive; | ||
| defaultOptions.parallel = false; | ||
| defaultOptions.par_backend = ParBackend::kSeq; | ||
| } | ||
|
|
||
| static RuntimeOptions setTBBOptions() { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = true; | ||
| options.par_backend = ParBackend::kTbb; | ||
| return options; | ||
| } | ||
|
|
||
| static RuntimeOptions setSeqOptions() { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = true; | ||
| options.par_backend = ParBackend::kSeq; | ||
| return options; | ||
| } | ||
|
|
||
| static RuntimeOptions setSTLOptions() { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = true; | ||
| options.par_backend = ParBackend::kThreads; | ||
| return options; | ||
| } | ||
|
|
||
| static RuntimeOptions setKokkosOptions() { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = true; | ||
| options.par_backend = ParBackend::kKokkos; | ||
| return options; | ||
| } | ||
|
|
||
| static RuntimeOptions setOmpOptions() { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = true; | ||
| options.par_backend = ParBackend::kOmp; | ||
| return options; | ||
| } | ||
|
|
||
| static RuntimeOptions createOptionsWithBackend(ParBackend backend) { | ||
| RuntimeOptions options; | ||
| options.backend = Backend::kNaive; | ||
| options.parallel = (backend != ParBackend::kSeq); | ||
| options.par_backend = backend; | ||
| return options; | ||
| } | ||
|
|
||
| static std::vector<float> basic1DData() { | ||
| return {9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f}; | ||
| } | ||
|
|
||
| static Shape basic1DShape() { return {8}; } | ||
|
|
||
| static std::vector<float> basic2DData4x4() { | ||
| return {9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, | ||
| 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f}; | ||
| } | ||
|
|
||
| static Shape basic2DShape4x4() { return {4, 4}; } | ||
|
|
||
| static std::vector<float> basic2DData3x3() { | ||
| return {9.0f, 8.0f, 7.0f, 5.0f, 4.0f, 3.0f, 2.0f, 3.0f, 4.0f}; | ||
| } | ||
|
|
||
| static Shape basic2DShape3x3() { return {3, 3}; } | ||
|
|
||
| static std::vector<float> activationTestData() { | ||
| return {-3.0f, -2.0f, -1.0f, 0.0f, 1.0f, 2.0f, 3.0f}; | ||
| } | ||
|
|
||
| static std::vector<float> reluExpected() { | ||
| return {0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 2.0f, 3.0f}; | ||
| } | ||
|
|
||
| static std::vector<float> sigmoidExpected() { | ||
| return {0.0474f, 0.1192f, 0.2689f, 0.5f, 0.7311f, 0.8808f, 0.9526f}; | ||
| } | ||
|
|
||
| static std::vector<float> get1DAverageExpected() { | ||
| return {8.0f, 6.0f, 4.0f}; | ||
| } | ||
|
|
||
| static std::vector<float> get2DAverageStride1Expected() { | ||
| return {6.5f, 5.5f, 4.5f, 3.5f, 3.5f, 3.5f, 4.5f, 5.5f, 6.5f}; | ||
| } | ||
|
|
||
| static std::vector<float> ascending1DData() { | ||
| return {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f}; | ||
| } | ||
|
|
||
| static Shape ascending1DShape() { return {10}; } | ||
|
|
||
| static std::vector<float> descending1DData() { | ||
| return {10.0f, 9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f}; | ||
| } | ||
|
|
||
| static std::vector<float> mixed1DData() { | ||
| return {-5.0f, -3.0f, 0.0f, 2.0f, 4.0f, -1.0f, 3.0f, 1.0f, -2.0f, 5.0f}; | ||
| } | ||
|
|
||
| static std::vector<float> small2DData2x2() { | ||
| return {1.0f, 2.0f, 3.0f, 4.0f}; | ||
| } | ||
|
|
||
| static Shape small2DShape2x2() { return {2, 2}; } | ||
|
|
||
| static std::vector<float> medium2DData5x5() { | ||
| return {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, | ||
| 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, | ||
| 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f, 25.0f}; | ||
| } | ||
|
|
||
| static Shape medium2DShape5x5() { return {5, 5}; } | ||
|
|
||
| static std::vector<float> zero2DData3x3() { | ||
| return {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; | ||
| } | ||
|
|
||
| static Shape zero2DShape3x3() { return {3, 3}; } | ||
|
|
||
| static std::vector<float> constant2DData4x4(float value = 5.0f) { | ||
| return std::vector<float>(16, value); | ||
| } | ||
|
|
||
| static Shape constant2DShape4x4() { return {4, 4}; } | ||
|
|
||
| template <typename T> | ||
| static void expectVectorsNear(const std::vector<T>& actual, | ||
| const std::vector<T>& expected, | ||
| T tolerance = static_cast<T>(1e-5)) { | ||
| ASSERT_EQ(actual.size(), expected.size()); | ||
| for (size_t i = 0; i < actual.size(); ++i) { | ||
| EXPECT_NEAR(actual[i], expected[i], tolerance) << "at index " << i; | ||
| } | ||
| } | ||
|
|
||
| protected: | ||
| RuntimeOptions defaultOptions; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, do not use
using namespace *in headers