Initial Commit
This commit is contained in:
@@ -0,0 +1,754 @@
|
||||
/* MOD2DENSE.C - Procedures for handling dense mod2 matrices. */
|
||||
|
||||
/* Copyright (c) 1995-2012 by Radford M. Neal.
|
||||
*
|
||||
* Permission is granted for anyone to copy, use, modify, and distribute
|
||||
* these programs and accompanying documents for any purpose, provided
|
||||
* this copyright notice is retained and prominently displayed, and note
|
||||
* is made of any changes made to these programs. These programs and
|
||||
* documents are distributed without any warranty, express or implied.
|
||||
* As the programs were written for research purposes only, they have not
|
||||
* been tested to the degree that would be advisable in any important
|
||||
* application. All use of these programs is entirely at the user's own
|
||||
* risk.
|
||||
*/
|
||||
|
||||
|
||||
/* NOTE: See mod2dense.html for documentation on these procedures. */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "intio.h"
|
||||
#include "mod2dense.h"
|
||||
|
||||
|
||||
/* ALLOCATE SPACE FOR A DENSE MOD2 MATRIX. */
|
||||
|
||||
mod2dense *mod2dense_allocate
|
||||
( int n_rows, /* Number of rows in matrix */
|
||||
int n_cols /* Number of columns in matrix */
|
||||
)
|
||||
{
|
||||
mod2dense *m;
|
||||
int j;
|
||||
|
||||
if (n_rows<=0 || n_cols<=0)
|
||||
{ fprintf(stderr,"mod2dense_allocate: Invalid number of rows or columns\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
m = chk_alloc (1, sizeof *m);
|
||||
|
||||
m->n_rows = n_rows;
|
||||
m->n_cols = n_cols;
|
||||
|
||||
m->n_words = (n_rows+mod2_wordsize-1) >> mod2_wordsize_shift;
|
||||
|
||||
m->col = chk_alloc (m->n_cols, sizeof *m->col);
|
||||
|
||||
m->bits = chk_alloc(m->n_words*m->n_cols, sizeof *m->bits);
|
||||
|
||||
for (j = 0; j<m->n_cols; j++)
|
||||
{ m->col[j] = m->bits + j*m->n_words;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/* FREE SPACE OCCUPIED BY A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_free
|
||||
( mod2dense *m /* Matrix to free */
|
||||
)
|
||||
{ if (m)
|
||||
{ free(m->bits);
|
||||
free(m->col);
|
||||
free(m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* CLEAR A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_clear
|
||||
( mod2dense *r
|
||||
)
|
||||
{
|
||||
int k, j;
|
||||
|
||||
for (j = 0; j<mod2dense_cols(r); j++)
|
||||
{ for (k = 0; k<r->n_words; k++)
|
||||
{ r->col[j][k] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* COPY A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_copy
|
||||
( mod2dense *m, /* Matrix to copy */
|
||||
mod2dense *r /* Place to store copy of matrix */
|
||||
)
|
||||
{
|
||||
int k, j;
|
||||
|
||||
if (mod2dense_rows(m)>mod2dense_rows(r)
|
||||
|| mod2dense_cols(m)>mod2dense_cols(r))
|
||||
{ fprintf(stderr,"mod2dense_copy: Destination matrix is too small\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (j = 0; j<mod2dense_cols(m); j++)
|
||||
{ for (k = 0; k<m->n_words; k++)
|
||||
{ r->col[j][k] = m->col[j][k];
|
||||
}
|
||||
for ( ; k<r->n_words; k++)
|
||||
{ r->col[j][k] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for ( ; j<mod2dense_cols(r); j++)
|
||||
{ for (k = 0; k<r->n_words; k++)
|
||||
{ r->col[j][k] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* COPY ROWS OF A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_copyrows
|
||||
( mod2dense *m, /* Matrix to copy */
|
||||
mod2dense *r, /* Place to store copy of matrix */
|
||||
int *rows /* Indexes of rows to copy, from 0 */
|
||||
)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if (mod2dense_cols(m)>mod2dense_cols(r))
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_copyrows: Destination matrix has fewer columns than source\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
|
||||
for (i = 0; i<mod2dense_rows(r); i++)
|
||||
{ if (rows[i]<0 || rows[i]>=mod2dense_rows(m))
|
||||
{ fprintf(stderr,"mod2dense_copyrows: Row index out of range\n");
|
||||
exit(1);
|
||||
}
|
||||
for (j = 0; j<mod2dense_cols(m); j++)
|
||||
{ mod2dense_set(r,i,j,mod2dense_get(m,rows[i],j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* COPY COLUMNS OF A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_copycols
|
||||
( mod2dense *m, /* Matrix to copy */
|
||||
mod2dense *r, /* Place to store copy of matrix */
|
||||
int *cols /* Indexes of columns to copy, from 0 */
|
||||
)
|
||||
{
|
||||
int k, j;
|
||||
|
||||
if (mod2dense_rows(m)>mod2dense_rows(r))
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_copycols: Destination matrix has fewer rows than source\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (j = 0; j<mod2dense_cols(r); j++)
|
||||
{ if (cols[j]<0 || cols[j]>=mod2dense_cols(m))
|
||||
{ fprintf(stderr,"mod2dense_copycols: Column index out of range\n");
|
||||
exit(1);
|
||||
}
|
||||
for (k = 0; k<m->n_words; k++)
|
||||
{ r->col[j][k] = m->col[cols[j]][k];
|
||||
}
|
||||
for ( ; k<r->n_words; k++)
|
||||
{ r->col[j][k] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* PRINT A DENSE MOD2 MATRIX IN HUMAN-READABLE FORM. */
|
||||
|
||||
void mod2dense_print
|
||||
( FILE *f,
|
||||
mod2dense *m
|
||||
)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i<mod2dense_rows(m); i++)
|
||||
{ for (j = 0; j<mod2dense_cols(m); j++)
|
||||
{ fprintf(f," %d",mod2dense_get(m,i,j));
|
||||
}
|
||||
fprintf(f,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* WRITE A DENSE MOD2 MATRIX TO A FILE IN MACHINE-READABLE FORM.
|
||||
|
||||
Data is written using intio_write, so that it will be readable on a machine
|
||||
with a different byte-ordering. At present, this assumes that the words
|
||||
used to pack bits into are no longer than 32 bits. */
|
||||
|
||||
int mod2dense_write
|
||||
( FILE *f,
|
||||
mod2dense *m
|
||||
)
|
||||
{
|
||||
int j, k;
|
||||
|
||||
intio_write(f,m->n_rows);
|
||||
if (ferror(f)) return 0;
|
||||
|
||||
intio_write(f,m->n_cols);
|
||||
if (ferror(f)) return 0;
|
||||
|
||||
for (j = 0; j<mod2dense_cols(m); j++)
|
||||
{
|
||||
for (k = 0; k<m->n_words; k++)
|
||||
{ intio_write(f,m->col[j][k]);
|
||||
if (ferror(f)) return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* READ A DENSE MOD2 MATRIX STORED IN MACHINE-READABLE FORM FROM A FILE. */
|
||||
|
||||
mod2dense *mod2dense_read
|
||||
( FILE *f
|
||||
)
|
||||
{
|
||||
int n_rows, n_cols;
|
||||
mod2dense *m;
|
||||
int j, k;
|
||||
|
||||
n_rows = intio_read(f);
|
||||
if (feof(f) || ferror(f) || n_rows<=0) return 0;
|
||||
|
||||
n_cols = intio_read(f);
|
||||
if (feof(f) || ferror(f) || n_cols<=0) return 0;
|
||||
|
||||
m = mod2dense_allocate(n_rows,n_cols);
|
||||
|
||||
for (j = 0; j<mod2dense_cols(m); j++)
|
||||
{
|
||||
for (k = 0; k<m->n_words; k++)
|
||||
{ m->col[j][k] = intio_read(f);
|
||||
if (feof(f) || ferror(f))
|
||||
{ mod2dense_free(m);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/* GET AN ELEMENT FROM A DENSE MOD2 MATRIX. */
|
||||
|
||||
int mod2dense_get
|
||||
( mod2dense *m, /* Matrix to get element from */
|
||||
int row, /* Row of element (starting with zero) */
|
||||
int col /* Column of element (starting with zero) */
|
||||
)
|
||||
{
|
||||
if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m))
|
||||
{ fprintf(stderr,"mod2dense_get: row or column index out of bounds\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return mod2_getbit (m->col[col][row>>mod2_wordsize_shift],
|
||||
row&mod2_wordsize_mask);
|
||||
}
|
||||
|
||||
|
||||
/* SET AN ELEMENT IN A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_set
|
||||
( mod2dense *m, /* Matrix to modify element of */
|
||||
int row, /* Row of element (starting with zero) */
|
||||
int col, /* Column of element (starting with zero) */
|
||||
int value /* New value of element (0 or 1) */
|
||||
)
|
||||
{
|
||||
mod2word *w;
|
||||
|
||||
if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m))
|
||||
{ fprintf(stderr,"mod2dense_set: row or column index out of bounds\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
w = &m->col[col][row>>mod2_wordsize_shift];
|
||||
|
||||
*w = value ? mod2_setbit1(*w,row&mod2_wordsize_mask)
|
||||
: mod2_setbit0(*w,row&mod2_wordsize_mask);
|
||||
}
|
||||
|
||||
|
||||
/* FLIP AN ELEMENT OF A DENSE MOD2 MATRIX. */
|
||||
|
||||
int mod2dense_flip
|
||||
( mod2dense *m, /* Matrix to flip element in */
|
||||
int row, /* Row of element (starting with zero) */
|
||||
int col /* Column of element (starting with zero) */
|
||||
)
|
||||
{
|
||||
mod2word *w;
|
||||
int b;
|
||||
|
||||
if (row<0 || row>=mod2dense_rows(m) || col<0 || col>=mod2dense_cols(m))
|
||||
{ fprintf(stderr,"mod2dense_flip: row or column index out of bounds\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
b = 1 ^ mod2_getbit (m->col[col][row>>mod2_wordsize_shift],
|
||||
row&mod2_wordsize_mask);
|
||||
|
||||
w = &m->col[col][row>>mod2_wordsize_shift];
|
||||
|
||||
*w = b ? mod2_setbit1(*w,row&mod2_wordsize_mask)
|
||||
: mod2_setbit0(*w,row&mod2_wordsize_mask);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/* COMPUTE THE TRANSPOSE OF A DENSE MOD2 MATRIX. */
|
||||
|
||||
void mod2dense_transpose
|
||||
( mod2dense *m, /* Matrix to compute transpose of (left unchanged) */
|
||||
mod2dense *r /* Result of transpose operation */
|
||||
)
|
||||
{
|
||||
mod2word w, v, *p;
|
||||
int k1, j1, i2, j2;
|
||||
|
||||
if (mod2dense_rows(m)!=mod2dense_cols(r)
|
||||
|| mod2dense_cols(m)!=mod2dense_rows(r))
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_transpose: Matrices have incompatible dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (r==m)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_transpose: Result matrix is the same as the operand\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
|
||||
for (j1 = 0; j1<mod2dense_cols(m); j1++)
|
||||
{
|
||||
i2 = j1 >> mod2_wordsize_shift;
|
||||
v = 1 << (j1 & mod2_wordsize_mask);
|
||||
|
||||
p = m->col[j1];
|
||||
k1 = 0;
|
||||
|
||||
for (j2 = 0; j2<mod2dense_cols(r); j2++)
|
||||
{ if (k1==0)
|
||||
{ w = *p++;
|
||||
k1 = mod2_wordsize;
|
||||
}
|
||||
if (w&1)
|
||||
{ r->col[j2][i2] |= v;
|
||||
}
|
||||
w >>= 1;
|
||||
k1 -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ADD TWO DENSE MOD2 MATRICES. */
|
||||
|
||||
void mod2dense_add
|
||||
( mod2dense *m1, /* Left operand of add */
|
||||
mod2dense *m2, /* Right operand of add */
|
||||
mod2dense *r /* Place to store result of add */
|
||||
)
|
||||
{
|
||||
int j, k;
|
||||
|
||||
if (mod2dense_rows(m1)!=mod2dense_rows(r)
|
||||
|| mod2dense_cols(m1)!=mod2dense_cols(r)
|
||||
|| mod2dense_rows(m2)!=mod2dense_rows(r)
|
||||
|| mod2dense_cols(m2)!=mod2dense_cols(r))
|
||||
{ fprintf(stderr,"mod2dense_add: Matrices have different dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (j = 0; j<mod2dense_cols(r); j++)
|
||||
{ for (k = 0; k<r->n_words; k++)
|
||||
{ r->col[j][k] = m1->col[j][k] ^ m2->col[j][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* MULTIPLY TWO DENSE MOD2 MATRICES.
|
||||
|
||||
The algorithm used runs faster if the second matrix (right operand of the
|
||||
multiply) is sparse, but it is also appropriate for dense matrices. This
|
||||
procedure could be speeded up a bit by replacing the call of mod2dense_get
|
||||
with in-line code that avoids division, but this doesn't seem worthwhile
|
||||
at the moment.
|
||||
*/
|
||||
|
||||
void mod2dense_multiply
|
||||
( mod2dense *m1, /* Left operand of multiply */
|
||||
mod2dense *m2, /* Right operand of multiply */
|
||||
mod2dense *r /* Place to store result of multiply */
|
||||
)
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
if (mod2dense_cols(m1)!=mod2dense_rows(m2)
|
||||
|| mod2dense_rows(m1)!=mod2dense_rows(r)
|
||||
|| mod2dense_cols(m2)!=mod2dense_cols(r))
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_multiply: Matrices have incompatible dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (r==m1 || r==m2)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_multiply: Result matrix is the same as one of the operands\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
|
||||
for (j = 0; j<mod2dense_cols(r); j++)
|
||||
{ for (i = 0; i<mod2dense_rows(m2); i++)
|
||||
{ if (mod2dense_get(m2,i,j))
|
||||
{ for (k = 0; k<r->n_words; k++)
|
||||
{ r->col[j][k] ^= m1->col[i][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* SEE WHETHER TWO DENSE MOD2 MATRICES ARE EQUAL. */
|
||||
|
||||
int mod2dense_equal
|
||||
( mod2dense *m1,
|
||||
mod2dense *m2
|
||||
)
|
||||
{
|
||||
int k, j, w;
|
||||
mod2word m;
|
||||
|
||||
if (mod2dense_rows(m1)!=mod2dense_rows(m2)
|
||||
|| mod2dense_cols(m1)!=mod2dense_cols(m2))
|
||||
{ fprintf(stderr,"mod2dense_equal: Matrices have different dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
w = m1->n_words;
|
||||
|
||||
/* Form a mask that has 1s in the lower bit positions corresponding to
|
||||
bits that contain information in the last word of a matrix column. */
|
||||
|
||||
m = (1 << (mod2_wordsize - (w*mod2_wordsize-m1->n_rows))) - 1;
|
||||
|
||||
for (j = 0; j<mod2dense_cols(m1); j++)
|
||||
{
|
||||
for (k = 0; k<w-1; k++)
|
||||
{ if (m1->col[j][k] != m2->col[j][k]) return 0;
|
||||
}
|
||||
|
||||
if ((m1->col[j][k]&m) != (m2->col[j][k]&m)) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* INVERT A DENSE MOD2 MATRIX. */
|
||||
|
||||
int mod2dense_invert
|
||||
( mod2dense *m, /* The matrix to find the inverse of (destroyed) */
|
||||
mod2dense *r /* Place to store the inverse */
|
||||
)
|
||||
{
|
||||
mod2word *s, *t;
|
||||
int i, j, k, n, w, k0, b0;
|
||||
|
||||
if (mod2dense_rows(m)!=mod2dense_cols(m))
|
||||
{ fprintf(stderr,"mod2dense_invert: Matrix to invert is not square\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (r==m)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_invert: Result matrix is the same as the operand\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
n = mod2dense_rows(m);
|
||||
w = m->n_words;
|
||||
|
||||
if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_invert: Matrix to receive inverse has wrong dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
for (i = 0; i<n; i++)
|
||||
{ mod2dense_set(r,i,i,1);
|
||||
}
|
||||
|
||||
for (i = 0; i<n; i++)
|
||||
{
|
||||
k0 = i >> mod2_wordsize_shift;
|
||||
b0 = i & mod2_wordsize_mask;
|
||||
|
||||
for (j = i; j<n; j++)
|
||||
{ if (mod2_getbit(m->col[j][k0],b0)) break;
|
||||
}
|
||||
|
||||
if (j==n) return 0;
|
||||
|
||||
if (j!=i)
|
||||
{
|
||||
t = m->col[i];
|
||||
m->col[i] = m->col[j];
|
||||
m->col[j] = t;
|
||||
|
||||
t = r->col[i];
|
||||
r->col[i] = r->col[j];
|
||||
r->col[j] = t;
|
||||
}
|
||||
|
||||
for (j = 0; j<n; j++)
|
||||
{ if (j!=i && mod2_getbit(m->col[j][k0],b0))
|
||||
{ s = m->col[j];
|
||||
t = m->col[i];
|
||||
for (k = k0; k<w; k++) s[k] ^= t[k];
|
||||
s = r->col[j];
|
||||
t = r->col[i];
|
||||
for (k = 0; k<w; k++) s[k] ^= t[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* INVERT A DENSE MOD2 MATRIX WITH ROWS & COLUMNS SELECTED FROM BIGGER MATRIX.*/
|
||||
|
||||
int mod2dense_invert_selected
|
||||
( mod2dense *m, /* Matrix from which to pick a submatrix to invert */
|
||||
mod2dense *r, /* Place to store the inverse */
|
||||
int *rows, /* Set to indexes of rows used and not used */
|
||||
int *cols /* Set to indexes of columns used and not used */
|
||||
)
|
||||
{
|
||||
mod2word *s, *t;
|
||||
int i, j, k, n, n2, w, k0, b0, c, R;
|
||||
|
||||
if (r==m)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_invert_selected2: Result matrix is the same as the operand\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
n = mod2dense_rows(m);
|
||||
w = m->n_words;
|
||||
|
||||
n2 = mod2dense_cols(m);
|
||||
|
||||
if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n2)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_invert_selected2: Matrix to receive inverse has wrong dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
|
||||
for (i = 0; i<n; i++)
|
||||
{ rows[i] = i;
|
||||
}
|
||||
|
||||
for (j = 0; j<n2; j++)
|
||||
{ cols[j] = j;
|
||||
}
|
||||
|
||||
R = 0;
|
||||
i = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
while (i<n-R)
|
||||
{
|
||||
k0 = rows[i] >> mod2_wordsize_shift;
|
||||
b0 = rows[i] & mod2_wordsize_mask;
|
||||
|
||||
for (j = i; j<n2; j++)
|
||||
{ if (mod2_getbit(m->col[cols[j]][k0],b0)) break;
|
||||
}
|
||||
|
||||
if (j<n2) break;
|
||||
|
||||
R += 1;
|
||||
c = rows[i];
|
||||
rows[i] = rows[n-R];
|
||||
rows[n-R] = c;
|
||||
|
||||
}
|
||||
|
||||
if (i==n-R) break;
|
||||
|
||||
c = cols[j];
|
||||
cols[j] = cols[i];
|
||||
cols[i] = c;
|
||||
|
||||
mod2dense_set(r,rows[i],c,1);
|
||||
|
||||
for (j = 0; j<n2; j++)
|
||||
{ if (j!=c && mod2_getbit(m->col[j][k0],b0))
|
||||
{ s = m->col[j];
|
||||
t = m->col[c];
|
||||
for (k = 0; k<w; k++) s[k] ^= t[k];
|
||||
s = r->col[j];
|
||||
t = r->col[c];
|
||||
for (k = 0; k<w; k++) s[k] ^= t[k];
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
for (j = n-R; j<n; j++)
|
||||
{ s = r->col[cols[j]];
|
||||
for (k = 0; k<w; k++) s[k] = 0;
|
||||
}
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
|
||||
/* FORCIBLY INVERT A DENSE MOD2 MATRIX. */
|
||||
|
||||
int mod2dense_forcibly_invert
|
||||
( mod2dense *m, /* The matrix to find the inverse of (destroyed) */
|
||||
mod2dense *r, /* Place to store the inverse */
|
||||
int *a_row, /* Place to store row indexes of altered elements */
|
||||
int *a_col /* Place to store column indexes of altered elements */
|
||||
)
|
||||
{
|
||||
mod2word *s, *t;
|
||||
int i, j, k, n, w, k0, b0;
|
||||
int u, c;
|
||||
|
||||
if (mod2dense_rows(m)!=mod2dense_cols(m))
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_forcibly_invert: Matrix to invert is not square\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (r==m)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_forcibly_invert: Result matrix is the same as the operand\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
n = mod2dense_rows(m);
|
||||
w = m->n_words;
|
||||
|
||||
if (mod2dense_rows(r)!=n || mod2dense_cols(r)!=n)
|
||||
{ fprintf(stderr,
|
||||
"mod2dense_forcibly_invert: Matrix to receive inverse has wrong dimensions\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mod2dense_clear(r);
|
||||
for (i = 0; i<n; i++)
|
||||
{ mod2dense_set(r,i,i,1);
|
||||
}
|
||||
|
||||
for (i = 0; i<n; i++)
|
||||
{ a_row[i] = -1;
|
||||
a_col[i] = i;
|
||||
}
|
||||
|
||||
for (i = 0; i<n; i++)
|
||||
{
|
||||
k0 = i >> mod2_wordsize_shift;
|
||||
b0 = i & mod2_wordsize_mask;
|
||||
|
||||
for (j = i; j<n; j++)
|
||||
{ if (mod2_getbit(m->col[j][k0],b0)) break;
|
||||
}
|
||||
|
||||
if (j==n)
|
||||
{ j = i;
|
||||
mod2dense_set(m,i,j,1);
|
||||
a_row[i] = i;
|
||||
}
|
||||
|
||||
if (j!=i)
|
||||
{
|
||||
t = m->col[i];
|
||||
m->col[i] = m->col[j];
|
||||
m->col[j] = t;
|
||||
|
||||
t = r->col[i];
|
||||
r->col[i] = r->col[j];
|
||||
r->col[j] = t;
|
||||
|
||||
u = a_col[i];
|
||||
a_col[i] = a_col[j];
|
||||
a_col[j] = u;
|
||||
}
|
||||
|
||||
for (j = 0; j<n; j++)
|
||||
{ if (j!=i && mod2_getbit(m->col[j][k0],b0))
|
||||
{ s = m->col[j];
|
||||
t = m->col[i];
|
||||
for (k = k0; k<w; k++) s[k] ^= t[k];
|
||||
s = r->col[j];
|
||||
t = r->col[i];
|
||||
for (k = 0; k<w; k++) s[k] ^= t[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c = 0;
|
||||
for (i = 0; i<n; i++)
|
||||
{ if (a_row[i]!=-1)
|
||||
{ a_row[c] = a_row[i];
|
||||
a_col[c] = a_col[i];
|
||||
c += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_FUSION_ITERATOR_10012005_1551)
|
||||
#define FUSION_FUSION_ITERATOR_10012005_1551
|
||||
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/iterator/value_of.hpp>
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/iterator/prior.hpp>
|
||||
#include <boost/fusion/iterator/advance.hpp>
|
||||
#include <boost/fusion/iterator/distance.hpp>
|
||||
#include <boost/fusion/support/category_of.hpp>
|
||||
#include <boost/mpl/next_prior.hpp>
|
||||
#include <boost/mpl/advance_fwd.hpp>
|
||||
#include <boost/mpl/distance_fwd.hpp>
|
||||
#include <boost/mpl/iterator_tags.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
|
||||
namespace boost { namespace fusion { namespace detail
|
||||
{
|
||||
|
||||
template<class Category>
|
||||
struct to_mpl_category {
|
||||
typedef typename mpl::eval_if<
|
||||
is_base_of<random_access_traversal_tag, Category>,
|
||||
mpl::random_access_iterator_tag,
|
||||
mpl::eval_if<
|
||||
is_base_of<bidirectional_traversal_tag, Category>,
|
||||
mpl::bidirectional_iterator_tag,
|
||||
mpl::forward_iterator_tag
|
||||
>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace mpl
|
||||
{
|
||||
template <typename Iterator>
|
||||
struct fusion_iterator
|
||||
{
|
||||
typedef typename fusion::result_of::value_of<Iterator>::type type;
|
||||
typedef typename fusion::traits::category_of<Iterator>::type fusion_category;
|
||||
typedef typename fusion::detail::to_mpl_category<fusion_category>::type category;
|
||||
typedef Iterator iterator;
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct next<fusion_iterator<Iterator> >
|
||||
{
|
||||
typedef fusion_iterator<typename fusion::result_of::next<Iterator>::type> type;
|
||||
};
|
||||
|
||||
template <typename Iterator>
|
||||
struct prior<fusion_iterator<Iterator> >
|
||||
{
|
||||
typedef fusion_iterator<typename fusion::result_of::prior<Iterator>::type> type;
|
||||
};
|
||||
|
||||
template <typename Iterator, typename N>
|
||||
struct advance<fusion_iterator<Iterator>, N>
|
||||
{
|
||||
typedef fusion_iterator<typename fusion::result_of::advance<Iterator, N>::type> type;
|
||||
};
|
||||
|
||||
template <typename First, typename Last>
|
||||
struct distance<fusion_iterator<First>, fusion_iterator<Last> >
|
||||
: fusion::result_of::distance<First, Last>
|
||||
{};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
|
||||
make-ldpc ex-ldpc36-1000a.pchk 1000 2000 1 evenboth 3 no4cycle
|
||||
Eliminated 24 cycles of length four by moving checks within column
|
||||
make-gen ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen dense
|
||||
Number of 1s per check in Inv(A) X B is 400.3
|
||||
rand-src ex-ldpc36-1000a.src 1 1000x100
|
||||
encode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.gen ex-ldpc36-1000a.src \
|
||||
ex-ldpc36-1000a.enc
|
||||
Encoded 100 blocks, source block size 1000, encoded block size 2000
|
||||
|
||||
# NOISE STANDARD DEVIATION 0.80, Eb/N0 = 1.94 dB
|
||||
|
||||
transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.80
|
||||
Transmitted 200000 bits
|
||||
decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.80\
|
||||
prprp 250
|
||||
Decoded 100 blocks, 100 valid. Average 10.8 iterations, 11% bit changes
|
||||
verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \
|
||||
ex-ldpc36-1000a.src
|
||||
Block counts: tot 100, with chk errs 0, with src errs 0, both 0
|
||||
Bit error rate (on message bits only): 0.000e+00
|
||||
|
||||
# NOISE STANDARD DEVIATION 0.85, Eb/N0 = 1.41 dB
|
||||
|
||||
transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.85
|
||||
Transmitted 200000 bits
|
||||
decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.85\
|
||||
prprp 250
|
||||
Decoded 100 blocks, 88 valid. Average 52.2 iterations, 12% bit changes
|
||||
verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \
|
||||
ex-ldpc36-1000a.src
|
||||
Block counts: tot 100, with chk errs 12, with src errs 12, both 12
|
||||
Bit error rate (on message bits only): 7.490e-03
|
||||
|
||||
# NOISE STANDARD DEVIATION 0.90, Eb/N0 = 0.92 dB
|
||||
|
||||
transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.90
|
||||
Transmitted 200000 bits
|
||||
decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.90\
|
||||
prprp 250
|
||||
Decoded 100 blocks, 19 valid. Average 209.4 iterations, 11% bit changes
|
||||
verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \
|
||||
ex-ldpc36-1000a.src
|
||||
Block counts: tot 100, with chk errs 81, with src errs 81, both 81
|
||||
Bit error rate (on message bits only): 6.529e-02
|
||||
|
||||
# NOISE STANDARD DEVIATION 0.95, Eb/N0 = 0.45 dB
|
||||
|
||||
transmit ex-ldpc36-1000a.enc ex-ldpc36-1000a.rec 1 awgn 0.95
|
||||
Transmitted 200000 bits
|
||||
decode ex-ldpc36-1000a.pchk ex-ldpc36-1000a.rec ex-ldpc36-1000a.dec awgn 0.95\
|
||||
prprp 250
|
||||
Decoded 100 blocks, 1 valid. Average 248.0 iterations, 9% bit changes
|
||||
verify ex-ldpc36-1000a.pchk ex-ldpc36-1000a.dec ex-ldpc36-1000a.gen \
|
||||
ex-ldpc36-1000a.src
|
||||
Block counts: tot 100, with chk errs 99, with src errs 99, both 99
|
||||
Bit error rate (on message bits only): 1.055e-01
|
||||
@@ -0,0 +1,135 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2006 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_ZIP_VIEW_23012006_0813)
|
||||
#define FUSION_ZIP_VIEW_23012006_0813
|
||||
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/support/sequence_base.hpp>
|
||||
#include <boost/fusion/support/unused.hpp>
|
||||
#include <boost/fusion/iterator/equal_to.hpp>
|
||||
#include <boost/fusion/view/detail/strictest_traversal.hpp>
|
||||
#include <boost/fusion/view/zip_view/detail/begin_impl.hpp>
|
||||
#include <boost/fusion/view/zip_view/detail/end_impl.hpp>
|
||||
#include <boost/fusion/view/zip_view/detail/size_impl.hpp>
|
||||
#include <boost/fusion/view/zip_view/detail/at_impl.hpp>
|
||||
#include <boost/fusion/view/zip_view/detail/value_at_impl.hpp>
|
||||
#include <boost/fusion/container/vector/convert.hpp>
|
||||
#include <boost/fusion/algorithm/query/find_if.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/end.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/remove.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/placeholders.hpp>
|
||||
#include <boost/mpl/transform_view.hpp>
|
||||
#include <boost/mpl/at.hpp>
|
||||
#include <boost/mpl/find_if.hpp>
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<typename Sequences>
|
||||
struct all_references
|
||||
: fusion::result_of::equal_to<typename fusion::result_of::find_if<Sequences, mpl::not_<is_reference<mpl::_> > >::type, typename fusion::result_of::end<Sequences>::type>
|
||||
{};
|
||||
|
||||
struct seq_ref_size
|
||||
{
|
||||
template<typename Params>
|
||||
struct result;
|
||||
|
||||
template<typename Seq>
|
||||
struct result<seq_ref_size(Seq)>
|
||||
{
|
||||
static int const high_int = static_cast<int>(
|
||||
(static_cast<unsigned>(~0) >> 1) - 1);
|
||||
|
||||
typedef typename remove_reference<Seq>::type SeqClass;
|
||||
|
||||
typedef typename mpl::eval_if<
|
||||
traits::is_forward<SeqClass>,
|
||||
result_of::size<SeqClass>,
|
||||
mpl::int_<high_int> >::type type;
|
||||
};
|
||||
|
||||
// never called, but needed for decltype-based result_of (C++0x)
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename Seq>
|
||||
BOOST_FUSION_GPU_ENABLED
|
||||
typename result<seq_ref_size(Seq)>::type
|
||||
operator()(Seq&&) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct poly_min
|
||||
{
|
||||
template<typename T>
|
||||
struct result;
|
||||
|
||||
template<typename Lhs, typename Rhs>
|
||||
struct result<poly_min(Lhs, Rhs)>
|
||||
{
|
||||
typedef typename remove_reference<Lhs>::type lhs;
|
||||
typedef typename remove_reference<Rhs>::type rhs;
|
||||
typedef typename mpl::min<lhs, rhs>::type type;
|
||||
};
|
||||
|
||||
// never called, but needed for decltype-based result_of (C++0x)
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename Lhs, typename Rhs>
|
||||
BOOST_FUSION_GPU_ENABLED
|
||||
typename result<poly_min(Lhs, Rhs)>::type
|
||||
operator()(Lhs&&, Rhs&&) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename Sequences>
|
||||
struct min_size
|
||||
{
|
||||
typedef typename result_of::transform<Sequences, detail::seq_ref_size>::type sizes;
|
||||
typedef typename result_of::fold<sizes, typename result_of::front<sizes>::type, detail::poly_min>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
struct zip_view_tag;
|
||||
struct fusion_sequence_tag;
|
||||
|
||||
template<typename Sequences>
|
||||
struct zip_view : sequence_base< zip_view<Sequences> >
|
||||
{
|
||||
typedef typename result_of::remove<Sequences, unused_type const&>::type real_sequences;
|
||||
BOOST_MPL_ASSERT((detail::all_references<Sequences>));
|
||||
typedef typename detail::strictest_traversal<real_sequences>::type category;
|
||||
typedef zip_view_tag fusion_tag;
|
||||
typedef fusion_sequence_tag tag; // this gets picked up by MPL
|
||||
typedef mpl::true_ is_view;
|
||||
typedef typename fusion::result_of::as_vector<Sequences>::type sequences;
|
||||
typedef typename detail::min_size<real_sequences>::type size;
|
||||
|
||||
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
||||
zip_view(
|
||||
const Sequences& seqs)
|
||||
: sequences_(seqs)
|
||||
{}
|
||||
|
||||
sequences sequences_;
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,82 @@
|
||||
#ifndef BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
||||
#define BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
||||
// collections_save_imp.hpp: serialization for stl collections
|
||||
|
||||
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
// helper function templates for serialization of collections
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include <boost/serialization/collection_size_type.hpp>
|
||||
#include <boost/serialization/item_version_type.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace serialization {
|
||||
namespace stl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// implementation of serialization for STL containers
|
||||
//
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void save_collection(
|
||||
Archive & ar,
|
||||
const Container &s,
|
||||
collection_size_type count)
|
||||
{
|
||||
ar << BOOST_SERIALIZATION_NVP(count);
|
||||
// record number of elements
|
||||
const item_version_type item_version(
|
||||
version<typename Container::value_type>::value
|
||||
);
|
||||
#if 0
|
||||
boost::archive::library_version_type library_version(
|
||||
ar.get_library_version()
|
||||
);
|
||||
if(boost::archive::library_version_type(3) < library_version){
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
}
|
||||
#else
|
||||
ar << BOOST_SERIALIZATION_NVP(item_version);
|
||||
#endif
|
||||
|
||||
typename Container::const_iterator it = s.begin();
|
||||
while(count-- > 0){
|
||||
// note borland emits a no-op without the explicit namespace
|
||||
boost::serialization::save_construct_data_adl(
|
||||
ar,
|
||||
&(*it),
|
||||
item_version
|
||||
);
|
||||
ar << boost::serialization::make_nvp("item", *it++);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Archive, class Container>
|
||||
inline void save_collection(Archive & ar, const Container &s)
|
||||
{
|
||||
// record number of elements
|
||||
collection_size_type count(s.size());
|
||||
save_collection(ar, s, count);
|
||||
}
|
||||
|
||||
} // namespace stl
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif //BOOST_SERIALIZATION_COLLECTIONS_SAVE_IMP_HPP
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
[auto_generated]
|
||||
boost/numeric/odeint/integrate/null_observer.hpp
|
||||
|
||||
[begin_description]
|
||||
null_observer
|
||||
[end_description]
|
||||
|
||||
Copyright 2011-2012 Karsten Ahnert
|
||||
Copyright 2011-2012 Mario Mulansky
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or
|
||||
copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
|
||||
#define BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
|
||||
|
||||
namespace boost {
|
||||
namespace numeric {
|
||||
namespace odeint {
|
||||
|
||||
struct null_observer
|
||||
{
|
||||
template< class State , class Time >
|
||||
void operator()( const State& /* x */ , Time /* t */ ) const
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace odeint
|
||||
} // namespace numeric
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NUMERIC_ODEINT_INTEGRATE_NULL_OBSERVER_HPP_INCLUDED
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* -*- c++ -*-
|
||||
*
|
||||
* \file num_columns.hpp
|
||||
*
|
||||
* \brief The \c num_columns operation.
|
||||
*
|
||||
* Copyright (c) 2009, Marco Guazzone
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* \author Marco Guazzone, marco.guazzone@gmail.com
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
|
||||
#define BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
|
||||
|
||||
|
||||
#include <boost/numeric/ublas/detail/config.hpp>
|
||||
#include <boost/numeric/ublas/expression_types.hpp>
|
||||
#include <boost/numeric/ublas/traits.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace numeric { namespace ublas {
|
||||
|
||||
/**
|
||||
* \brief Return the number of columns.
|
||||
* \tparam MatrixExprT A type which models the matrix expression concept.
|
||||
* \param m A matrix expression.
|
||||
* \return The number of columns.
|
||||
*/
|
||||
template <typename MatrixExprT>
|
||||
BOOST_UBLAS_INLINE
|
||||
typename matrix_traits<MatrixExprT>::size_type num_columns(matrix_expression<MatrixExprT> const& me)
|
||||
{
|
||||
return me().size2();
|
||||
}
|
||||
|
||||
}}} // Namespace boost::numeric::ublas
|
||||
|
||||
|
||||
#endif // BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
|
||||
@@ -0,0 +1,72 @@
|
||||
program fersum
|
||||
|
||||
character mode*5
|
||||
character infile*40
|
||||
real dop(0:9)
|
||||
real thresh(0:9,12),threshsync(0:9,12)
|
||||
data dop/0.25,0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0/
|
||||
|
||||
nargs=iargc()
|
||||
if(nargs.ne.1) then
|
||||
print*,'Usage: fersum <infile>'
|
||||
go to 999
|
||||
endif
|
||||
call getarg(1,infile)
|
||||
open(10,file=infile,status='old')
|
||||
thresh=0.
|
||||
threshsync=0.
|
||||
|
||||
do iblk=1,999
|
||||
1 read(10,1002,end=100) mode,iters,ntot,naggr,d,navg,nds
|
||||
1002 format(a5,8x,i5,4x,i6,7x,i3,6x,f6.2,17x,i3,5x,i2)
|
||||
write(33,*) iblk,mode
|
||||
if(mode.eq.' ') go to 1
|
||||
read(10,1002)
|
||||
read(10,1002)
|
||||
read(10,1002)
|
||||
|
||||
nsync0=0
|
||||
ngood0=0
|
||||
xsum0=0.
|
||||
do n=1,99
|
||||
read(10,1010,end=100) snr,nsync,ngood,nbad,xsync,esync,dsnr,esnr, &
|
||||
xdt,edt,dfreq,efreq,xsum,esum,xwidth,ewidth
|
||||
1010 format(f5.1,2i6i4,2f6.1,f6.1,f5.1,f6.2,f5.2,6f5.1)
|
||||
if(snr.eq.0.0) exit
|
||||
if(mode(5:5).eq.'A') nmode=1
|
||||
if(mode(5:5).eq.'B') nmode=2
|
||||
if(mode(5:5).eq.'C') nmode=3
|
||||
j=nint(log(d)/log(2.0) + 2.0)
|
||||
if(navg.eq.1 .and. nds.eq.0) k=nmode
|
||||
if(navg.eq.1 .and. nds.eq.1) k=nmode+3
|
||||
if(navg.gt.1 .and. nds.eq.0) k=nmode+6
|
||||
if(navg.gt.1 .and. nds.eq.1) k=nmode+9
|
||||
if(nsync0.le.iters/2 .and. nsync.ge.iters/2) then
|
||||
threshsync(j,k)=snr-float(nsync-iters/2)/(nsync-nsync0)
|
||||
endif
|
||||
if(ngood0.le.iters/2 .and. ngood.ge.iters/2) then
|
||||
threshold=snr-float(ngood-iters/2)/(ngood-ngood0)
|
||||
xsumavg=max(1.0,0.5*(xsum0+xsum))
|
||||
! write(*,1020) mode,iters,ntot,naggr,d,navg,nds,threshold,xsumavg
|
||||
!1020 format(a5,i7,i7,i3,f7.2,i3,i3,f7.1,f6.1)
|
||||
thresh(j,k)=threshold
|
||||
endif
|
||||
nsync0=nsync
|
||||
ngood0=ngood
|
||||
xsum0=xsum
|
||||
enddo
|
||||
enddo
|
||||
|
||||
100 write(12,1100)
|
||||
1100 format(' ')
|
||||
do i=0,9
|
||||
write(12,1110) dop(i),thresh(i,1:12)
|
||||
1110 format(f6.2,13f6.1)
|
||||
enddo
|
||||
|
||||
write(12,1110)
|
||||
do i=0,9
|
||||
write(12,1110) dop(i),threshsync(i,1:12)
|
||||
enddo
|
||||
|
||||
999 end program fersum
|
||||
@@ -0,0 +1,23 @@
|
||||
// (C) Copyright John Maddock 2005.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
#define BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
|
||||
#ifndef BOOST_MATH_HYPOT_INCLUDED
|
||||
# include <boost/math/special_functions/hypot.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace math{
|
||||
|
||||
template<class T>
|
||||
inline T fabs(const std::complex<T>& z)
|
||||
{
|
||||
return ::boost::math::hypot(z.real(), z.imag());
|
||||
}
|
||||
|
||||
} } // namespaces
|
||||
|
||||
#endif // BOOST_MATH_COMPLEX_FABS_INCLUDED
|
||||
@@ -0,0 +1,36 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// See http://boostorg.github.com/compute for more information.
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP
|
||||
#define BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP
|
||||
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/algorithm/find_if_not.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace compute {
|
||||
|
||||
/// Returns \c true if \p predicate returns \c true for all of the elements in
|
||||
/// the range [\p first, \p last).
|
||||
///
|
||||
/// \see any_of(), none_of()
|
||||
template<class InputIterator, class UnaryPredicate>
|
||||
inline bool all_of(InputIterator first,
|
||||
InputIterator last,
|
||||
UnaryPredicate predicate,
|
||||
command_queue &queue = system::default_queue())
|
||||
{
|
||||
return ::boost::compute::find_if_not(first, last, predicate, queue) == last;
|
||||
}
|
||||
|
||||
} // end compute namespace
|
||||
} // end boost namespace
|
||||
|
||||
#endif // BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP
|
||||
@@ -0,0 +1,59 @@
|
||||
#if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES)
|
||||
|
||||
#include <boost/proto/detail/preprocessed/or_n.hpp>
|
||||
|
||||
#elif !defined(BOOST_PP_IS_ITERATING)
|
||||
|
||||
#if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 2, line: 0, output: "preprocessed/or_n.hpp")
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// \file or_n.hpp
|
||||
/// Definitions of or_N
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(preserve: 1)
|
||||
#endif
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 \
|
||||
(3, (2, BOOST_PROTO_MAX_LOGICAL_ARITY, <boost/proto/detail/or_n.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
#if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES)
|
||||
#pragma wave option(output: null)
|
||||
#endif
|
||||
|
||||
#else // BOOST_PP_IS_ITERATING
|
||||
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
template<bool B, typename Expr, typename BasicExpr, BOOST_PP_ENUM_PARAMS(N, typename G)>
|
||||
struct BOOST_PP_CAT(or_, N)
|
||||
#if 2 == N
|
||||
: mpl::bool_<matches_<Expr, BasicExpr, typename G1::proto_grammar>::value>
|
||||
{
|
||||
typedef G1 which;
|
||||
};
|
||||
#else
|
||||
: BOOST_PP_CAT(or_, BOOST_PP_DEC(N))<
|
||||
matches_<Expr, BasicExpr, typename G1::proto_grammar>::value
|
||||
, Expr, BasicExpr, BOOST_PP_ENUM_SHIFTED_PARAMS(N, G)
|
||||
>
|
||||
{};
|
||||
#endif
|
||||
|
||||
template<typename Expr, typename BasicExpr BOOST_PP_ENUM_TRAILING_PARAMS(N, typename G)>
|
||||
struct BOOST_PP_CAT(or_, N)<true, Expr, BasicExpr, BOOST_PP_ENUM_PARAMS(N, G)>
|
||||
: mpl::true_
|
||||
{
|
||||
typedef G0 which;
|
||||
};
|
||||
|
||||
#undef N
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range
|
||||
{
|
||||
|
||||
/// \brief template function reverse_copy
|
||||
///
|
||||
/// range-based version of the reverse_copy std algorithm
|
||||
///
|
||||
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
|
||||
template<class BidirectionalRange, class OutputIterator>
|
||||
inline OutputIterator reverse_copy(const BidirectionalRange& rng, OutputIterator out)
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
|
||||
return std::reverse_copy(boost::begin(rng), boost::end(rng), out);
|
||||
}
|
||||
|
||||
} // namespace range
|
||||
using range::reverse_copy;
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,167 @@
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_HPP_INCLUDED
|
||||
#define BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_HPP_INCLUDED
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
// detail/sp_counted_base_gcc_sparc.hpp - g++ on Sparc V8+
|
||||
//
|
||||
// Copyright (c) 2006 Piotr Wyderski
|
||||
// Copyright (c) 2006 Tomas Puverle
|
||||
// Copyright (c) 2006 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// Thanks to Michael van der Westhuizen
|
||||
|
||||
#include <boost/detail/sp_typeinfo.hpp>
|
||||
#include <inttypes.h> // int32_t
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline int32_t compare_and_swap( int32_t * dest_, int32_t compare_, int32_t swap_ )
|
||||
{
|
||||
__asm__ __volatile__( "cas [%1], %2, %0"
|
||||
: "+r" (swap_)
|
||||
: "r" (dest_), "r" (compare_)
|
||||
: "memory" );
|
||||
|
||||
return swap_;
|
||||
}
|
||||
|
||||
inline int32_t atomic_fetch_and_add( int32_t * pw, int32_t dv )
|
||||
{
|
||||
// long r = *pw;
|
||||
// *pw += dv;
|
||||
// return r;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
int32_t r = *pw;
|
||||
|
||||
if( __builtin_expect((compare_and_swap(pw, r, r + dv) == r), 1) )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void atomic_increment( int32_t * pw )
|
||||
{
|
||||
atomic_fetch_and_add( pw, 1 );
|
||||
}
|
||||
|
||||
inline int32_t atomic_decrement( int32_t * pw )
|
||||
{
|
||||
return atomic_fetch_and_add( pw, -1 );
|
||||
}
|
||||
|
||||
inline int32_t atomic_conditional_increment( int32_t * pw )
|
||||
{
|
||||
// long r = *pw;
|
||||
// if( r != 0 ) ++*pw;
|
||||
// return r;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
int32_t r = *pw;
|
||||
|
||||
if( r == 0 )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
if( __builtin_expect( ( compare_and_swap( pw, r, r + 1 ) == r ), 1 ) )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class sp_counted_base
|
||||
{
|
||||
private:
|
||||
|
||||
sp_counted_base( sp_counted_base const & );
|
||||
sp_counted_base & operator= ( sp_counted_base const & );
|
||||
|
||||
int32_t use_count_; // #shared
|
||||
int32_t weak_count_; // #weak + (#shared != 0)
|
||||
|
||||
public:
|
||||
|
||||
sp_counted_base(): use_count_( 1 ), weak_count_( 1 )
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~sp_counted_base() // nothrow
|
||||
{
|
||||
}
|
||||
|
||||
// dispose() is called when use_count_ drops to zero, to release
|
||||
// the resources managed by *this.
|
||||
|
||||
virtual void dispose() = 0; // nothrow
|
||||
|
||||
// destroy() is called when weak_count_ drops to zero.
|
||||
|
||||
virtual void destroy() // nothrow
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
|
||||
virtual void * get_untyped_deleter() = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
{
|
||||
atomic_increment( &use_count_ );
|
||||
}
|
||||
|
||||
bool add_ref_lock() // true on success
|
||||
{
|
||||
return atomic_conditional_increment( &use_count_ ) != 0;
|
||||
}
|
||||
|
||||
void release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &use_count_ ) == 1 )
|
||||
{
|
||||
dispose();
|
||||
weak_release();
|
||||
}
|
||||
}
|
||||
|
||||
void weak_add_ref() // nothrow
|
||||
{
|
||||
atomic_increment( &weak_count_ );
|
||||
}
|
||||
|
||||
void weak_release() // nothrow
|
||||
{
|
||||
if( atomic_decrement( &weak_count_ ) == 1 )
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
long use_count() const // nothrow
|
||||
{
|
||||
return const_cast< int32_t const volatile & >( use_count_ );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_GCC_SPARC_HPP_INCLUDED
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_UNIQUE_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_UNIQUE_HPP_INCLUDED
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/range/detail/range_return.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range
|
||||
{
|
||||
|
||||
/// \brief template function unique
|
||||
///
|
||||
/// range-based version of the unique std algorithm
|
||||
///
|
||||
/// \pre Rng meets the requirements for a Forward range
|
||||
template< range_return_value re, class ForwardRange >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
|
||||
unique( ForwardRange& rng )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
|
||||
return range_return<ForwardRange,re>::
|
||||
pack( std::unique( boost::begin(rng),
|
||||
boost::end(rng)), rng );
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template< range_return_value re, class ForwardRange >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
|
||||
unique( const ForwardRange& rng )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
|
||||
return range_return<const ForwardRange,re>::
|
||||
pack( std::unique( boost::begin(rng),
|
||||
boost::end(rng)), rng );
|
||||
}
|
||||
/// \overload
|
||||
template< range_return_value re, class ForwardRange, class BinaryPredicate >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
|
||||
unique( ForwardRange& rng, BinaryPredicate pred )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
|
||||
return range_return<ForwardRange,re>::
|
||||
pack(std::unique(boost::begin(rng), boost::end(rng), pred),
|
||||
rng);
|
||||
}
|
||||
/// \overload
|
||||
template< range_return_value re, class ForwardRange, class BinaryPredicate >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
|
||||
unique( const ForwardRange& rng, BinaryPredicate pred )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
|
||||
return range_return<const ForwardRange,re>::
|
||||
pack(std::unique(boost::begin(rng), boost::end(rng), pred),
|
||||
rng);
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template< class ForwardRange >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
|
||||
unique( ForwardRange& rng )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
|
||||
return ::boost::range::unique<return_begin_found>(rng);
|
||||
}
|
||||
/// \overload
|
||||
template< class ForwardRange >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
|
||||
unique( const ForwardRange& rng )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
|
||||
return ::boost::range::unique<return_begin_found>(rng);
|
||||
}
|
||||
/// \overload
|
||||
template< class ForwardRange, class BinaryPredicate >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
|
||||
unique( ForwardRange& rng, BinaryPredicate pred )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
|
||||
return ::boost::range::unique<return_begin_found>(rng, pred);
|
||||
}
|
||||
/// \overload
|
||||
template< class ForwardRange, class BinaryPredicate >
|
||||
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
|
||||
unique( const ForwardRange& rng, BinaryPredicate pred )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
|
||||
return ::boost::range::unique<return_begin_found>(rng, pred);
|
||||
}
|
||||
|
||||
} // namespace range
|
||||
using range::unique;
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,141 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@ file
|
||||
/// Defines template_test_case_gen
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
|
||||
#define BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/detail/config.hpp>
|
||||
#include <boost/test/detail/global_typedef.hpp>
|
||||
#include <boost/test/detail/fwd_decl.hpp>
|
||||
#include <boost/test/detail/workaround.hpp>
|
||||
|
||||
#include <boost/test/utils/class_properties.hpp>
|
||||
|
||||
#include <boost/test/tree/observer.hpp>
|
||||
|
||||
|
||||
// Boost
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/type.hpp>
|
||||
#include <boost/type_traits/is_const.hpp>
|
||||
#include <boost/function/function0.hpp>
|
||||
|
||||
#if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
|
||||
# include <boost/current_function.hpp>
|
||||
#else
|
||||
# include <boost/core/demangle.hpp>
|
||||
#endif
|
||||
|
||||
// STL
|
||||
#include <string> // for std::string
|
||||
#include <list> // for std::list
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace ut_detail {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** test_case_template_invoker ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename TestCaseTemplate,typename TestType>
|
||||
class test_case_template_invoker {
|
||||
public:
|
||||
void operator()() { TestCaseTemplate::run( (boost::type<TestType>*)0 ); }
|
||||
};
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** generate_test_case_4_type ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename Generator,typename TestCaseTemplate>
|
||||
struct generate_test_case_4_type {
|
||||
explicit generate_test_case_4_type( const_string tc_name, const_string tc_file, std::size_t tc_line, Generator& G )
|
||||
: m_test_case_name( tc_name )
|
||||
, m_test_case_file( tc_file )
|
||||
, m_test_case_line( tc_line )
|
||||
, m_holder( G )
|
||||
{}
|
||||
|
||||
template<typename TestType>
|
||||
void operator()( mpl::identity<TestType> )
|
||||
{
|
||||
std::string full_name;
|
||||
assign_op( full_name, m_test_case_name, 0 );
|
||||
full_name += '<';
|
||||
#if !defined(BOOST_NO_TYPEID) && !defined(BOOST_NO_RTTI)
|
||||
full_name += boost::core::demangle(typeid(TestType).name()); // same as execution_monitor.ipp
|
||||
#else
|
||||
full_name += BOOST_CURRENT_FUNCTION;
|
||||
#endif
|
||||
if( boost::is_const<TestType>::value )
|
||||
full_name += "_const";
|
||||
full_name += '>';
|
||||
|
||||
m_holder.m_test_cases.push_back( new test_case( ut_detail::normalize_test_case_name( full_name ),
|
||||
m_test_case_file,
|
||||
m_test_case_line,
|
||||
test_case_template_invoker<TestCaseTemplate,TestType>() ) );
|
||||
}
|
||||
|
||||
private:
|
||||
// Data members
|
||||
const_string m_test_case_name;
|
||||
const_string m_test_case_file;
|
||||
std::size_t m_test_case_line;
|
||||
Generator& m_holder;
|
||||
};
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** test_case_template ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename TestCaseTemplate,typename TestTypesList>
|
||||
class template_test_case_gen : public test_unit_generator {
|
||||
public:
|
||||
// Constructor
|
||||
template_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line )
|
||||
{
|
||||
typedef generate_test_case_4_type<template_test_case_gen<TestCaseTemplate,TestTypesList>,TestCaseTemplate> single_test_gen;
|
||||
|
||||
mpl::for_each<TestTypesList,mpl::make_identity<mpl::_> >( single_test_gen( tc_name, tc_file, tc_line, *this ) );
|
||||
}
|
||||
|
||||
virtual test_unit* next() const
|
||||
{
|
||||
if( m_test_cases.empty() )
|
||||
return 0;
|
||||
|
||||
test_unit* res = m_test_cases.front();
|
||||
m_test_cases.pop_front();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// Data members
|
||||
mutable std::list<test_unit*> m_test_cases;
|
||||
};
|
||||
|
||||
} // namespace ut_detail
|
||||
} // unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_TREE_TEST_CASE_TEMPLATE_HPP_091911GER
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright David Abrahams 2002.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
#ifndef CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
# define CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
|
||||
namespace boost { namespace python { namespace converter {
|
||||
|
||||
// Declares the type of functions used to construct C++ objects for
|
||||
// rvalue from_python conversions.
|
||||
struct rvalue_from_python_stage1_data;
|
||||
typedef void (*constructor_function)(PyObject* source, rvalue_from_python_stage1_data*);
|
||||
|
||||
}}} // namespace boost::python::converter
|
||||
|
||||
#endif // CONSTRUCTOR_FUNCTION_DWA200278_HPP
|
||||
@@ -0,0 +1,14 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_ITERATOR_MPL_10022005_0557)
|
||||
#define FUSION_ITERATOR_MPL_10022005_0557
|
||||
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/iterator/mpl/convert_iterator.hpp>
|
||||
#include <boost/fusion/iterator/mpl/fusion_iterator.hpp>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,116 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief defines abstract interface for test observer
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_TEST_OBSERVER_HPP_021005GER
|
||||
#define BOOST_TEST_TEST_OBSERVER_HPP_021005GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/detail/fwd_decl.hpp>
|
||||
#include <boost/test/detail/global_typedef.hpp>
|
||||
#include <boost/test/detail/config.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** test_observer ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/// @brief Generic test observer interface
|
||||
///
|
||||
/// This interface is used by observers in order to receive notifications from the
|
||||
/// Boost.Test framework on the current execution state.
|
||||
///
|
||||
/// Several observers can be running at the same time, and it is not unusual to
|
||||
/// have interactions among them. The test_observer#priority member function allows the specification
|
||||
/// of a particular order among them (lowest priority executed first, except specified otherwise).
|
||||
///
|
||||
class BOOST_TEST_DECL test_observer {
|
||||
public:
|
||||
|
||||
//! Called before the framework starts executing the test cases
|
||||
//!
|
||||
//! @param[in] number_of_test_cases indicates the number of test cases. Only active
|
||||
//! test cases are taken into account.
|
||||
//!
|
||||
virtual void test_start( counter_t /* number_of_test_cases */ ) {}
|
||||
|
||||
|
||||
//! Called after the framework ends executing the test cases
|
||||
//!
|
||||
//! @note The call is made with a reversed priority order.
|
||||
virtual void test_finish() {}
|
||||
|
||||
//! Called when a critical error is detected
|
||||
//!
|
||||
//! The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework.
|
||||
//! Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining
|
||||
//! tests are discarded.
|
||||
//!
|
||||
//! @note may be called before test_observer::test_unit_finish()
|
||||
virtual void test_aborted() {}
|
||||
|
||||
//! Called before the framework starts executing a test unit
|
||||
//!
|
||||
//! @param[in] test_unit the test being executed
|
||||
virtual void test_unit_start( test_unit const& /* test */) {}
|
||||
|
||||
//! Called at each end of a test unit.
|
||||
//!
|
||||
//! @param elapsed duration of the test unit in microseconds.
|
||||
virtual void test_unit_finish( test_unit const& /* test */, unsigned long /* elapsed */ ) {}
|
||||
virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); }
|
||||
virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility
|
||||
|
||||
//! Called when a test unit indicates a fatal error.
|
||||
//!
|
||||
//! A fatal error happens when
|
||||
//! - a strong assertion (with @c REQUIRE) fails, which indicates that the test case cannot continue
|
||||
//! - an unexpected exception is caught by the Boost.Test framework
|
||||
virtual void test_unit_aborted( test_unit const& ) {}
|
||||
|
||||
virtual void assertion_result( unit_test::assertion_result ar )
|
||||
{
|
||||
switch( ar ) {
|
||||
case AR_PASSED: assertion_result( true ); break;
|
||||
case AR_FAILED: assertion_result( false ); break;
|
||||
case AR_TRIGGERED: break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
//! Called when an exception is intercepted
|
||||
//!
|
||||
//! In case an exception is intercepted, this call happens before the call
|
||||
//! to @ref test_unit_aborted in order to log
|
||||
//! additional data about the exception.
|
||||
virtual void exception_caught( execution_exception const& ) {}
|
||||
|
||||
virtual int priority() { return 0; }
|
||||
|
||||
protected:
|
||||
//! Deprecated
|
||||
virtual void assertion_result( bool /* passed */ ) {}
|
||||
|
||||
BOOST_TEST_PROTECTED_VIRTUAL ~test_observer() {}
|
||||
};
|
||||
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_TEST_OBSERVER_HPP_021005GER
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
# /* Copyright (C) 2001
|
||||
# * Housemarque Oy
|
||||
# * http://www.housemarque.com
|
||||
# *
|
||||
# * Distributed under the Boost Software License, Version 1.0. (See
|
||||
# * accompanying file LICENSE_1_0.txt or copy at
|
||||
# * http://www.boost.org/LICENSE_1_0.txt)
|
||||
# */
|
||||
#
|
||||
# /* Revised by Paul Mensonides (2002) */
|
||||
#
|
||||
# /* See http://www.boost.org for most recent version. */
|
||||
#
|
||||
# ifndef BOOST_PREPROCESSOR_ARITHMETIC_DEC_HPP
|
||||
# define BOOST_PREPROCESSOR_ARITHMETIC_DEC_HPP
|
||||
#
|
||||
# include <boost/preprocessor/config/config.hpp>
|
||||
#
|
||||
# /* BOOST_PP_DEC */
|
||||
#
|
||||
# if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MWCC()
|
||||
# define BOOST_PP_DEC(x) BOOST_PP_DEC_I(x)
|
||||
# else
|
||||
# define BOOST_PP_DEC(x) BOOST_PP_DEC_OO((x))
|
||||
# define BOOST_PP_DEC_OO(par) BOOST_PP_DEC_I ## par
|
||||
# endif
|
||||
#
|
||||
# define BOOST_PP_DEC_I(x) BOOST_PP_DEC_ ## x
|
||||
#
|
||||
# define BOOST_PP_DEC_0 0
|
||||
# define BOOST_PP_DEC_1 0
|
||||
# define BOOST_PP_DEC_2 1
|
||||
# define BOOST_PP_DEC_3 2
|
||||
# define BOOST_PP_DEC_4 3
|
||||
# define BOOST_PP_DEC_5 4
|
||||
# define BOOST_PP_DEC_6 5
|
||||
# define BOOST_PP_DEC_7 6
|
||||
# define BOOST_PP_DEC_8 7
|
||||
# define BOOST_PP_DEC_9 8
|
||||
# define BOOST_PP_DEC_10 9
|
||||
# define BOOST_PP_DEC_11 10
|
||||
# define BOOST_PP_DEC_12 11
|
||||
# define BOOST_PP_DEC_13 12
|
||||
# define BOOST_PP_DEC_14 13
|
||||
# define BOOST_PP_DEC_15 14
|
||||
# define BOOST_PP_DEC_16 15
|
||||
# define BOOST_PP_DEC_17 16
|
||||
# define BOOST_PP_DEC_18 17
|
||||
# define BOOST_PP_DEC_19 18
|
||||
# define BOOST_PP_DEC_20 19
|
||||
# define BOOST_PP_DEC_21 20
|
||||
# define BOOST_PP_DEC_22 21
|
||||
# define BOOST_PP_DEC_23 22
|
||||
# define BOOST_PP_DEC_24 23
|
||||
# define BOOST_PP_DEC_25 24
|
||||
# define BOOST_PP_DEC_26 25
|
||||
# define BOOST_PP_DEC_27 26
|
||||
# define BOOST_PP_DEC_28 27
|
||||
# define BOOST_PP_DEC_29 28
|
||||
# define BOOST_PP_DEC_30 29
|
||||
# define BOOST_PP_DEC_31 30
|
||||
# define BOOST_PP_DEC_32 31
|
||||
# define BOOST_PP_DEC_33 32
|
||||
# define BOOST_PP_DEC_34 33
|
||||
# define BOOST_PP_DEC_35 34
|
||||
# define BOOST_PP_DEC_36 35
|
||||
# define BOOST_PP_DEC_37 36
|
||||
# define BOOST_PP_DEC_38 37
|
||||
# define BOOST_PP_DEC_39 38
|
||||
# define BOOST_PP_DEC_40 39
|
||||
# define BOOST_PP_DEC_41 40
|
||||
# define BOOST_PP_DEC_42 41
|
||||
# define BOOST_PP_DEC_43 42
|
||||
# define BOOST_PP_DEC_44 43
|
||||
# define BOOST_PP_DEC_45 44
|
||||
# define BOOST_PP_DEC_46 45
|
||||
# define BOOST_PP_DEC_47 46
|
||||
# define BOOST_PP_DEC_48 47
|
||||
# define BOOST_PP_DEC_49 48
|
||||
# define BOOST_PP_DEC_50 49
|
||||
# define BOOST_PP_DEC_51 50
|
||||
# define BOOST_PP_DEC_52 51
|
||||
# define BOOST_PP_DEC_53 52
|
||||
# define BOOST_PP_DEC_54 53
|
||||
# define BOOST_PP_DEC_55 54
|
||||
# define BOOST_PP_DEC_56 55
|
||||
# define BOOST_PP_DEC_57 56
|
||||
# define BOOST_PP_DEC_58 57
|
||||
# define BOOST_PP_DEC_59 58
|
||||
# define BOOST_PP_DEC_60 59
|
||||
# define BOOST_PP_DEC_61 60
|
||||
# define BOOST_PP_DEC_62 61
|
||||
# define BOOST_PP_DEC_63 62
|
||||
# define BOOST_PP_DEC_64 63
|
||||
# define BOOST_PP_DEC_65 64
|
||||
# define BOOST_PP_DEC_66 65
|
||||
# define BOOST_PP_DEC_67 66
|
||||
# define BOOST_PP_DEC_68 67
|
||||
# define BOOST_PP_DEC_69 68
|
||||
# define BOOST_PP_DEC_70 69
|
||||
# define BOOST_PP_DEC_71 70
|
||||
# define BOOST_PP_DEC_72 71
|
||||
# define BOOST_PP_DEC_73 72
|
||||
# define BOOST_PP_DEC_74 73
|
||||
# define BOOST_PP_DEC_75 74
|
||||
# define BOOST_PP_DEC_76 75
|
||||
# define BOOST_PP_DEC_77 76
|
||||
# define BOOST_PP_DEC_78 77
|
||||
# define BOOST_PP_DEC_79 78
|
||||
# define BOOST_PP_DEC_80 79
|
||||
# define BOOST_PP_DEC_81 80
|
||||
# define BOOST_PP_DEC_82 81
|
||||
# define BOOST_PP_DEC_83 82
|
||||
# define BOOST_PP_DEC_84 83
|
||||
# define BOOST_PP_DEC_85 84
|
||||
# define BOOST_PP_DEC_86 85
|
||||
# define BOOST_PP_DEC_87 86
|
||||
# define BOOST_PP_DEC_88 87
|
||||
# define BOOST_PP_DEC_89 88
|
||||
# define BOOST_PP_DEC_90 89
|
||||
# define BOOST_PP_DEC_91 90
|
||||
# define BOOST_PP_DEC_92 91
|
||||
# define BOOST_PP_DEC_93 92
|
||||
# define BOOST_PP_DEC_94 93
|
||||
# define BOOST_PP_DEC_95 94
|
||||
# define BOOST_PP_DEC_96 95
|
||||
# define BOOST_PP_DEC_97 96
|
||||
# define BOOST_PP_DEC_98 97
|
||||
# define BOOST_PP_DEC_99 98
|
||||
# define BOOST_PP_DEC_100 99
|
||||
# define BOOST_PP_DEC_101 100
|
||||
# define BOOST_PP_DEC_102 101
|
||||
# define BOOST_PP_DEC_103 102
|
||||
# define BOOST_PP_DEC_104 103
|
||||
# define BOOST_PP_DEC_105 104
|
||||
# define BOOST_PP_DEC_106 105
|
||||
# define BOOST_PP_DEC_107 106
|
||||
# define BOOST_PP_DEC_108 107
|
||||
# define BOOST_PP_DEC_109 108
|
||||
# define BOOST_PP_DEC_110 109
|
||||
# define BOOST_PP_DEC_111 110
|
||||
# define BOOST_PP_DEC_112 111
|
||||
# define BOOST_PP_DEC_113 112
|
||||
# define BOOST_PP_DEC_114 113
|
||||
# define BOOST_PP_DEC_115 114
|
||||
# define BOOST_PP_DEC_116 115
|
||||
# define BOOST_PP_DEC_117 116
|
||||
# define BOOST_PP_DEC_118 117
|
||||
# define BOOST_PP_DEC_119 118
|
||||
# define BOOST_PP_DEC_120 119
|
||||
# define BOOST_PP_DEC_121 120
|
||||
# define BOOST_PP_DEC_122 121
|
||||
# define BOOST_PP_DEC_123 122
|
||||
# define BOOST_PP_DEC_124 123
|
||||
# define BOOST_PP_DEC_125 124
|
||||
# define BOOST_PP_DEC_126 125
|
||||
# define BOOST_PP_DEC_127 126
|
||||
# define BOOST_PP_DEC_128 127
|
||||
# define BOOST_PP_DEC_129 128
|
||||
# define BOOST_PP_DEC_130 129
|
||||
# define BOOST_PP_DEC_131 130
|
||||
# define BOOST_PP_DEC_132 131
|
||||
# define BOOST_PP_DEC_133 132
|
||||
# define BOOST_PP_DEC_134 133
|
||||
# define BOOST_PP_DEC_135 134
|
||||
# define BOOST_PP_DEC_136 135
|
||||
# define BOOST_PP_DEC_137 136
|
||||
# define BOOST_PP_DEC_138 137
|
||||
# define BOOST_PP_DEC_139 138
|
||||
# define BOOST_PP_DEC_140 139
|
||||
# define BOOST_PP_DEC_141 140
|
||||
# define BOOST_PP_DEC_142 141
|
||||
# define BOOST_PP_DEC_143 142
|
||||
# define BOOST_PP_DEC_144 143
|
||||
# define BOOST_PP_DEC_145 144
|
||||
# define BOOST_PP_DEC_146 145
|
||||
# define BOOST_PP_DEC_147 146
|
||||
# define BOOST_PP_DEC_148 147
|
||||
# define BOOST_PP_DEC_149 148
|
||||
# define BOOST_PP_DEC_150 149
|
||||
# define BOOST_PP_DEC_151 150
|
||||
# define BOOST_PP_DEC_152 151
|
||||
# define BOOST_PP_DEC_153 152
|
||||
# define BOOST_PP_DEC_154 153
|
||||
# define BOOST_PP_DEC_155 154
|
||||
# define BOOST_PP_DEC_156 155
|
||||
# define BOOST_PP_DEC_157 156
|
||||
# define BOOST_PP_DEC_158 157
|
||||
# define BOOST_PP_DEC_159 158
|
||||
# define BOOST_PP_DEC_160 159
|
||||
# define BOOST_PP_DEC_161 160
|
||||
# define BOOST_PP_DEC_162 161
|
||||
# define BOOST_PP_DEC_163 162
|
||||
# define BOOST_PP_DEC_164 163
|
||||
# define BOOST_PP_DEC_165 164
|
||||
# define BOOST_PP_DEC_166 165
|
||||
# define BOOST_PP_DEC_167 166
|
||||
# define BOOST_PP_DEC_168 167
|
||||
# define BOOST_PP_DEC_169 168
|
||||
# define BOOST_PP_DEC_170 169
|
||||
# define BOOST_PP_DEC_171 170
|
||||
# define BOOST_PP_DEC_172 171
|
||||
# define BOOST_PP_DEC_173 172
|
||||
# define BOOST_PP_DEC_174 173
|
||||
# define BOOST_PP_DEC_175 174
|
||||
# define BOOST_PP_DEC_176 175
|
||||
# define BOOST_PP_DEC_177 176
|
||||
# define BOOST_PP_DEC_178 177
|
||||
# define BOOST_PP_DEC_179 178
|
||||
# define BOOST_PP_DEC_180 179
|
||||
# define BOOST_PP_DEC_181 180
|
||||
# define BOOST_PP_DEC_182 181
|
||||
# define BOOST_PP_DEC_183 182
|
||||
# define BOOST_PP_DEC_184 183
|
||||
# define BOOST_PP_DEC_185 184
|
||||
# define BOOST_PP_DEC_186 185
|
||||
# define BOOST_PP_DEC_187 186
|
||||
# define BOOST_PP_DEC_188 187
|
||||
# define BOOST_PP_DEC_189 188
|
||||
# define BOOST_PP_DEC_190 189
|
||||
# define BOOST_PP_DEC_191 190
|
||||
# define BOOST_PP_DEC_192 191
|
||||
# define BOOST_PP_DEC_193 192
|
||||
# define BOOST_PP_DEC_194 193
|
||||
# define BOOST_PP_DEC_195 194
|
||||
# define BOOST_PP_DEC_196 195
|
||||
# define BOOST_PP_DEC_197 196
|
||||
# define BOOST_PP_DEC_198 197
|
||||
# define BOOST_PP_DEC_199 198
|
||||
# define BOOST_PP_DEC_200 199
|
||||
# define BOOST_PP_DEC_201 200
|
||||
# define BOOST_PP_DEC_202 201
|
||||
# define BOOST_PP_DEC_203 202
|
||||
# define BOOST_PP_DEC_204 203
|
||||
# define BOOST_PP_DEC_205 204
|
||||
# define BOOST_PP_DEC_206 205
|
||||
# define BOOST_PP_DEC_207 206
|
||||
# define BOOST_PP_DEC_208 207
|
||||
# define BOOST_PP_DEC_209 208
|
||||
# define BOOST_PP_DEC_210 209
|
||||
# define BOOST_PP_DEC_211 210
|
||||
# define BOOST_PP_DEC_212 211
|
||||
# define BOOST_PP_DEC_213 212
|
||||
# define BOOST_PP_DEC_214 213
|
||||
# define BOOST_PP_DEC_215 214
|
||||
# define BOOST_PP_DEC_216 215
|
||||
# define BOOST_PP_DEC_217 216
|
||||
# define BOOST_PP_DEC_218 217
|
||||
# define BOOST_PP_DEC_219 218
|
||||
# define BOOST_PP_DEC_220 219
|
||||
# define BOOST_PP_DEC_221 220
|
||||
# define BOOST_PP_DEC_222 221
|
||||
# define BOOST_PP_DEC_223 222
|
||||
# define BOOST_PP_DEC_224 223
|
||||
# define BOOST_PP_DEC_225 224
|
||||
# define BOOST_PP_DEC_226 225
|
||||
# define BOOST_PP_DEC_227 226
|
||||
# define BOOST_PP_DEC_228 227
|
||||
# define BOOST_PP_DEC_229 228
|
||||
# define BOOST_PP_DEC_230 229
|
||||
# define BOOST_PP_DEC_231 230
|
||||
# define BOOST_PP_DEC_232 231
|
||||
# define BOOST_PP_DEC_233 232
|
||||
# define BOOST_PP_DEC_234 233
|
||||
# define BOOST_PP_DEC_235 234
|
||||
# define BOOST_PP_DEC_236 235
|
||||
# define BOOST_PP_DEC_237 236
|
||||
# define BOOST_PP_DEC_238 237
|
||||
# define BOOST_PP_DEC_239 238
|
||||
# define BOOST_PP_DEC_240 239
|
||||
# define BOOST_PP_DEC_241 240
|
||||
# define BOOST_PP_DEC_242 241
|
||||
# define BOOST_PP_DEC_243 242
|
||||
# define BOOST_PP_DEC_244 243
|
||||
# define BOOST_PP_DEC_245 244
|
||||
# define BOOST_PP_DEC_246 245
|
||||
# define BOOST_PP_DEC_247 246
|
||||
# define BOOST_PP_DEC_248 247
|
||||
# define BOOST_PP_DEC_249 248
|
||||
# define BOOST_PP_DEC_250 249
|
||||
# define BOOST_PP_DEC_251 250
|
||||
# define BOOST_PP_DEC_252 251
|
||||
# define BOOST_PP_DEC_253 252
|
||||
# define BOOST_PP_DEC_254 253
|
||||
# define BOOST_PP_DEC_255 254
|
||||
# define BOOST_PP_DEC_256 255
|
||||
# define BOOST_PP_DEC_257 256
|
||||
#
|
||||
# endif
|
||||
@@ -0,0 +1,317 @@
|
||||
//
|
||||
// Copyright (c) 2009
|
||||
// Gunter Winkler
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef _BOOST_UBLAS_SPARSE_VIEW_
|
||||
#define _BOOST_UBLAS_SPARSE_VIEW_
|
||||
|
||||
#include <boost/numeric/ublas/matrix_expression.hpp>
|
||||
#include <boost/numeric/ublas/detail/matrix_assign.hpp>
|
||||
#if BOOST_UBLAS_TYPE_CHECK
|
||||
#include <boost/numeric/ublas/matrix.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/numeric/ublas/storage.hpp>
|
||||
|
||||
namespace boost { namespace numeric { namespace ublas {
|
||||
|
||||
// view a chunk of memory as ublas array
|
||||
|
||||
template < class T >
|
||||
class c_array_view
|
||||
: public storage_array< c_array_view<T> > {
|
||||
private:
|
||||
typedef c_array_view<T> self_type;
|
||||
typedef T * pointer;
|
||||
|
||||
public:
|
||||
// TODO: think about a const pointer
|
||||
typedef const pointer array_type;
|
||||
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
typedef T value_type;
|
||||
typedef const T &const_reference;
|
||||
typedef const T *const_pointer;
|
||||
|
||||
typedef const_pointer const_iterator;
|
||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
//
|
||||
// typedefs required by vector concept
|
||||
//
|
||||
|
||||
typedef dense_tag storage_category;
|
||||
typedef const vector_reference<const self_type> const_closure_type;
|
||||
|
||||
c_array_view(size_type size, array_type data) :
|
||||
size_(size), data_(data)
|
||||
{}
|
||||
|
||||
~c_array_view()
|
||||
{}
|
||||
|
||||
//
|
||||
// immutable methods of container concept
|
||||
//
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
size_type size () const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
const_reference operator [] (size_type i) const {
|
||||
BOOST_UBLAS_CHECK (i < size_, bad_index ());
|
||||
return data_ [i];
|
||||
}
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
const_iterator begin () const {
|
||||
return data_;
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
const_iterator end () const {
|
||||
return data_ + size_;
|
||||
}
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
const_reverse_iterator rbegin () const {
|
||||
return const_reverse_iterator (end ());
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
const_reverse_iterator rend () const {
|
||||
return const_reverse_iterator (begin ());
|
||||
}
|
||||
|
||||
private:
|
||||
size_type size_;
|
||||
array_type data_;
|
||||
};
|
||||
|
||||
|
||||
/** \brief Present existing arrays as compressed array based
|
||||
* sparse matrix.
|
||||
* This class provides CRS / CCS storage layout.
|
||||
*
|
||||
* see also http://www.netlib.org/utk/papers/templates/node90.html
|
||||
*
|
||||
* \param L layout type, either row_major or column_major
|
||||
* \param IB index base, use 0 for C indexing and 1 for
|
||||
* FORTRAN indexing of the internal index arrays. This
|
||||
* does not affect the operator()(int,int) where the first
|
||||
* row/column has always index 0.
|
||||
* \param IA index array type, e.g., int[]
|
||||
* \param TA value array type, e.g., double[]
|
||||
*/
|
||||
template<class L, std::size_t IB, class IA, class JA, class TA>
|
||||
class compressed_matrix_view:
|
||||
public matrix_expression<compressed_matrix_view<L, IB, IA, JA, TA> > {
|
||||
|
||||
public:
|
||||
typedef typename vector_view_traits<TA>::value_type value_type;
|
||||
|
||||
private:
|
||||
typedef value_type &true_reference;
|
||||
typedef value_type *pointer;
|
||||
typedef const value_type *const_pointer;
|
||||
typedef L layout_type;
|
||||
typedef compressed_matrix_view<L, IB, IA, JA, TA> self_type;
|
||||
|
||||
public:
|
||||
#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
||||
using matrix_expression<self_type>::operator ();
|
||||
#endif
|
||||
// ISSUE require type consistency check
|
||||
// is_convertable (IA::size_type, TA::size_type)
|
||||
typedef typename boost::remove_cv<typename vector_view_traits<JA>::value_type>::type index_type;
|
||||
// for compatibility, should be removed some day ...
|
||||
typedef index_type size_type;
|
||||
// size_type for the data arrays.
|
||||
typedef typename vector_view_traits<JA>::size_type array_size_type;
|
||||
typedef typename vector_view_traits<JA>::difference_type difference_type;
|
||||
typedef const value_type & const_reference;
|
||||
|
||||
// do NOT define reference type, because class is read only
|
||||
// typedef value_type & reference;
|
||||
|
||||
typedef IA rowptr_array_type;
|
||||
typedef JA index_array_type;
|
||||
typedef TA value_array_type;
|
||||
typedef const matrix_reference<const self_type> const_closure_type;
|
||||
typedef matrix_reference<self_type> closure_type;
|
||||
|
||||
// FIXME: define a corresponding temporary type
|
||||
// typedef compressed_vector<T, IB, IA, TA> vector_temporary_type;
|
||||
|
||||
// FIXME: define a corresponding temporary type
|
||||
// typedef self_type matrix_temporary_type;
|
||||
|
||||
typedef sparse_tag storage_category;
|
||||
typedef typename L::orientation_category orientation_category;
|
||||
|
||||
//
|
||||
// private types for internal use
|
||||
//
|
||||
|
||||
private:
|
||||
typedef typename vector_view_traits<index_array_type>::const_iterator const_subiterator_type;
|
||||
|
||||
//
|
||||
// Construction and destruction
|
||||
//
|
||||
private:
|
||||
/// private default constructor because data must be filled by caller
|
||||
BOOST_UBLAS_INLINE
|
||||
compressed_matrix_view () { }
|
||||
|
||||
public:
|
||||
BOOST_UBLAS_INLINE
|
||||
compressed_matrix_view (index_type n_rows, index_type n_cols, array_size_type nnz
|
||||
, const rowptr_array_type & iptr
|
||||
, const index_array_type & jptr
|
||||
, const value_array_type & values):
|
||||
matrix_expression<self_type> (),
|
||||
size1_ (n_rows), size2_ (n_cols),
|
||||
nnz_ (nnz),
|
||||
index1_data_ (iptr),
|
||||
index2_data_ (jptr),
|
||||
value_data_ (values) {
|
||||
storage_invariants ();
|
||||
}
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
compressed_matrix_view(const compressed_matrix_view& o) :
|
||||
size1_(o.size1_), size2_(o.size2_),
|
||||
nnz_(o.nnz_),
|
||||
index1_data_(o.index1_data_),
|
||||
index2_data_(o.index2_data_),
|
||||
value_data_(o.value_data_)
|
||||
{}
|
||||
|
||||
//
|
||||
// implement immutable iterator types
|
||||
//
|
||||
|
||||
class const_iterator1 {};
|
||||
class const_iterator2 {};
|
||||
|
||||
typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
|
||||
typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
|
||||
|
||||
//
|
||||
// implement all read only methods for the matrix expression concept
|
||||
//
|
||||
|
||||
//! return the number of rows
|
||||
index_type size1() const {
|
||||
return size1_;
|
||||
}
|
||||
|
||||
//! return the number of columns
|
||||
index_type size2() const {
|
||||
return size2_;
|
||||
}
|
||||
|
||||
//! return value at position (i,j)
|
||||
value_type operator()(index_type i, index_type j) const {
|
||||
const_pointer p = find_element(i,j);
|
||||
if (!p) {
|
||||
return zero_;
|
||||
} else {
|
||||
return *p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
//
|
||||
// private helper functions
|
||||
//
|
||||
|
||||
const_pointer find_element (index_type i, index_type j) const {
|
||||
index_type element1 (layout_type::index_M (i, j));
|
||||
index_type element2 (layout_type::index_m (i, j));
|
||||
|
||||
const array_size_type itv = zero_based( index1_data_[element1] );
|
||||
const array_size_type itv_next = zero_based( index1_data_[element1+1] );
|
||||
|
||||
const_subiterator_type it_start = boost::next(vector_view_traits<index_array_type>::begin(index2_data_),itv);
|
||||
const_subiterator_type it_end = boost::next(vector_view_traits<index_array_type>::begin(index2_data_),itv_next);
|
||||
const_subiterator_type it = find_index_in_row(it_start, it_end, element2) ;
|
||||
|
||||
if (it == it_end || *it != k_based (element2))
|
||||
return 0;
|
||||
return &value_data_ [it - vector_view_traits<index_array_type>::begin(index2_data_)];
|
||||
}
|
||||
|
||||
const_subiterator_type find_index_in_row(const_subiterator_type it_start
|
||||
, const_subiterator_type it_end
|
||||
, index_type index) const {
|
||||
return std::lower_bound( it_start
|
||||
, it_end
|
||||
, k_based (index) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void storage_invariants () const {
|
||||
BOOST_UBLAS_CHECK (index1_data_ [layout_type::size_M (size1_, size2_)] == k_based (nnz_), external_logic ());
|
||||
}
|
||||
|
||||
index_type size1_;
|
||||
index_type size2_;
|
||||
|
||||
array_size_type nnz_;
|
||||
|
||||
const rowptr_array_type & index1_data_;
|
||||
const index_array_type & index2_data_;
|
||||
const value_array_type & value_data_;
|
||||
|
||||
static const value_type zero_;
|
||||
|
||||
BOOST_UBLAS_INLINE
|
||||
static index_type zero_based (index_type k_based_index) {
|
||||
return k_based_index - IB;
|
||||
}
|
||||
BOOST_UBLAS_INLINE
|
||||
static index_type k_based (index_type zero_based_index) {
|
||||
return zero_based_index + IB;
|
||||
}
|
||||
|
||||
friend class iterator1;
|
||||
friend class iterator2;
|
||||
friend class const_iterator1;
|
||||
friend class const_iterator2;
|
||||
};
|
||||
|
||||
template<class L, std::size_t IB, class IA, class JA, class TA >
|
||||
const typename compressed_matrix_view<L,IB,IA,JA,TA>::value_type
|
||||
compressed_matrix_view<L,IB,IA,JA,TA>::zero_ = value_type/*zero*/();
|
||||
|
||||
|
||||
template<class L, std::size_t IB, class IA, class JA, class TA >
|
||||
compressed_matrix_view<L,IB,IA,JA,TA>
|
||||
make_compressed_matrix_view(typename vector_view_traits<JA>::value_type n_rows
|
||||
, typename vector_view_traits<JA>::value_type n_cols
|
||||
, typename vector_view_traits<JA>::size_type nnz
|
||||
, const IA & ia
|
||||
, const JA & ja
|
||||
, const TA & ta) {
|
||||
|
||||
return compressed_matrix_view<L,IB,IA,JA,TA>(n_rows, n_cols, nnz, ia, ja, ta);
|
||||
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#if !defined(FUSION_ITERATOR_10022005_0559)
|
||||
#define FUSION_ITERATOR_10022005_0559
|
||||
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/fusion/iterator/iterator_facade.hpp>
|
||||
#include <boost/fusion/iterator/iterator_adapter.hpp>
|
||||
#include <boost/fusion/iterator/segmented_iterator.hpp>
|
||||
#include <boost/fusion/iterator/advance.hpp>
|
||||
#include <boost/fusion/iterator/deref.hpp>
|
||||
#include <boost/fusion/iterator/distance.hpp>
|
||||
#include <boost/fusion/iterator/equal_to.hpp>
|
||||
#include <boost/fusion/iterator/mpl.hpp>
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/iterator/prior.hpp>
|
||||
#include <boost/fusion/iterator/value_of.hpp>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,728 @@
|
||||
// boost\math\distributions\binomial.hpp
|
||||
|
||||
// Copyright John Maddock 2006.
|
||||
// Copyright Paul A. Bristow 2007.
|
||||
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt
|
||||
// or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// http://en.wikipedia.org/wiki/binomial_distribution
|
||||
|
||||
// Binomial distribution is the discrete probability distribution of
|
||||
// the number (k) of successes, in a sequence of
|
||||
// n independent (yes or no, success or failure) Bernoulli trials.
|
||||
|
||||
// It expresses the probability of a number of events occurring in a fixed time
|
||||
// if these events occur with a known average rate (probability of success),
|
||||
// and are independent of the time since the last event.
|
||||
|
||||
// The number of cars that pass through a certain point on a road during a given period of time.
|
||||
// The number of spelling mistakes a secretary makes while typing a single page.
|
||||
// The number of phone calls at a call center per minute.
|
||||
// The number of times a web server is accessed per minute.
|
||||
// The number of light bulbs that burn out in a certain amount of time.
|
||||
// The number of roadkill found per unit length of road
|
||||
|
||||
// http://en.wikipedia.org/wiki/binomial_distribution
|
||||
|
||||
// Given a sample of N measured values k[i],
|
||||
// we wish to estimate the value of the parameter x (mean)
|
||||
// of the binomial population from which the sample was drawn.
|
||||
// To calculate the maximum likelihood value = 1/N sum i = 1 to N of k[i]
|
||||
|
||||
// Also may want a function for EXACTLY k.
|
||||
|
||||
// And probability that there are EXACTLY k occurrences is
|
||||
// exp(-x) * pow(x, k) / factorial(k)
|
||||
// where x is expected occurrences (mean) during the given interval.
|
||||
// For example, if events occur, on average, every 4 min,
|
||||
// and we are interested in number of events occurring in 10 min,
|
||||
// then x = 10/4 = 2.5
|
||||
|
||||
// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366i.htm
|
||||
|
||||
// The binomial distribution is used when there are
|
||||
// exactly two mutually exclusive outcomes of a trial.
|
||||
// These outcomes are appropriately labeled "success" and "failure".
|
||||
// The binomial distribution is used to obtain
|
||||
// the probability of observing x successes in N trials,
|
||||
// with the probability of success on a single trial denoted by p.
|
||||
// The binomial distribution assumes that p is fixed for all trials.
|
||||
|
||||
// P(x, p, n) = n!/(x! * (n-x)!) * p^x * (1-p)^(n-x)
|
||||
|
||||
// http://mathworld.wolfram.com/BinomialCoefficient.html
|
||||
|
||||
// The binomial coefficient (n; k) is the number of ways of picking
|
||||
// k unordered outcomes from n possibilities,
|
||||
// also known as a combination or combinatorial number.
|
||||
// The symbols _nC_k and (n; k) are used to denote a binomial coefficient,
|
||||
// and are sometimes read as "n choose k."
|
||||
// (n; k) therefore gives the number of k-subsets possible out of a set of n distinct items.
|
||||
|
||||
// For example:
|
||||
// The 2-subsets of {1,2,3,4} are the six pairs {1,2}, {1,3}, {1,4}, {2,3}, {2,4}, and {3,4}, so (4; 2)==6.
|
||||
|
||||
// http://functions.wolfram.com/GammaBetaErf/Binomial/ for evaluation.
|
||||
|
||||
// But note that the binomial distribution
|
||||
// (like others including the poisson, negative binomial & Bernoulli)
|
||||
// is strictly defined as a discrete function: only integral values of k are envisaged.
|
||||
// However because of the method of calculation using a continuous gamma function,
|
||||
// it is convenient to treat it as if a continous function,
|
||||
// and permit non-integral values of k.
|
||||
// To enforce the strict mathematical model, users should use floor or ceil functions
|
||||
// on k outside this function to ensure that k is integral.
|
||||
|
||||
#ifndef BOOST_MATH_SPECIAL_BINOMIAL_HPP
|
||||
#define BOOST_MATH_SPECIAL_BINOMIAL_HPP
|
||||
|
||||
#include <boost/math/distributions/fwd.hpp>
|
||||
#include <boost/math/special_functions/beta.hpp> // for incomplete beta.
|
||||
#include <boost/math/distributions/complement.hpp> // complements
|
||||
#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
|
||||
#include <boost/math/distributions/detail/inv_discrete_quantile.hpp> // error checks
|
||||
#include <boost/math/special_functions/fpclassify.hpp> // isnan.
|
||||
#include <boost/math/tools/roots.hpp> // for root finding.
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace math
|
||||
{
|
||||
|
||||
template <class RealType, class Policy>
|
||||
class binomial_distribution;
|
||||
|
||||
namespace binomial_detail{
|
||||
// common error checking routines for binomial distribution functions:
|
||||
template <class RealType, class Policy>
|
||||
inline bool check_N(const char* function, const RealType& N, RealType* result, const Policy& pol)
|
||||
{
|
||||
if((N < 0) || !(boost::math::isfinite)(N))
|
||||
{
|
||||
*result = policies::raise_domain_error<RealType>(
|
||||
function,
|
||||
"Number of Trials argument is %1%, but must be >= 0 !", N, pol);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template <class RealType, class Policy>
|
||||
inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& pol)
|
||||
{
|
||||
if((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
|
||||
{
|
||||
*result = policies::raise_domain_error<RealType>(
|
||||
function,
|
||||
"Success fraction argument is %1%, but must be >= 0 and <= 1 !", p, pol);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template <class RealType, class Policy>
|
||||
inline bool check_dist(const char* function, const RealType& N, const RealType& p, RealType* result, const Policy& pol)
|
||||
{
|
||||
return check_success_fraction(
|
||||
function, p, result, pol)
|
||||
&& check_N(
|
||||
function, N, result, pol);
|
||||
}
|
||||
template <class RealType, class Policy>
|
||||
inline bool check_dist_and_k(const char* function, const RealType& N, const RealType& p, RealType k, RealType* result, const Policy& pol)
|
||||
{
|
||||
if(check_dist(function, N, p, result, pol) == false)
|
||||
return false;
|
||||
if((k < 0) || !(boost::math::isfinite)(k))
|
||||
{
|
||||
*result = policies::raise_domain_error<RealType>(
|
||||
function,
|
||||
"Number of Successes argument is %1%, but must be >= 0 !", k, pol);
|
||||
return false;
|
||||
}
|
||||
if(k > N)
|
||||
{
|
||||
*result = policies::raise_domain_error<RealType>(
|
||||
function,
|
||||
"Number of Successes argument is %1%, but must be <= Number of Trials !", k, pol);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
template <class RealType, class Policy>
|
||||
inline bool check_dist_and_prob(const char* function, const RealType& N, RealType p, RealType prob, RealType* result, const Policy& pol)
|
||||
{
|
||||
if((check_dist(function, N, p, result, pol) && detail::check_probability(function, prob, result, pol)) == false)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
T inverse_binomial_cornish_fisher(T n, T sf, T p, T q, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
// mean:
|
||||
T m = n * sf;
|
||||
// standard deviation:
|
||||
T sigma = sqrt(n * sf * (1 - sf));
|
||||
// skewness
|
||||
T sk = (1 - 2 * sf) / sigma;
|
||||
// kurtosis:
|
||||
// T k = (1 - 6 * sf * (1 - sf) ) / (n * sf * (1 - sf));
|
||||
// Get the inverse of a std normal distribution:
|
||||
T x = boost::math::erfc_inv(p > q ? 2 * q : 2 * p, pol) * constants::root_two<T>();
|
||||
// Set the sign:
|
||||
if(p < 0.5)
|
||||
x = -x;
|
||||
T x2 = x * x;
|
||||
// w is correction term due to skewness
|
||||
T w = x + sk * (x2 - 1) / 6;
|
||||
/*
|
||||
// Add on correction due to kurtosis.
|
||||
// Disabled for now, seems to make things worse?
|
||||
//
|
||||
if(n >= 10)
|
||||
w += k * x * (x2 - 3) / 24 + sk * sk * x * (2 * x2 - 5) / -36;
|
||||
*/
|
||||
w = m + sigma * w;
|
||||
if(w < tools::min_value<T>())
|
||||
return sqrt(tools::min_value<T>());
|
||||
if(w > n)
|
||||
return n;
|
||||
return w;
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
RealType quantile_imp(const binomial_distribution<RealType, Policy>& dist, const RealType& p, const RealType& q, bool comp)
|
||||
{ // Quantile or Percent Point Binomial function.
|
||||
// Return the number of expected successes k,
|
||||
// for a given probability p.
|
||||
//
|
||||
// Error checks:
|
||||
BOOST_MATH_STD_USING // ADL of std names
|
||||
RealType result = 0;
|
||||
RealType trials = dist.trials();
|
||||
RealType success_fraction = dist.success_fraction();
|
||||
if(false == binomial_detail::check_dist_and_prob(
|
||||
"boost::math::quantile(binomial_distribution<%1%> const&, %1%)",
|
||||
trials,
|
||||
success_fraction,
|
||||
p,
|
||||
&result, Policy()))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// Special cases:
|
||||
//
|
||||
if(p == 0)
|
||||
{ // There may actually be no answer to this question,
|
||||
// since the probability of zero successes may be non-zero,
|
||||
// but zero is the best we can do:
|
||||
return 0;
|
||||
}
|
||||
if(p == 1)
|
||||
{ // Probability of n or fewer successes is always one,
|
||||
// so n is the most sensible answer here:
|
||||
return trials;
|
||||
}
|
||||
if (p <= pow(1 - success_fraction, trials))
|
||||
{ // p <= pdf(dist, 0) == cdf(dist, 0)
|
||||
return 0; // So the only reasonable result is zero.
|
||||
} // And root finder would fail otherwise.
|
||||
if(success_fraction == 1)
|
||||
{ // our formulae break down in this case:
|
||||
return p > 0.5f ? trials : 0;
|
||||
}
|
||||
|
||||
// Solve for quantile numerically:
|
||||
//
|
||||
RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, success_fraction, p, q, Policy());
|
||||
RealType factor = 8;
|
||||
if(trials > 100)
|
||||
factor = 1.01f; // guess is pretty accurate
|
||||
else if((trials > 10) && (trials - 1 > guess) && (guess > 3))
|
||||
factor = 1.15f; // less accurate but OK.
|
||||
else if(trials < 10)
|
||||
{
|
||||
// pretty inaccurate guess in this area:
|
||||
if(guess > trials / 64)
|
||||
{
|
||||
guess = trials / 4;
|
||||
factor = 2;
|
||||
}
|
||||
else
|
||||
guess = trials / 1024;
|
||||
}
|
||||
else
|
||||
factor = 2; // trials largish, but in far tails.
|
||||
|
||||
typedef typename Policy::discrete_quantile_type discrete_quantile_type;
|
||||
boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
|
||||
return detail::inverse_discrete_quantile(
|
||||
dist,
|
||||
comp ? q : p,
|
||||
comp,
|
||||
guess,
|
||||
factor,
|
||||
RealType(1),
|
||||
discrete_quantile_type(),
|
||||
max_iter);
|
||||
} // quantile
|
||||
|
||||
}
|
||||
|
||||
template <class RealType = double, class Policy = policies::policy<> >
|
||||
class binomial_distribution
|
||||
{
|
||||
public:
|
||||
typedef RealType value_type;
|
||||
typedef Policy policy_type;
|
||||
|
||||
binomial_distribution(RealType n = 1, RealType p = 0.5) : m_n(n), m_p(p)
|
||||
{ // Default n = 1 is the Bernoulli distribution
|
||||
// with equal probability of 'heads' or 'tails.
|
||||
RealType r;
|
||||
binomial_detail::check_dist(
|
||||
"boost::math::binomial_distribution<%1%>::binomial_distribution",
|
||||
m_n,
|
||||
m_p,
|
||||
&r, Policy());
|
||||
} // binomial_distribution constructor.
|
||||
|
||||
RealType success_fraction() const
|
||||
{ // Probability.
|
||||
return m_p;
|
||||
}
|
||||
RealType trials() const
|
||||
{ // Total number of trials.
|
||||
return m_n;
|
||||
}
|
||||
|
||||
enum interval_type{
|
||||
clopper_pearson_exact_interval,
|
||||
jeffreys_prior_interval
|
||||
};
|
||||
|
||||
//
|
||||
// Estimation of the success fraction parameter.
|
||||
// The best estimate is actually simply successes/trials,
|
||||
// these functions are used
|
||||
// to obtain confidence intervals for the success fraction.
|
||||
//
|
||||
static RealType find_lower_bound_on_p(
|
||||
RealType trials,
|
||||
RealType successes,
|
||||
RealType probability,
|
||||
interval_type t = clopper_pearson_exact_interval)
|
||||
{
|
||||
static const char* function = "boost::math::binomial_distribution<%1%>::find_lower_bound_on_p";
|
||||
// Error checks:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
function, trials, RealType(0), successes, &result, Policy())
|
||||
&&
|
||||
binomial_detail::check_dist_and_prob(
|
||||
function, trials, RealType(0), probability, &result, Policy()))
|
||||
{ return result; }
|
||||
|
||||
if(successes == 0)
|
||||
return 0;
|
||||
|
||||
// NOTE!!! The Clopper Pearson formula uses "successes" not
|
||||
// "successes+1" as usual to get the lower bound,
|
||||
// see http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm
|
||||
return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability, static_cast<RealType*>(0), Policy())
|
||||
: ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
|
||||
}
|
||||
static RealType find_upper_bound_on_p(
|
||||
RealType trials,
|
||||
RealType successes,
|
||||
RealType probability,
|
||||
interval_type t = clopper_pearson_exact_interval)
|
||||
{
|
||||
static const char* function = "boost::math::binomial_distribution<%1%>::find_upper_bound_on_p";
|
||||
// Error checks:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
function, trials, RealType(0), successes, &result, Policy())
|
||||
&&
|
||||
binomial_detail::check_dist_and_prob(
|
||||
function, trials, RealType(0), probability, &result, Policy()))
|
||||
{ return result; }
|
||||
|
||||
if(trials == successes)
|
||||
return 1;
|
||||
|
||||
return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability, static_cast<RealType*>(0), Policy())
|
||||
: ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
|
||||
}
|
||||
// Estimate number of trials parameter:
|
||||
//
|
||||
// "How many trials do I need to be P% sure of seeing k events?"
|
||||
// or
|
||||
// "How many trials can I have to be P% sure of seeing fewer than k events?"
|
||||
//
|
||||
static RealType find_minimum_number_of_trials(
|
||||
RealType k, // number of events
|
||||
RealType p, // success fraction
|
||||
RealType alpha) // risk level
|
||||
{
|
||||
static const char* function = "boost::math::binomial_distribution<%1%>::find_minimum_number_of_trials";
|
||||
// Error checks:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
function, k, p, k, &result, Policy())
|
||||
&&
|
||||
binomial_detail::check_dist_and_prob(
|
||||
function, k, p, alpha, &result, Policy()))
|
||||
{ return result; }
|
||||
|
||||
result = ibetac_invb(k + 1, p, alpha, Policy()); // returns n - k
|
||||
return result + k;
|
||||
}
|
||||
|
||||
static RealType find_maximum_number_of_trials(
|
||||
RealType k, // number of events
|
||||
RealType p, // success fraction
|
||||
RealType alpha) // risk level
|
||||
{
|
||||
static const char* function = "boost::math::binomial_distribution<%1%>::find_maximum_number_of_trials";
|
||||
// Error checks:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
function, k, p, k, &result, Policy())
|
||||
&&
|
||||
binomial_detail::check_dist_and_prob(
|
||||
function, k, p, alpha, &result, Policy()))
|
||||
{ return result; }
|
||||
|
||||
result = ibeta_invb(k + 1, p, alpha, Policy()); // returns n - k
|
||||
return result + k;
|
||||
}
|
||||
|
||||
private:
|
||||
RealType m_n; // Not sure if this shouldn't be an int?
|
||||
RealType m_p; // success_fraction
|
||||
}; // template <class RealType, class Policy> class binomial_distribution
|
||||
|
||||
typedef binomial_distribution<> binomial;
|
||||
// typedef binomial_distribution<double> binomial;
|
||||
// IS now included since no longer a name clash with function binomial.
|
||||
//typedef binomial_distribution<double> binomial; // Reserved name of type double.
|
||||
|
||||
template <class RealType, class Policy>
|
||||
const std::pair<RealType, RealType> range(const binomial_distribution<RealType, Policy>& dist)
|
||||
{ // Range of permissible values for random variable k.
|
||||
using boost::math::tools::max_value;
|
||||
return std::pair<RealType, RealType>(static_cast<RealType>(0), dist.trials());
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
const std::pair<RealType, RealType> support(const binomial_distribution<RealType, Policy>& dist)
|
||||
{ // Range of supported values for random variable k.
|
||||
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
|
||||
return std::pair<RealType, RealType>(static_cast<RealType>(0), dist.trials());
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType mean(const binomial_distribution<RealType, Policy>& dist)
|
||||
{ // Mean of Binomial distribution = np.
|
||||
return dist.trials() * dist.success_fraction();
|
||||
} // mean
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType variance(const binomial_distribution<RealType, Policy>& dist)
|
||||
{ // Variance of Binomial distribution = np(1-p).
|
||||
return dist.trials() * dist.success_fraction() * (1 - dist.success_fraction());
|
||||
} // variance
|
||||
|
||||
template <class RealType, class Policy>
|
||||
RealType pdf(const binomial_distribution<RealType, Policy>& dist, const RealType& k)
|
||||
{ // Probability Density/Mass Function.
|
||||
BOOST_FPU_EXCEPTION_GUARD
|
||||
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
RealType n = dist.trials();
|
||||
|
||||
// Error check:
|
||||
RealType result = 0; // initialization silences some compiler warnings
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
"boost::math::pdf(binomial_distribution<%1%> const&, %1%)",
|
||||
n,
|
||||
dist.success_fraction(),
|
||||
k,
|
||||
&result, Policy()))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// Special cases of success_fraction, regardless of k successes and regardless of n trials.
|
||||
if (dist.success_fraction() == 0)
|
||||
{ // probability of zero successes is 1:
|
||||
return static_cast<RealType>(k == 0 ? 1 : 0);
|
||||
}
|
||||
if (dist.success_fraction() == 1)
|
||||
{ // probability of n successes is 1:
|
||||
return static_cast<RealType>(k == n ? 1 : 0);
|
||||
}
|
||||
// k argument may be integral, signed, or unsigned, or floating point.
|
||||
// If necessary, it has already been promoted from an integral type.
|
||||
if (n == 0)
|
||||
{
|
||||
return 1; // Probability = 1 = certainty.
|
||||
}
|
||||
if (k == 0)
|
||||
{ // binomial coeffic (n 0) = 1,
|
||||
// n ^ 0 = 1
|
||||
return pow(1 - dist.success_fraction(), n);
|
||||
}
|
||||
if (k == n)
|
||||
{ // binomial coeffic (n n) = 1,
|
||||
// n ^ 0 = 1
|
||||
return pow(dist.success_fraction(), k); // * pow((1 - dist.success_fraction()), (n - k)) = 1
|
||||
}
|
||||
|
||||
// Probability of getting exactly k successes
|
||||
// if C(n, k) is the binomial coefficient then:
|
||||
//
|
||||
// f(k; n,p) = C(n, k) * p^k * (1-p)^(n-k)
|
||||
// = (n!/(k!(n-k)!)) * p^k * (1-p)^(n-k)
|
||||
// = (tgamma(n+1) / (tgamma(k+1)*tgamma(n-k+1))) * p^k * (1-p)^(n-k)
|
||||
// = p^k (1-p)^(n-k) / (beta(k+1, n-k+1) * (n+1))
|
||||
// = ibeta_derivative(k+1, n-k+1, p) / (n+1)
|
||||
//
|
||||
using boost::math::ibeta_derivative; // a, b, x
|
||||
return ibeta_derivative(k+1, n-k+1, dist.success_fraction(), Policy()) / (n+1);
|
||||
|
||||
} // pdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType cdf(const binomial_distribution<RealType, Policy>& dist, const RealType& k)
|
||||
{ // Cumulative Distribution Function Binomial.
|
||||
// The random variate k is the number of successes in n trials.
|
||||
// k argument may be integral, signed, or unsigned, or floating point.
|
||||
// If necessary, it has already been promoted from an integral type.
|
||||
|
||||
// Returns the sum of the terms 0 through k of the Binomial Probability Density/Mass:
|
||||
//
|
||||
// i=k
|
||||
// -- ( n ) i n-i
|
||||
// > | | p (1-p)
|
||||
// -- ( i )
|
||||
// i=0
|
||||
|
||||
// The terms are not summed directly instead
|
||||
// the incomplete beta integral is employed,
|
||||
// according to the formula:
|
||||
// P = I[1-p]( n-k, k+1).
|
||||
// = 1 - I[p](k + 1, n - k)
|
||||
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
RealType n = dist.trials();
|
||||
RealType p = dist.success_fraction();
|
||||
|
||||
// Error check:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
"boost::math::cdf(binomial_distribution<%1%> const&, %1%)",
|
||||
n,
|
||||
p,
|
||||
k,
|
||||
&result, Policy()))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (k == n)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Special cases, regardless of k.
|
||||
if (p == 0)
|
||||
{ // This need explanation:
|
||||
// the pdf is zero for all cases except when k == 0.
|
||||
// For zero p the probability of zero successes is one.
|
||||
// Therefore the cdf is always 1:
|
||||
// the probability of k or *fewer* successes is always 1
|
||||
// if there are never any successes!
|
||||
return 1;
|
||||
}
|
||||
if (p == 1)
|
||||
{ // This is correct but needs explanation:
|
||||
// when k = 1
|
||||
// all the cdf and pdf values are zero *except* when k == n,
|
||||
// and that case has been handled above already.
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// P = I[1-p](n - k, k + 1)
|
||||
// = 1 - I[p](k + 1, n - k)
|
||||
// Use of ibetac here prevents cancellation errors in calculating
|
||||
// 1-p if p is very small, perhaps smaller than machine epsilon.
|
||||
//
|
||||
// Note that we do not use a finite sum here, since the incomplete
|
||||
// beta uses a finite sum internally for integer arguments, so
|
||||
// we'll just let it take care of the necessary logic.
|
||||
//
|
||||
return ibetac(k + 1, n - k, p, Policy());
|
||||
} // binomial cdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType cdf(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c)
|
||||
{ // Complemented Cumulative Distribution Function Binomial.
|
||||
// The random variate k is the number of successes in n trials.
|
||||
// k argument may be integral, signed, or unsigned, or floating point.
|
||||
// If necessary, it has already been promoted from an integral type.
|
||||
|
||||
// Returns the sum of the terms k+1 through n of the Binomial Probability Density/Mass:
|
||||
//
|
||||
// i=n
|
||||
// -- ( n ) i n-i
|
||||
// > | | p (1-p)
|
||||
// -- ( i )
|
||||
// i=k+1
|
||||
|
||||
// The terms are not summed directly instead
|
||||
// the incomplete beta integral is employed,
|
||||
// according to the formula:
|
||||
// Q = 1 -I[1-p]( n-k, k+1).
|
||||
// = I[p](k + 1, n - k)
|
||||
|
||||
BOOST_MATH_STD_USING // for ADL of std functions
|
||||
|
||||
RealType const& k = c.param;
|
||||
binomial_distribution<RealType, Policy> const& dist = c.dist;
|
||||
RealType n = dist.trials();
|
||||
RealType p = dist.success_fraction();
|
||||
|
||||
// Error checks:
|
||||
RealType result = 0;
|
||||
if(false == binomial_detail::check_dist_and_k(
|
||||
"boost::math::cdf(binomial_distribution<%1%> const&, %1%)",
|
||||
n,
|
||||
p,
|
||||
k,
|
||||
&result, Policy()))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (k == n)
|
||||
{ // Probability of greater than n successes is necessarily zero:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Special cases, regardless of k.
|
||||
if (p == 0)
|
||||
{
|
||||
// This need explanation: the pdf is zero for all
|
||||
// cases except when k == 0. For zero p the probability
|
||||
// of zero successes is one. Therefore the cdf is always
|
||||
// 1: the probability of *more than* k successes is always 0
|
||||
// if there are never any successes!
|
||||
return 0;
|
||||
}
|
||||
if (p == 1)
|
||||
{
|
||||
// This needs explanation, when p = 1
|
||||
// we always have n successes, so the probability
|
||||
// of more than k successes is 1 as long as k < n.
|
||||
// The k == n case has already been handled above.
|
||||
return 1;
|
||||
}
|
||||
//
|
||||
// Calculate cdf binomial using the incomplete beta function.
|
||||
// Q = 1 -I[1-p](n - k, k + 1)
|
||||
// = I[p](k + 1, n - k)
|
||||
// Use of ibeta here prevents cancellation errors in calculating
|
||||
// 1-p if p is very small, perhaps smaller than machine epsilon.
|
||||
//
|
||||
// Note that we do not use a finite sum here, since the incomplete
|
||||
// beta uses a finite sum internally for integer arguments, so
|
||||
// we'll just let it take care of the necessary logic.
|
||||
//
|
||||
return ibeta(k + 1, n - k, p, Policy());
|
||||
} // binomial cdf
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType quantile(const binomial_distribution<RealType, Policy>& dist, const RealType& p)
|
||||
{
|
||||
return binomial_detail::quantile_imp(dist, p, RealType(1-p), false);
|
||||
} // quantile
|
||||
|
||||
template <class RealType, class Policy>
|
||||
RealType quantile(const complemented2_type<binomial_distribution<RealType, Policy>, RealType>& c)
|
||||
{
|
||||
return binomial_detail::quantile_imp(c.dist, RealType(1-c.param), c.param, true);
|
||||
} // quantile
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType mode(const binomial_distribution<RealType, Policy>& dist)
|
||||
{
|
||||
BOOST_MATH_STD_USING // ADL of std functions.
|
||||
RealType p = dist.success_fraction();
|
||||
RealType n = dist.trials();
|
||||
return floor(p * (n + 1));
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType median(const binomial_distribution<RealType, Policy>& dist)
|
||||
{ // Bounds for the median of the negative binomial distribution
|
||||
// VAN DE VEN R. ; WEBER N. C. ;
|
||||
// Univ. Sydney, school mathematics statistics, Sydney N.S.W. 2006, AUSTRALIE
|
||||
// Metrika (Metrika) ISSN 0026-1335 CODEN MTRKA8
|
||||
// 1993, vol. 40, no3-4, pp. 185-189 (4 ref.)
|
||||
|
||||
// Bounds for median and 50 percetage point of binomial and negative binomial distribution
|
||||
// Metrika, ISSN 0026-1335 (Print) 1435-926X (Online)
|
||||
// Volume 41, Number 1 / December, 1994, DOI 10.1007/BF01895303
|
||||
BOOST_MATH_STD_USING // ADL of std functions.
|
||||
RealType p = dist.success_fraction();
|
||||
RealType n = dist.trials();
|
||||
// Wikipedia says one of floor(np) -1, floor (np), floor(np) +1
|
||||
return floor(p * n); // Chose the middle value.
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType skewness(const binomial_distribution<RealType, Policy>& dist)
|
||||
{
|
||||
BOOST_MATH_STD_USING // ADL of std functions.
|
||||
RealType p = dist.success_fraction();
|
||||
RealType n = dist.trials();
|
||||
return (1 - 2 * p) / sqrt(n * p * (1 - p));
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType kurtosis(const binomial_distribution<RealType, Policy>& dist)
|
||||
{
|
||||
RealType p = dist.success_fraction();
|
||||
RealType n = dist.trials();
|
||||
return 3 - 6 / n + 1 / (n * p * (1 - p));
|
||||
}
|
||||
|
||||
template <class RealType, class Policy>
|
||||
inline RealType kurtosis_excess(const binomial_distribution<RealType, Policy>& dist)
|
||||
{
|
||||
RealType p = dist.success_fraction();
|
||||
RealType q = 1 - p;
|
||||
RealType n = dist.trials();
|
||||
return (1 - 6 * p * q) / (n * p * q);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
} // namespace boost
|
||||
|
||||
// This include must be at the end, *after* the accessors
|
||||
// for this distribution have been defined, in order to
|
||||
// keep compilers that support two-phase lookup happy.
|
||||
#include <boost/math/distributions/detail/derived_accessors.hpp>
|
||||
|
||||
#endif // BOOST_MATH_SPECIAL_BINOMIAL_HPP
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
subroutine sync64(c0,nf1,nf2,nfqso,ntol,mode64,emedelay,dtx,f0,jpk,sync, &
|
||||
sync2,width)
|
||||
|
||||
use timer_module, only: timer
|
||||
|
||||
parameter (NMAX=60*12000) !Max size of raw data at 12000 Hz
|
||||
parameter (NSPS=3456) !Samples per symbol at 6000 Hz
|
||||
parameter (NSPC=7*NSPS) !Samples per Costas array
|
||||
real s1(0:NSPC-1) !Power spectrum of Costas 1
|
||||
real s2(0:NSPC-1) !Power spectrum of Costas 2
|
||||
real s3(0:NSPC-1) !Power spectrum of Costas 3
|
||||
real s0(0:NSPC-1) !Sum of s1+s2+s3
|
||||
real s0a(0:NSPC-1) !Best synchromized spectrum (saved)
|
||||
real s0b(0:NSPC-1) !tmp
|
||||
real a(5)
|
||||
integer icos7(0:6) !Costas 7x7 tones
|
||||
integer ipk0(1)
|
||||
complex cc(0:NSPC-1) !Costas waveform
|
||||
complex c0(0:720000) !Complex spectrum of dd()
|
||||
complex c1(0:NSPC-1) !Complex spectrum of Costas 1
|
||||
complex c2(0:NSPC-1) !Complex spectrum of Costas 2
|
||||
complex c3(0:NSPC-1) !Complex spectrum of Costas 3
|
||||
data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern
|
||||
data mode64z/-1/
|
||||
save
|
||||
|
||||
if(mode64.ne.mode64z) then
|
||||
twopi=8.0*atan(1.0)
|
||||
dfgen=mode64*12000.0/6912.0
|
||||
k=-1
|
||||
phi=0.
|
||||
do j=0,6 !Compute complex Costas waveform
|
||||
dphi=twopi*10.0*icos7(j)*dfgen/6000.0
|
||||
do i=1,NSPS
|
||||
phi=phi + dphi
|
||||
if(phi.gt.twopi) phi=phi-twopi
|
||||
k=k+1
|
||||
cc(k)=cmplx(cos(phi),sin(phi))
|
||||
enddo
|
||||
enddo
|
||||
mode64z=mode64
|
||||
endif
|
||||
|
||||
nfft3=NSPC
|
||||
nh3=nfft3/2
|
||||
df3=6000.0/nfft3
|
||||
|
||||
fa=max(nf1,nfqso-ntol)
|
||||
fb=min(nf2,nfqso+ntol)
|
||||
iaa=max(0,nint(fa/df3))
|
||||
ibb=min(NSPC-1,nint(fb/df3))
|
||||
|
||||
maxtol=max(ntol,500)
|
||||
fa=max(nf1,nfqso-maxtol)
|
||||
fb=min(nf2,nfqso+maxtol)
|
||||
ia=max(0,nint(fa/df3))
|
||||
ib=min(NSPC-1,nint(fb/df3))
|
||||
id=0.1*(ib-ia)
|
||||
iz=ib-ia+1
|
||||
sync=-1.e30
|
||||
smaxall=0.
|
||||
jpk=0
|
||||
ja=0
|
||||
jb=(5.0+emedelay)*6000
|
||||
jstep=100
|
||||
ipk=0
|
||||
kpk=0
|
||||
nadd=10*mode64
|
||||
if(mod(nadd,2).eq.0) nadd=nadd+1 !Make nadd odd
|
||||
nskip=max(49,nadd)
|
||||
|
||||
do j1=ja,jb,jstep
|
||||
call timer('sync64_1',0)
|
||||
j2=j1 + 39*NSPS
|
||||
j3=j1 + 77*NSPS
|
||||
c1=1.e-4*c0(j1:j1+NSPC-1) * conjg(cc)
|
||||
c2=1.e-4*c0(j2:j2+NSPC-1) * conjg(cc)
|
||||
c3=1.e-4*c0(j3:j3+NSPC-1) * conjg(cc)
|
||||
call four2a(c1,nfft3,1,-1,1)
|
||||
call four2a(c2,nfft3,1,-1,1)
|
||||
call four2a(c3,nfft3,1,-1,1)
|
||||
s1=0.
|
||||
s2=0.
|
||||
s3=0.
|
||||
s0b=0.
|
||||
do i=ia,ib
|
||||
freq=i*df3
|
||||
s1(i)=real(c1(i))**2 + aimag(c1(i))**2
|
||||
s2(i)=real(c2(i))**2 + aimag(c2(i))**2
|
||||
s3(i)=real(c3(i))**2 + aimag(c3(i))**2
|
||||
enddo
|
||||
call timer('sync64_1',1)
|
||||
|
||||
call timer('sync64_2',0)
|
||||
s0(ia:ib)=s1(ia:ib) + s2(ia:ib) + s3(ia:ib)
|
||||
s0(:ia-1)=0.
|
||||
s0(ib+1:)=0.
|
||||
if(nadd.ge.3) then
|
||||
do ii=1,3
|
||||
s0b(ia:ib)=s0(ia:ib)
|
||||
call smo(s0b(ia:ib),iz,s0(ia:ib),nadd)
|
||||
enddo
|
||||
endif
|
||||
call averms(s0(ia+id:ib-id),iz-2*id,nskip,ave,rms)
|
||||
s=(maxval(s0(iaa:ibb))-ave)/rms
|
||||
ipk0=maxloc(s0(iaa:ibb))
|
||||
ip=ipk0(1) + iaa - 1
|
||||
if(s.gt.sync) then
|
||||
jpk=j1
|
||||
s0a=(s0-ave)/rms
|
||||
sync=s
|
||||
dtx=jpk/6000.0 - 1.0
|
||||
ipk=ip
|
||||
f0=ip*df3
|
||||
endif
|
||||
call timer('sync64_2',1)
|
||||
enddo
|
||||
|
||||
s0a=s0a+2.0
|
||||
! write(17) ia,ib,s0a(ia:ib) !Save data for red curve
|
||||
! close(17)
|
||||
|
||||
nskip=50
|
||||
call lorentzian(s0a(ia+nskip:ib-nskip),iz-2*nskip,a)
|
||||
f0a=(a(3)+ia+49)*df3
|
||||
w1=df3*a(4)
|
||||
w2=2*nadd*df3
|
||||
width=w1
|
||||
if(w1.gt.1.2*w2) width=sqrt(w1**2 - w2**2)
|
||||
|
||||
sq=0.
|
||||
do i=1,20
|
||||
j=ia+nskip+1
|
||||
k=ib-nskip-21+i
|
||||
sq=sq + (s0a(j)-a(1))**2 + (s0a(k)-a(1))**2
|
||||
enddo
|
||||
rms2=sqrt(sq/40.0)
|
||||
sync2=10.0*log10(a(2)/rms2)
|
||||
|
||||
slimit=6.0
|
||||
rewind 17
|
||||
write(17,1110) 0.0,0.0
|
||||
rewind 17
|
||||
! rewind 76
|
||||
do i=2,iz-2*nskip-1,3
|
||||
x=i
|
||||
z=(x-a(3))/(0.5*a(4))
|
||||
yfit=a(1)
|
||||
if(abs(z).lt.3.0) then
|
||||
d=1.0 + z*z
|
||||
yfit=a(1) + a(2)*(1.0/d - 0.1)
|
||||
endif
|
||||
j=i+ia+49
|
||||
freq=j*df3
|
||||
ss=(s0a(j-1)+s0a(j)+s0a(j+1))/3.0
|
||||
if(ss.gt.slimit) write(17,1110) freq,ss
|
||||
1110 format(3f10.3)
|
||||
! write(76,1110) freq,ss,yfit
|
||||
enddo
|
||||
flush(17)
|
||||
close(17)
|
||||
! flush(76)
|
||||
|
||||
return
|
||||
end subroutine sync64
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
Reference in New Issue
Block a user