Skip to content

Commit 26e2bc3

Browse files
committed
more fixes
1 parent c8d4eaf commit 26e2bc3

4 files changed

Lines changed: 37 additions & 24 deletions

File tree

.clang-tidy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ Checks: >
99
readability-*,
1010
-google-build-using-namespace,
1111
-cppcoreguidelines-avoid-magic-numbers,
12-
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
13-
-cppcoreguidelines-narrowing-conversions,
1412
-cppcoreguidelines-avoid-non-const-global-variables,
13+
-cppcoreguidelines-narrowing-conversions,
14+
-cppcoreguidelines-non-private-member-variables-in-classes,
15+
-cppcoreguidelines-prefer-member-initializer,
16+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
17+
-cppcoreguidelines-pro-type-const-cast,
18+
-cppcoreguidelines-pro-type-reinterpret-cast,
19+
-cppcoreguidelines-pro-type-member-init,
20+
-cppcoreguidelines-special-member-functions,
1521
-google-readability-braces-around-statements,
1622
-google-readability-namespace-comments,
1723
-google-runtime-references,

include/layers/Layer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class LayerImpl {
7878
LayerImpl() = default;
7979
LayerImpl(const Shape& inputShape, const Shape& outputShape)
8080
: inputShape_(inputShape), outputShape_(outputShape) {}
81+
virtual ~LayerImpl() = default;
8182
LayerImpl(const LayerImpl& c) = default;
8283
LayerImpl& operator=(const LayerImpl& c) = default;
8384
[[nodiscard]] virtual std::vector<ValueType> run(

include/layers/PoolingLayer.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ PoolingLayerImpl<ValueType>::PoolingLayerImpl(
179179

180180
size_t effective_kernel_size = (kernel_size - 1) * dilation + 1;
181181

182-
size_t output_size;
183-
if (ceil_mode) {
184-
output_size = static_cast<size_t>(
185-
std::ceil((input_size + pad - effective_kernel_size) /
186-
static_cast<float>(stride))) +
187-
1;
188-
} else {
189-
output_size = static_cast<size_t>(
190-
std::floor((input_size + pad - effective_kernel_size) /
191-
static_cast<float>(stride))) +
192-
1;
193-
}
182+
size_t output_size = [=]() {
183+
if (ceil_mode) {
184+
return static_cast<size_t>(
185+
std::ceil((input_size + pad - effective_kernel_size) /
186+
static_cast<float>(stride))) +
187+
1;
188+
}
189+
return static_cast<size_t>(
190+
std::floor((input_size + pad - effective_kernel_size) /
191+
static_cast<float>(stride))) +
192+
1;
193+
}();
194194

195195
this->outputShape_[input_shape.dims() - pooling_shape.dims() + i] =
196196
output_size;
@@ -321,4 +321,4 @@ std::vector<ValueType> PoolingLayerImpl<ValueType>::run(
321321
return res;
322322
}
323323

324-
} // namespace it_lab_ai
324+
} // namespace it_lab_ai

include/perf/benchmarking.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cmath>
88
#include <numeric>
99
#include <stdexcept>
10+
#include <utility>
1011
#include <vector>
1112

1213
namespace it_lab_ai {
@@ -16,7 +17,7 @@ template <typename DurationContainerType, typename DurationType, class Function,
1617
DurationContainerType elapsed_time(Function&& func, Args&&... args) {
1718
auto duration = std::chrono::duration<DurationContainerType, DurationType>();
1819
auto start = std::chrono::high_resolution_clock::now();
19-
func(args...);
20+
std::forward<Function>(func)(std::forward<Args>(args)...);
2021
auto end = std::chrono::high_resolution_clock::now();
2122
duration = end - start;
2223
return duration.count();
@@ -26,7 +27,7 @@ DurationContainerType elapsed_time(Function&& func, Args&&... args) {
2627
template <class Function, typename... Args>
2728
double elapsed_time_omp(Function&& func, Args&&... args) {
2829
double start = omp_get_wtime();
29-
func(args...);
30+
std::forward<Function>(func)(std::forward<Args>(args)...);
3031
double end = omp_get_wtime();
3132
return end - start;
3233
}
@@ -38,7 +39,7 @@ DurationContainerType elapsed_time_avg(const size_t iters, Function&& func,
3839
auto duration = std::chrono::duration<DurationContainerType, DurationType>();
3940
auto start = std::chrono::high_resolution_clock::now();
4041
for (size_t i = 0; i < iters; i++) {
41-
func(args...);
42+
std::forward<Function>(func)(std::forward<Args>(args)...);
4243
}
4344
auto end = std::chrono::high_resolution_clock::now();
4445
duration = (end - start) / iters;
@@ -51,7 +52,7 @@ double elapsed_time_omp_avg(const size_t iters, Function&& func,
5152
Args&&... args) {
5253
double start = omp_get_wtime();
5354
for (size_t i = 0; i < iters; i++) {
54-
func(args...);
55+
std::forward<Function>(func)(std::forward<Args>(args)...);
5556
}
5657
double end = omp_get_wtime();
5758
return (end - start) / iters;
@@ -61,26 +62,31 @@ template <typename ThroughputContainerType, typename DurationType,
6162
class Function, typename... Args>
6263
ThroughputContainerType throughput(Function&& func, Args&&... args) {
6364
return ThroughputContainerType(1) /
64-
elapsed_time<ThroughputContainerType, DurationType>(func, args...);
65+
elapsed_time<ThroughputContainerType, DurationType>(
66+
std::forward<Function>(func), std::forward<Args>(args)...);
6567
}
6668

6769
template <class Function, typename... Args>
6870
double throughput_omp(Function&& func, Args&&... args) {
69-
return 1 / elapsed_time_omp(func, args...);
71+
return 1 /
72+
elapsed_time_omp(std::forward<Function>(func),
73+
std::forward<Args>(args)...);
7074
}
7175

7276
template <typename ThroughputContainerType, typename DurationType,
7377
class Function, typename... Args>
7478
ThroughputContainerType throughput_avg(const size_t iters, Function&& func,
7579
Args&&... args) {
7680
return ThroughputContainerType(1) /
77-
elapsed_time_avg<ThroughputContainerType, DurationType>(iters, func,
78-
args...);
81+
elapsed_time_avg<ThroughputContainerType, DurationType>(
82+
iters, std::forward<Function>(func), std::forward<Args>(args)...);
7983
}
8084

8185
template <class Function, typename... Args>
8286
double throughput_omp_avg(const size_t iters, Function&& func, Args&&... args) {
83-
return 1 / elapsed_time_omp_avg(iters, func, args...);
87+
return 1 /
88+
elapsed_time_omp_avg(iters, std::forward<Function>(func),
89+
std::forward<Args>(args)...);
8490
}
8591

8692
// as "Manhattan" norm of error-vector

0 commit comments

Comments
 (0)