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