Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract partial sum into an independent algorithm.
- Loading branch information
1 parent
7ef54e3
commit 2d56241
Showing
6 changed files
with
42 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,33 @@ | ||
/*! | ||
* Copyright 2022, XGBoost contributors. | ||
*/ | ||
#include <gtest/gtest.h> | ||
|
||
#include <numeric> | ||
|
||
#include "../../../src/common/numeric.h" | ||
|
||
namespace xgboost { | ||
namespace common { | ||
TEST(Numeric, PartialSum) { | ||
{ | ||
std::vector<size_t> values{1, 2, 3, 4}; | ||
std::vector<size_t> result(values.size() + 1); | ||
Context ctx; | ||
PartialSum(ctx.Threads(), values.begin(), values.end(), static_cast<size_t>(0), result.begin()); | ||
std::vector<size_t> sol(values.size() + 1, 0); | ||
std::partial_sum(values.begin(), values.end(), sol.begin() + 1); | ||
ASSERT_EQ(sol, result); | ||
} | ||
{ | ||
std::vector<double> values{1.5, 2.5, 3.5, 4.5}; | ||
std::vector<double> result(values.size() + 1); | ||
Context ctx; | ||
PartialSum(ctx.Threads(), values.begin(), values.end(), 0.0, result.begin()); | ||
std::vector<double> sol(values.size() + 1, 0.0); | ||
std::partial_sum(values.begin(), values.end(), sol.begin() + 1); | ||
ASSERT_EQ(sol, result); | ||
} | ||
} | ||
} // namespace common | ||
} // namespace xgboost |
This file contains 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