casacore
Loading...
Searching...
No Matches
Combinatorics.h
Go to the documentation of this file.
1//# Smooth.h: smooth vectors and arrays
2//# Copyright (C) 2010 by ESO (in the framework of the ALMA collaboration)
3//# Copyright (C) 1996,1997,1998,1999,2000,2001
4//# Associated Universities, Inc. Washington DC, USA.
5//#
6//# This library is free software; you can redistribute it and/or modify it
7//# under the terms of the GNU Library General Public License as published by
8//# the Free Software Foundation; either version 2 of the License, or (at your
9//# option) any later version.
10//#
11//# This library is distributed in the hope that it will be useful, but WITHOUT
12//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14//# License for more details.
15//#
16//# You should have received a copy of the GNU Library General Public License
17//# along with this library; if not, write to the Free Software Foundation,
18//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19//#
20//# Correspondence concerning AIPS++ should be addressed as follows:
21//# Internet email: casa-feedback@nrao.edu.
22//# Postal address: AIPS++ Project Office
23//# National Radio Astronomy Observatory
24//# 520 Edgemont Road
25//# Charlottesville, VA 22903-2475 USA
26
27#ifndef SCIMATH_COMBINATORICS_H
28#define SCIMATH_COMBINATORICS_H
29
30
31//# Includes
32#include <casacore/casa/aips.h>
33#include <casacore/casa/Arrays/Vector.h>
34
35#include <mutex>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary>
40// Combinatorics related functions.
41// </summary>
42
43// <use visibility=export>
44
45//# <author>Dave Mehringer</author>
46// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
47// </reviewed>
48
49// <prerequisite>
50// <li> <linkto class="Vector">Vector</linkto>
51// <li> <linkto class="Array">Array</linkto>
52// </prerequisite>
53
54// <etymology>
55// self-explanatory
56// </etymology>
57
58// <synopsis>
59// Various factorial and combinatorical functions.
60// </synopsis>
61
62// <motivation>
63// Binomial coefficients needed for Images/ImageProfileFitter
64// </motivation>
65
67
68 public:
69
70 // Get n!
71 static uInt factorial(const uInt n)
72 {
73 fillCache(n);
74 return _factorialCache[n];
75 }
76
77 // "n choose k" = n!/(k!(n-k)!)
78 // Exception is thrown if k > n.
79 static uInt choose(const uInt n, const uInt k);
80
81 private:
82 static void fillCache(const uInt n);
83
85 static volatile uInt _factorialCacheSize; //# volatile for double checked lock
86 static std::mutex theirMutex;
87};
88} //# NAMESPACE CASACORE - END
89
90#endif
91
static uInt factorial(const uInt n)
Get n!
static uInt choose(const uInt n, const uInt k)
"n choose k" = n!/(k!(n-k)!) Exception is thrown if k > n.
static Vector< uInt > _factorialCache
static void fillCache(const uInt n)
static volatile uInt _factorialCacheSize
static std::mutex theirMutex
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49