Xmipp  v3.23.11-Nereus
Classes | Functions
Poly.h File Reference
#include "MultInd.h"
#include "Vector.h"
#include "Matrix.h"
#include <fstream>
Include dependency graph for Poly.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Polynomial
 
struct  Polynomial::PolynomialDataTag
 

Functions

unsigned long choose (unsigned n, unsigned k)
 
Polynomial operator* (const double &dou, Polynomial &p)
 

Function Documentation

◆ choose()

unsigned long choose ( unsigned  n,
unsigned  k 
)

Definition at line 38 of file tools.cpp.

39 {
40  const unsigned long uupSize = 100;
41  static unsigned long uup[uupSize];
42  unsigned long *up;
43  static unsigned long Nold = 0;
44  static unsigned long Kold = 0;
45  unsigned long l,m;
46  unsigned i,j;
47 
48  if ( (n < k) || !n ) return 0;
49 
50  if ( (n == k) || !k ) // includes n == 1
51  return 1;
52 
53  if ( k > (n >> 1) ) // Only lower half
54  k = n-k;
55 
56  if ( (Nold == n) && (k < Kold) ) // We did it last time ...
57  return *(uup + k - 1);
58 
59  if ( k > uupSize )
60  {
61  printf( "choose( unsigned, unsigned) : overflow\n");
62  getchar(); exit(-1);
63  }
64 
65  Nold=n; Kold=k;
66 
67  *(up=uup)=2;
68  for (i=2; i<n; i++) // Pascal's triangle
69  {
70  // todo: remove next line:
71  *(up+1)=1;
72  l=1;
73  m=*(up=uup);
74  for (j=0; j<mmin(i,k); j++)
75  {
76  *up=m+l;
77  l=m;
78  m=*(++up);
79  }
80  // todo: remove next line:
81  *up=1;
82  }
83 
84  return *(uup + k - 1);
85 }
double mmin(const double t1, const double t2)
Definition: tools.h:69
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define j
int m
int * n

◆ operator*()

Polynomial operator* ( const double &  dou,
Polynomial p 
)
inline

Definition at line 132 of file Poly.h.

133 {
134  // we can use operator * defined on Polynomial because of commutativity
135  return p * dou;
136 }