NumCpp
2.3.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
pnr.hpp
Go to the documentation of this file.
1
#pragma once
29
30
#include "
NumCpp/Core/Types.hpp
"
31
#include "
NumCpp/NdArray.hpp
"
32
#include "
NumCpp/Special/factorial.hpp
"
33
34
#include "boost/math/special_functions/factorials.hpp"
35
36
namespace
nc
37
{
38
namespace
special
39
{
40
//============================================================================
41
// Method Description:
49
inline
double
pnr
(
uint32
n,
uint32
r)
50
{
51
if
(r > n)
52
{
53
return
0.0;
54
}
55
if
(r == n)
56
{
57
return
factorial
(n);
58
}
59
60
double
combinations = 1.0;
61
62
if
(n <= boost::math::max_factorial<double>::value)
63
{
64
const
double
nFactorial =
factorial
(n);
65
const
double
nMinusRFactoral =
factorial
(n - r);
66
67
combinations = nFactorial / nMinusRFactoral;
68
}
69
else
70
{
71
const
uint32
lower = n - r + 1;
72
73
combinations =
static_cast<
double
>
(lower);
74
for
(
uint32
i = lower + 1; i < n; ++i)
75
{
76
combinations *=
static_cast<
double
>
(i);
77
}
78
}
79
80
return
combinations;
81
}
82
}
// namespace special
83
}
// namespace nc
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:40
NdArray.hpp
nc
Definition:
Coordinate.hpp:44
factorial.hpp
nc::special::factorial
double factorial(uint32 inValue)
Definition:
factorial.hpp:51
Types.hpp
nc::special::pnr
double pnr(uint32 n, uint32 r)
Definition:
pnr.hpp:49
include
NumCpp
Special
pnr.hpp
Generated by
1.8.17