Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
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
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
BasedOnStyle: Google
IndentWidth: 4
Language: Cpp
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
Expand All @@ -8,4 +9,5 @@ AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
PointerAlignment: Left
ColumnLimit: 80
AccessModifierOffset: 0
KeepEmptyLinesAtTheStartOfBlocks: true
89 changes: 45 additions & 44 deletions benchmarks/algebra/include/algebra/array/data_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,74 +22,75 @@ namespace algebra {
template <concepts::vector vector_t>
inline void fill_random_vec(std::vector<vector_t> &collection) {

// Generate a vector of the right type with random values
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<typename vector_t::value_type> dist(0.f, 1.f);
// Generate a vector of the right type with random values
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<typename vector_t::value_type> dist(0.f,
1.f);

auto rand_obj = [&]() { return vector_t{dist(mt), dist(mt), dist(mt)}; };
auto rand_obj = [&]() { return vector_t{dist(mt), dist(mt), dist(mt)}; };

collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
}

/// Fill a @c std::array based transform3 with random values
template <concepts::transform3D transform3_t>
inline void fill_random_trf(std::vector<transform3_t> &collection) {

using vector_t = typename transform3_t::vector3;
using vector_t = typename transform3_t::vector3;

// Generate a random, but valid affine transformation
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<typename transform3_t::scalar_type> dist(0.f,
1.f);
// Generate a random, but valid affine transformation
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<typename transform3_t::scalar_type> dist(
0.f, 1.f);

auto rand_obj = [&]() {
vector_t x_axis;
vector_t z_axis;
vector_t t;
auto rand_obj = [&]() {
vector_t x_axis;
vector_t z_axis;
vector_t t;

x_axis = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
z_axis = {dist(mt), dist(mt), dist(mt)};
t = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
x_axis = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});
z_axis = {dist(mt), dist(mt), dist(mt)};
t = vector::normalize(vector_t{dist(mt), dist(mt), dist(mt)});

// Gram-Schmidt projection
typename transform3_t::scalar_type coeff =
vector::dot(x_axis, z_axis) / vector::norm(x_axis);
z_axis = x_axis - coeff * z_axis;
// Gram-Schmidt projection
typename transform3_t::scalar_type coeff =
vector::dot(x_axis, z_axis) / vector::norm(x_axis);
z_axis = x_axis - coeff * z_axis;

return transform3_t{t, x_axis, vector::normalize(z_axis)};
};
return transform3_t{t, x_axis, vector::normalize(z_axis)};
};

collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
}

/// Fill a @c std::array based matrix with random values
template <concepts::matrix matrix_t>
inline void fill_random_matrix(std::vector<matrix_t> &collection) {

using scalar_t = typename matrix_t::value_type::value_type;
using scalar_t = typename matrix_t::value_type::value_type;

// Generate a random, but valid affine transformation
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<scalar_t> dist(0.f, 1.f);
auto rand_obj = [&]() {
matrix_t m;
// Generate a random, but valid affine transformation
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_real_distribution<scalar_t> dist(0.f, 1.f);
auto rand_obj = [&]() {
matrix_t m;

for (std::size_t j = 0u; j < m.size(); ++j) {
for (std::size_t i = 0u; i < m[0].size(); ++i) {
m[j][i] = dist(mt);
}
}
for (std::size_t j = 0u; j < m.size(); ++j) {
for (std::size_t i = 0u; i < m[0].size(); ++i) {
m[j][i] = dist(mt);
}
}

return m;
};
return m;
};

collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
collection.resize(collection.capacity());
std::ranges::generate(collection, rand_obj);
}

} // namespace algebra
131 changes: 66 additions & 65 deletions benchmarks/algebra/include/algebra/common/benchmark_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,72 @@ namespace algebra {

/// Base type for linear algebra benchmarks with google benchmark
struct benchmark_base {
/// Local configuration type
struct configuration {
/// Size of data sample to be used in benchmark
std::size_t m_samples{100u};
// Sleep after building data sample
bool m_sleep = false;
// Number of seconds to sleep
std::size_t m_n_sleep{1u};

/// Setters
/// @{
configuration& n_samples(std::size_t n) {
m_samples = n;
return *this;
}
configuration& do_sleep(bool b) {
m_sleep = b;
return *this;
}
configuration& n_sleep(std::size_t n) {
m_n_sleep = n;
m_sleep = true;
return *this;
}
/// @}

/// Getters
/// @{
std::size_t n_samples() const { return m_samples; }
constexpr bool do_sleep() const { return m_sleep; }
constexpr std::size_t n_sleep() const { return m_n_sleep; }
/// @}

/// Print configuration
friend std::ostream& operator<<(std::ostream& os,
const benchmark_base::configuration& cfg) {
os << " -> running:\t " << cfg.n_samples() << " samples" << std::endl;
if (cfg.do_sleep()) {
os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl;
}
os << std::endl;
return os;
}
};

/// The benchmark configuration
configuration m_cfg{};

/// Default construction
benchmark_base() = default;

/// Construct from an externally provided configuration @param cfg
explicit benchmark_base(configuration cfg) : m_cfg{cfg} {}

/// @returns the benchmark configuration
configuration& config() { return m_cfg; }

/// Default destructor
virtual ~benchmark_base() = default;

/// @returns the benchmark name
virtual constexpr std::string name() const = 0;

/// Benchmark case
virtual void operator()(::benchmark::State&) const = 0;
/// Local configuration type
struct configuration {
/// Size of data sample to be used in benchmark
std::size_t m_samples{100u};
// Sleep after building data sample
bool m_sleep = false;
// Number of seconds to sleep
std::size_t m_n_sleep{1u};

/// Setters
/// @{
configuration& n_samples(std::size_t n) {
m_samples = n;
return *this;
}
configuration& do_sleep(bool b) {
m_sleep = b;
return *this;
}
configuration& n_sleep(std::size_t n) {
m_n_sleep = n;
m_sleep = true;
return *this;
}
/// @}

/// Getters
/// @{
std::size_t n_samples() const { return m_samples; }
constexpr bool do_sleep() const { return m_sleep; }
constexpr std::size_t n_sleep() const { return m_n_sleep; }
/// @}

/// Print configuration
friend std::ostream& operator<<(
std::ostream& os, const benchmark_base::configuration& cfg) {
os << " -> running:\t " << cfg.n_samples() << " samples"
<< std::endl;
if (cfg.do_sleep()) {
os << " -> cool down:\t " << cfg.n_sleep() << "s" << std::endl;
}
os << std::endl;
return os;
}
};

/// The benchmark configuration
configuration m_cfg{};

/// Default construction
benchmark_base() = default;

/// Construct from an externally provided configuration @param cfg
explicit benchmark_base(configuration cfg) : m_cfg{cfg} {}

/// @returns the benchmark configuration
configuration& config() { return m_cfg; }

/// Default destructor
virtual ~benchmark_base() = default;

/// @returns the benchmark name
virtual constexpr std::string name() const = 0;

/// Benchmark case
virtual void operator()(::benchmark::State&) const = 0;
};

} // namespace algebra
Loading