SimiLie
Loading...
Searching...
No Matches
binomial_coefficient.hpp
1// SPDX-FileCopyrightText: 2024 Baptiste Legouix
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#pragma once
5
6#include <ddc/ddc.hpp>
7
8namespace sil {
9
10namespace misc {
11
12// From https://stackoverflow.com/a/44719219
13KOKKOS_FUNCTION constexpr inline std::size_t binomial_coefficient(
14 std::size_t n,
15 std::size_t k) noexcept
16{
17 return (k > n) ? 0 : // out of range
18 (k == 0 || k == n) ? 1
19 : // edge
20 (k == 1 || k == n - 1) ? n
21 : // first
22 binomial_coefficient(n - 1, k - 1) * n / k; // recursive
23}
24
25} // namespace misc
26
27} // namespace sil
KOKKOS_FUNCTION constexpr std::size_t binomial_coefficient(std::size_t n, std::size_t k) noexcept
The top-level namespace of SimiLie.
Definition csr.hpp:15