|
20 | 20 |
|
21 | 21 | #ifdef XTENSOR_BENCHMARK_USE_EIGEN |
22 | 22 | #include <Eigen/Core> |
| 23 | +#include <unsupported/Eigen/CXX11/Tensor> |
23 | 24 | #endif |
24 | 25 |
|
25 | 26 | #ifdef XTENSOR_BENCHMARK_USE_ARMADILLO |
@@ -188,6 +189,41 @@ namespace xt::compare |
188 | 189 | benchmark::ClobberMemory(); |
189 | 190 | } |
190 | 191 | } |
| 192 | + |
| 193 | + void broadcast_dynamic_eigen(benchmark::State& state) |
| 194 | + { |
| 195 | + using tensor = Eigen::Tensor<double, 3, Eigen::RowMajor>; |
| 196 | + tensor x(64, 64, 16), out(64, 64, 16); |
| 197 | + Eigen::Tensor<double, 1, Eigen::RowMajor> row(16), column(64); |
| 198 | + for (Eigen::Index i = 0; i < x.size(); ++i) x.data()[i] = 0.5 + double(i % 251) * 0.01; |
| 199 | + for (Eigen::Index i = 0; i < row.size(); ++i) row(i) = double(i) * 0.25; |
| 200 | + for (Eigen::Index i = 0; i < column.size(); ++i) column(i) = double(i) * 0.125; |
| 201 | + const Eigen::array<Eigen::Index, 3> row_shape = {1, 1, 16}; |
| 202 | + const Eigen::array<Eigen::Index, 3> row_broadcast = {64, 64, 1}; |
| 203 | + const Eigen::array<Eigen::Index, 3> column_shape = {64, 1, 1}; |
| 204 | + const Eigen::array<Eigen::Index, 3> column_broadcast = {1, 64, 16}; |
| 205 | + for (auto _ : state) |
| 206 | + { |
| 207 | + out = (x + row.reshape(row_shape).broadcast(row_broadcast)) * 1.5 |
| 208 | + - column.reshape(column_shape).broadcast(column_broadcast); |
| 209 | + benchmark::DoNotOptimize(out.data()); |
| 210 | + benchmark::ClobberMemory(); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + void transpose_cast_eigen(benchmark::State& state) |
| 215 | + { |
| 216 | + Eigen::Tensor<unsigned char, 3, Eigen::RowMajor> input(128, 256, 3); |
| 217 | + Eigen::Tensor<float, 3, Eigen::RowMajor> out(3, 128, 256); |
| 218 | + for (Eigen::Index i = 0; i < input.size(); ++i) input.data()[i] = static_cast<unsigned char>(i % 251); |
| 219 | + const Eigen::array<Eigen::Index, 3> permutation = {2, 0, 1}; |
| 220 | + for (auto _ : state) |
| 221 | + { |
| 222 | + out = input.shuffle(permutation).cast<float>() / 255.0f; |
| 223 | + benchmark::DoNotOptimize(out.data()); |
| 224 | + benchmark::ClobberMemory(); |
| 225 | + } |
| 226 | + } |
191 | 227 | #endif |
192 | 228 |
|
193 | 229 | #ifdef XTENSOR_BENCHMARK_USE_ARMADILLO |
@@ -226,6 +262,8 @@ namespace xt::compare |
226 | 262 | #ifdef XTENSOR_BENCHMARK_USE_EIGEN |
227 | 263 | BENCHMARK(linear_dynamic_eigen); |
228 | 264 | BENCHMARK(linear_fixed_eigen); |
| 265 | + BENCHMARK(broadcast_dynamic_eigen); |
| 266 | + BENCHMARK(transpose_cast_eigen); |
229 | 267 | #endif |
230 | 268 | #ifdef XTENSOR_BENCHMARK_USE_ARMADILLO |
231 | 269 | BENCHMARK(linear_dynamic_armadillo); |
|
0 commit comments