Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions code/header_units/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void compute(int len, T initial, T step) {
std::adjacent_difference(v.begin(), v.end(), diffs.begin());

// compute standard deviation of it
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T sum = std::reduce(diffs.begin()+1, diffs.end());
const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down
6 changes: 3 additions & 3 deletions code/header_units/solution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void compute(int len, T initial, T step) {
std::adjacent_difference(v.begin(), v.end(), diffs.begin());

// compute standard deviation of it
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T sum = std::reduce(diffs.begin()+1, diffs.end());
const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down
6 changes: 3 additions & 3 deletions code/modules/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void compute(int len, T initial, T step) {
std::adjacent_difference(v.begin(), v.end(), diffs.begin());

// compute standard deviation of it
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T sum = std::reduce(diffs.begin()+1, diffs.end());
const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down
6 changes: 3 additions & 3 deletions code/modules/solution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ void compute(int len, T initial, T step) {
std::adjacent_difference(v.begin(), v.end(), diffs.begin());

// compute standard deviation of it
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T sum = std::reduce(diffs.begin()+1, diffs.end());
const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(),
[](const T& s, const T& a) { return s + a * a; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down
2 changes: 1 addition & 1 deletion code/smartPointers/smartPointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ double sumEntries(std::span<double const> range) {
// Simulate an error
throw std::invalid_argument("Error when summing over data.");

return std::reduce(range.begin(), range.end(), 0.);
return std::reduce(range.begin(), range.end());
}

// Often, data are owned by one entity, and merely used by others. In this case, we hand the data to
Expand Down
2 changes: 1 addition & 1 deletion code/smartPointers/solution/smartPointers.sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ double sumEntries(std::span<double const> range) {
// Simulate an error
throw std::invalid_argument("Error when summing over data.");

return std::reduce(range.begin(), range.end(), 0.);
return std::reduce(range.begin(), range.end());
}

// Often, data are owned by one entity, and merely used by others. In this case, we hand the data to
Expand Down
2 changes: 1 addition & 1 deletion code/stl/randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void compute(int len, T initial, T step) {

// compute standard deviation of all differences
const T sum = std::reduce(...);
const T sumsq = std::reduce(..., [](...) { ...; });
const T sumsq = std::accumulate(..., [](...) { ...; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down
8 changes: 4 additions & 4 deletions code/stl/solution/randomize.sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void compute(int len, T initial, T step) {

// compute standard deviation of all differences.
// Note that the first element is just the original element itself, so we need to skip it.
const T sum = std::reduce(diffs.begin()+1, diffs.end(), T());
const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
const T sum = std::reduce(diffs.begin()+1, diffs.end());
const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
// Alternatively:
// const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(),
// [](const T& s, const T& a) { return s + a * a; });
// const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(),
// [](const T& s, const T& a) { return s + a * a; });
const T mean = sum/len;
const T variance = sumsq/len - mean*mean;

Expand Down