34{1.0, 1.0, 2.0, 6.0, 24.0, 120.0, 720.0, 5040.0, 40320.0, 362880.0, 3628800.0, 39916800.0, 479001600.0, 6.2270208e9, 8.71782891e10, 1.307674368000000e12, 2.092278988800000e13, 3.556874280960000e14, 6.402373705728000e15, 1.216451004088320e17, 2.432902008176640e18};
37static void combinationUtil(
int* arr,
int* data,
int start,
int end,
int index,
int r,
int** comb,
int* nComb) {
40 (*comb) =
realloc1d( (*comb), (*nComb)*r*
sizeof(
int));
41 for (
int j=0; j<r; j++)
42 (*comb)[((*nComb)-1)*r+j] = data[j];
45 for (
int i=
start; i<=end && end-i+1 >= r-index; i++) {
58 for(i=0; i<nDirs; i++){
59 if(dirs_deg[i*2]>180.0f)
60 dirs_deg[i*2] = -360.0f + dirs_deg[i*2];
71 if (numsamp > INT_MAX)
76 if (npts_max >= numsamp)
91 for(l=0; l<len_x; l++){
93 weights[k*len_x+l] = 1.0f;
97 weights[i*len_x+l] *= ((x[l]-(float)k) / (float)(i-k));
112 int i, band, counter, next_erb_idx;
113 float band_centreFreq, erb, erb_centre, tmp;
115 saf_assert(centerFreq[nBands-1]>maxFreqLim,
"maxFreqLim must be set to be lower than Nyquist...");
117 band_centreFreq = (powf(2.0f, 1.0f/3.0f)+1.0f)/2.0f;
121 (*erb_freqs) =
malloc1d(
sizeof(
float));
123 (*erb_freqs)[0] = centerFreq[0];
126 while((*erb_freqs)[counter]<maxFreqLim){
127 erb = 24.7f + 0.108f * (*erb_freqs)[counter] * band_centreFreq;
128 (*erb_idx) =
realloc1d((*erb_idx), (counter+2)*
sizeof(
int));
129 (*erb_freqs) =
realloc1d((*erb_freqs), (counter+2)*
sizeof(
float));
130 (*erb_freqs)[counter+1] = (*erb_freqs)[counter] + erb;
131 erb_centre = FLT_MAX;
133 for(band=0; band<nBands; band++){
134 tmp =fabsf((*erb_freqs)[counter+1] - centerFreq[band]);
140 (*erb_idx)[counter+1] = next_erb_idx + 1;
141 if((*erb_idx)[counter+1] == (*erb_idx)[counter])
142 (*erb_idx)[counter+1] = (*erb_idx)[counter+1]+1;
143 (*erb_freqs)[counter+1] = centerFreq[(*erb_idx)[counter+1]-1];
147 (*erb_idx) =
realloc1d((*erb_idx), (counter + 2) *
sizeof(
int));
148 (*erb_freqs) =
realloc1d((*erb_freqs), (counter + 2) *
sizeof(
float));
149 (*erb_idx)[counter+1] = nBands;
150 (*erb_freqs)[counter+1] = centerFreq[nBands-1];
151 (*nERBBands) = counter+2;
154 for(i=0; i<(*nERBBands); i++)
155 (*erb_idx)[i] = (*erb_idx)[i] - 1;
166 for (i = 0; i < len; i++)
168 for (i = 0; i < len; i++) {
169 j = rand() % (len-i) + i;
184 for(i = 1; i<=n; i++)
185 ff *= (
long double)i;
191 float tmp = fmodf(x, y);
192 return tmp >= 0 ? tmp : tmp + y;
204 int m, n, negFLAG, arg, len, lim;
206 len = (int)(la + lb) - 1;
207 memset(x_ab, 0, len*
sizeof(
float));
208 for(m=1; m<=len; m++){
218 for(n=1; n<=lim; n++){
220 x_ab[m-1] += (a[arg+n-1] * b[n-1]);
222 x_ab[m-1] += (a[n-1] * b[n-arg-1]);
234 for(i=0; i<length; i++)
235 vector[i] = (2.0f*rand()/(
float)RAND_MAX)-1.0f;
240 float_complex* vector,
245 for(i=0; i<length; i++)
246 vector[i] = cmplxf((2.0f*rand()/(
float)RAND_MAX)-1.0f, (2.0f*rand()/(
float)RAND_MAX)-1.0f);
256 for(i=0; i<length; i++)
257 vector[i] = rand()/(float)RAND_MAX;
269 int i, j, h_start, x_start, x_end, len_y;
271 len_y = len_h+len_x-1;
272 memset(y, 0, len_y*
sizeof(
double));
273 for (i=0; i<len_y; i++) {
274 x_start =
SAF_MAX(0,i-len_h+1);
277 for(j=x_start; j<x_end; j++)
278 y[i] += h[h_start--]*x[j];
291 int i, j, h_start, x_start, x_end, len_y;
293 len_y = len_h+len_x-1;
294 memset(y, 0, len_y*
sizeof(double_complex));
295 for (i=0; i<len_y; i++) {
296 x_start =
SAF_MAX(0,i-len_h+1);
299 for(j=x_start; j<x_end; j++)
300 y[i] = ccadd(y[i], ccmul(h[h_start--], x[j]));
313 memset(poly, 0, (len_x+1)*
sizeof(
double));
315 for (j=0; j<len_x; j++){
316 for(i=j+1; i>0; i--){
317 poly[i] = poly[i] - x[j] * (poly[i-1]);
325 double_complex* poly,
331 memset(poly, 0, (len_x+1)*
sizeof(double_complex));
332 poly[0] = cmplx(1.0, 0.0);
333 for (j=0; j<len_x; j++){
334 for(i=j+1; i>0; i--){
335 poly[i] = ccsub(poly[i], ccmul(x[j], poly[i-1]));
343 double_complex* poly,
348 double_complex* Xcmplx, *e;
351 Xcmplx =
malloc1d(size_x*size_x*
sizeof(double_complex));
352 e =
malloc1d(size_x*
sizeof(double_complex));
353 for(i=0; i<size_x*size_x; i++)
354 Xcmplx[i] = cmplx(X[i], 0.0);
355 utility_zeig(NULL, Xcmplx, size_x, NULL, NULL, NULL, e);
358 memset(poly, 0, (size_x+1)*
sizeof(double_complex));
359 poly[0] = cmplx(1.0, 0.0);
360 for (j=0; j<size_x; j++){
361 for(i=j+1; i>0; i--){
362 poly[i] = ccsub(poly[i], ccmul(e[j], poly[i-1]));
378#if defined(SAF_USE_INTEL_IPP)
379 ippsSum_32f((Ipp32f*)values, nValues, &sum, ippAlgHintNone);
383 for(i=0; i<nValues; i++)
397 for(i=0; i<nValues; i++)
398 if(values[i]<threshold)
412 int i, j, k, nDups, foundDups, foundNewDup;
413 int* dups, *nDuplicates_perInput;
418 if(uniqueVals!=NULL){
419 (*uniqueVals) =
malloc1d((*nUnique)*
sizeof(
int));
420 (*uniqueVals)[0] = input[0];
422 if(uniqueInds!=NULL){
423 (*uniqueInds) =
malloc1d((*nUnique)*
sizeof(
int));
424 (*uniqueInds)[0] = 0;
429 dups =
malloc1d(nInputs*
sizeof(
int));
430 nDuplicates_perInput =
calloc1d(nInputs,
sizeof(
int));
431 (*nUnique) = nInputs;
435 for(i=0; i<nInputs; i++) {
437 for(j=i+1; j<nInputs; j++) {
438 if(input[i] == input[j]) {
440 for(k=0; k<nDups; k++)
441 if(input[i]==dups[k])
445 nDuplicates_perInput[i]++;
454 dups[nDups] = input[i];
458 saf_assert((*nUnique)>-1,
"Something very bad happened");
463 (*uniqueVals) = NULL;
464 (*uniqueInds) = NULL;
466 free(nDuplicates_perInput);
473 (*uniqueVals) =
malloc1d((*nUnique)*
sizeof(
int));
475 (*uniqueInds) =
malloc1d((*nUnique)*
sizeof(
int));
476 for(i=0; i<nInputs; i++) {
477 if(nDuplicates_perInput[i] == 0) {
480 (*uniqueVals)[j] = input[i];
482 (*uniqueInds)[j] = i;
488 free(nDuplicates_perInput);
501 data =
malloc1d(nElements*
sizeof(
int));
502 saf_assert(*comb==NULL,
"comb must be empty and NULL prior to calling findCombinations()");
504 combinationUtil(arrValues, data, 0, nValues-1, 0, nElements, comb, nComb);
520 float tol, s, h2, h, hh, hhh, two;
521 float** D_2, **D_3, **D_4, **D_5, **Dh, **Ym1, **Ym2;
559 D_2 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
560 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, sizeD, sizeD, sizeD, 1.0f,
564 D_3 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
565 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, sizeD, sizeD, sizeD, 1.0f,
569 D_4 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
570 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, sizeD, sizeD, sizeD, 1.0f,
574 D_5 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
575 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, sizeD, sizeD, sizeD, 1.0f,
593 Dh = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
594 memcpy(
FLATTEN2D(Dh), D, sizeD*sizeD*
sizeof(
float));
598 Ym1 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
599 for(i=0; i<sizeD; i++)
600 for(j=0; j<sizeD; j++)
601 Ym1[i][j] = Dh[i][j] + (1.0f/15.0f)*D_3[i][j];
602 Ym2 = (
float**)
malloc2d(sizeD, sizeD,
sizeof(
float));
603 for(i=0; i<sizeD; i++){
604 for(j=0; j<sizeD; j++){
605 Ym2[i][j] = (2.0f/5.0f)*D_2[i][j]-Ym1[i][j];
616 for (k = 0; k<(int)s; k++){
617 cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, sizeD, sizeD, sizeD, 1.0f,
621 for(i=0; i<sizeD; i++)
622 for(j=0; j<sizeD; j++)
623 Ym1[i][j] = Ym2[i][j] + 2.0f*Ym1[i][j];
625 memcpy(Y,
FLATTEN2D(Ym1), sizeD*sizeD*
sizeof(
float));
628 for(i=0; i<sizeD; i++)
629 for(j=0; j<sizeD; j++)
631 Y[i*sizeD+j] += 1.0f;
#define saf_assert(x, message)
Macro to make an assertion, along with a string explaining its purpose.
void findCombinations(int *arrValues, int nValues, int nElements, int **comb, int *nComb)
Given an array of values, find all the possible combinations (nCr) for subgroups of "nElements"; deri...
#define SAF_MAX(a, b)
Returns the maximum of the two values.
void findERBpartitions(float *centerFreq, int nBands, float maxFreqLim, int **erb_idx, float **erb_freqs, int *nERBBands)
This function takes a frequency vector and groups its frequencies into critical bands [Equivalent-Rec...
void convert_0_360To_m180_180(float *dirs_deg, int nDirs)
Wraps around any angles exeeding 180 degrees (e.g., 200-> -160)
float matlab_fmodf(float x, float y)
C fmodf function, except it behaves like 'mod' in Matlab (i.e.
void unique_i(int *input, int nInputs, int **uniqueVals, int **uniqueInds, int *nUnique)
Finds the unique values (and their indices) of the input vector.
void cxcorr(float *a, float *b, float *x_ab, size_t la, size_t lb)
Calculates the cross correlation between two vectors.
void rand_0_1(float *vector, int length)
Generates random numbers between 0 and 1 and stores them in the input vector.
void utility_sglslv(void *const hWork, const float *A, const int dim, float *B, int nCol, float *X)
General linear solver: single precision, i.e.
void randperm(int len, int *randperm)
Returns the indices required to randomly permute a vector of length 'len'.
void rand_cmplx_m1_1(float_complex *vector, int length)
Generates random numbers between -1 and 1 and stores them in the input vector for both the real and i...
void gexpm(float *D, int sizeD, int m1, float *Y)
Numerically solves first-order, linear, homogeneous differential equation systems,...
void polyd_m(double *X, double_complex *poly, int size_x)
Convert roots of a matrix to polynomial (real double precision)
#define SAF_MIN(a, b)
Returns the minimum of the two values.
void utility_zeig(void *const hWork, const double_complex *A, const int dim, double_complex *VL, double_complex *VR, double_complex *D, double_complex *eig)
Eigenvalue decomposition of a NON-SYMMETRIC matrix: double precision complex, i.e.
long double factorial(int n)
Factorial, accurate up to n<=25.
float Frob_norm(float *M, int lenX, int lenY)
Returns the Frobenius Norm of a matrix M, of dimensions: lenX x lenY.
float sumf(float *values, int nValues)
Returns the sum of all values.
void convd(double *x, double *h, int len_x, int len_h, double *y)
Basic 1-D direct convolution in the time-domain (real double precision)
int nextpow2(int numsamp)
A simple function which returns the next power of 2.
void polyd_v(double *x, double *poly, int len_x)
Convert roots of a vector to polynomial (real double precision)
void polyz_v(double_complex *x, double_complex *poly, int len_x)
Convert roots of a vector to polynomial (complex double precision)
void lagrangeWeights(int N, float *x, int len_x, float *weights)
Computes Lagrange interpolation weights of order 'N' for value 'x'.
int anyLessThanf(float *values, int nValues, float threshold)
Returns 1, if any value in 'values' (nValues x 1) is less than 'threshold', otherwise,...
void convz(double_complex *x, double_complex *h, int len_x, int len_h, double_complex *y)
Basic 1-D direct convolution in the time-domain (complex double precision)
void utility_svsmul(float *a, const float *s, const int len, float *c)
Single-precision, multiplies each element in vector 'a' with a scalar 's', i.e.
void rand_m1_1(float *vector, int length)
Generates random numbers between -1 and 1 and stores them in the input vector.
void ** malloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D malloc (contiguously allocated, so use free() as usual to deallocate)
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
void * calloc1d(size_t dim1, size_t data_size)
1-D calloc (same as calloc, but with error checking)
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
#define FLATTEN2D(A)
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other func...
Include header for SAF externals.
static tick_t start
Start time for whole test program.
Main header for the utilities module (SAF_UTILITIES_MODULE)
static const long double factorials_21[21]
Precomputed factorials for up to !21 (i.e.
static void combinationUtil(int *arr, int *data, int start, int end, int index, int r, int **comb, int *nComb)
Helper function for findCombinations()