gsl_wavelet_workspace * gsl_wavelet_workspace_alloc (size_t n) { gsl_wavelet_workspace *work; if (n == 0) { GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0); } work = (gsl_wavelet_workspace *) malloc (sizeof (gsl_wavelet_workspace)); if (work == NULL) { GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0); } work->n = n; work->scratch = (double *) malloc (n * sizeof (double)); if (work->scratch == NULL) { /* error in constructor, prevent memory leak */ free (work); GSL_ERROR_VAL ("failed to allocate scratch space", GSL_ENOMEM, 0); } return work; }
gsl_rng * gsl_rng_alloc (const gsl_rng_type * T) { gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng)); if (r == 0) { GSL_ERROR_VAL ("failed to allocate space for rng struct", GSL_ENOMEM, 0); }; r->state = calloc (1, T->size); if (r->state == 0) { free (r); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for rng state", GSL_ENOMEM, 0); }; r->type = T; gsl_rng_set (r, gsl_rng_default_seed); /* seed the generator */ return r; }
FUNCTION (gsl_matrix, view_array) (QUALIFIER ATOMIC * array, const size_t n1, const size_t n2) { QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; if (n1 == 0) { GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", GSL_EINVAL, view); } else if (n2 == 0) { GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", GSL_EINVAL, view); } { TYPE(gsl_matrix) m = NULL_MATRIX; m.data = (ATOMIC *)array; m.size1 = n1; m.size2 = n2; m.tda = n2; m.block = 0; m.owner = 0; view.matrix = m; return view; } }
int gsl_histogram2d_set_ranges_uniform (gsl_histogram2d * h, double xmin, double xmax, double ymin, double ymax) { size_t i; const size_t nx = h->nx, ny = h->ny; if (xmin >= xmax) { GSL_ERROR_VAL ("xmin must be less than xmax", GSL_EINVAL, 0); } if (ymin >= ymax) { GSL_ERROR_VAL ("ymin must be less than ymax", GSL_EINVAL, 0); } /* initialize ranges */ make_uniform (h->xrange, nx, xmin, xmax); make_uniform (h->yrange, ny, ymin, ymax); /* clear contents */ for (i = 0; i < nx * ny; i++) { h->bin[i] = 0; } return GSL_SUCCESS; }
gsl_wavelet * gsl_wavelet_alloc (const gsl_wavelet_type * T, size_t k) { int status; gsl_wavelet *w = (gsl_wavelet *) malloc (sizeof (gsl_wavelet)); if (w == NULL) { GSL_ERROR_VAL ("failed to allocate space for wavelet struct", GSL_ENOMEM, 0); }; w->type = T; status = (T->init) (&(w->h1), &(w->g1), &(w->h2), &(w->g2), &(w->nc), &(w->offset), k); if (status) { free (w); GSL_ERROR_VAL ("invalid wavelet member", GSL_EINVAL, 0); } return w; }
gsl_rng * gsl_rng_clone (const gsl_rng * q) { gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng)); if (r == 0) { GSL_ERROR_VAL ("failed to allocate space for rng struct", GSL_ENOMEM, 0); }; r->state = malloc (q->type->size); if (r->state == 0) { free (r); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for rng state", GSL_ENOMEM, 0); }; r->type = q->type; memcpy (r->state, q->state, q->type->size); return r; }
/* This function initializes a vector of length n, returning a pointer to a * newly initialized vector struct. A new block is allocated for the elements * of the vector, and stored in the block component of the vector struct. * The size of the vector is set to zero while the size of the block is set * to the argument n. The size of block indicates the capacity of the vector. * Argument: * n - size of the elements * Return: * A point to the vector struct if successful. * A null pointer is returned if insufficient memory is available to * create the vector. */ alder_vector_interval_t * alder_vector_interval_init (const size_t n) { alder_vector_interval_block_t * b; alder_vector_interval_t * v; v = (alder_vector_interval_t *) malloc (sizeof (alder_vector_interval_t)); if (v == 0) { GSL_ERROR_VAL ("failed to allocate space for vector struct", GSL_ENOMEM, 0); } b = alder_vector_interval_block_t_alloc (n);; if (b == 0) { free (v) ; GSL_ERROR_VAL ("failed to allocate space for block", GSL_ENOMEM, 0); } v->data = b->data; v->size = 0; v->block = b; return v; }
gsl_cheb_series * gsl_cheb_alloc(const size_t order) { gsl_cheb_series * cs = (gsl_cheb_series *) malloc(sizeof(gsl_cheb_series)); if(cs == 0) { GSL_ERROR_VAL("failed to allocate gsl_cheb_series struct", GSL_ENOMEM, 0); } cs->order = order; cs->order_sp = order; cs->c = (double *) malloc((order+1) * sizeof(double)); if(cs->c == 0) { GSL_ERROR_VAL("failed to allocate cheb coefficients", GSL_ENOMEM, 0); } cs->f = (double *) malloc((order+1) * sizeof(double)); if(cs->f == 0) { GSL_ERROR_VAL("failed to allocate cheb function space", GSL_ENOMEM, 0); } return cs; }
gsl_ntuple * gsl_ntuple_open (char *filename, void *ntuple_data, size_t size) { gsl_ntuple *ntuple = malloc (sizeof (gsl_ntuple)); if (ntuple == 0) { GSL_ERROR_VAL ("failed to allocate space for ntuple struct", GSL_ENOMEM, 0); } ntuple->ntuple_data = ntuple_data; ntuple->size = size; ntuple->file = fopen (filename, "rb"); if (ntuple->file == 0) { free (ntuple); GSL_ERROR_VAL ("unable to open ntuple file for reading", GSL_EFAILED, 0); } return ntuple; }
gsl_histogram2d * gsl_histogram2d_calloc_uniform (const size_t nx, const size_t ny, const double xmin, const double xmax, const double ymin, const double ymax) { gsl_histogram2d *h; if (xmin >= xmax) { GSL_ERROR_VAL ("xmin must be less than xmax", GSL_EINVAL, 0); } if (ymin >= ymax) { GSL_ERROR_VAL ("ymin must be less than ymax", GSL_EINVAL, 0); } h = gsl_histogram2d_calloc (nx, ny); if (h == 0) { return h; } make_uniform (h->xrange, nx, xmin, xmax); make_uniform (h->yrange, ny, ymin, ymax); return h; }
gsl_qrng * gsl_qrng_clone (const gsl_qrng * q) { gsl_qrng * r = (gsl_qrng *) malloc (sizeof (gsl_qrng)); if (r == 0) { GSL_ERROR_VAL ("failed to allocate space for rng struct", GSL_ENOMEM, 0); }; r->dimension = q->dimension; r->state_size = q->state_size; r->state = malloc (r->state_size); if (r->state == 0) { free (r); GSL_ERROR_VAL ("failed to allocate space for rng state", GSL_ENOMEM, 0); }; r->type = q->type; memcpy (r->state, q->state, q->state_size); return r; }
_gsl_vector_match_const_view gsl_vector_match_const_subvector (const gsl_vector_match * v, size_t offset, size_t n) { _gsl_vector_match_const_view view = {{0, 0, 0, 0, 0}}; if (n == 0) { GSL_ERROR_VAL ("vector length n must be positive integer", GSL_EINVAL, view); } if (offset + (n - 1) >= v->size) { GSL_ERROR_VAL ("view would extend past end of vector", GSL_EINVAL, view); } { gsl_vector_match s = {0, 0, 0, 0, 0}; s.data = v->data + 1 * v->stride * offset ; s.size = n; s.stride = v->stride; s.block = v->block; s.owner = 0; view.vector = s; return view; } }
gsl_monte_plain_state * gsl_monte_plain_alloc (size_t dim) { gsl_monte_plain_state *s = (gsl_monte_plain_state *) malloc (sizeof (gsl_monte_plain_state)); if (s == 0) { GSL_ERROR_VAL ("failed to allocate space for state struct", GSL_ENOMEM, 0); } s->x = (double *) malloc (dim * sizeof (double)); if (s->x == 0) { free (s); GSL_ERROR_VAL ("failed to allocate space for working vector", GSL_ENOMEM, 0); } s->dim = dim; return s; }
gsl_min_fminimizer * gsl_min_fminimizer_alloc (const gsl_min_fminimizer_type * T) { gsl_min_fminimizer * s = (gsl_min_fminimizer *) malloc (sizeof (gsl_min_fminimizer)); if (s == 0) { GSL_ERROR_VAL ("failed to allocate space for minimizer struct", GSL_ENOMEM, 0); }; s->state = malloc (T->size); if (s->state == 0) { free (s); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for minimizer state", GSL_ENOMEM, 0); }; s->type = T ; s->function = NULL; return s; }
gsl_permutation * gsl_permutation_alloc (const size_t n) { gsl_permutation * p; if (n == 0) { GSL_ERROR_VAL ("permutation length n must be positive integer", GSL_EDOM, 0); } p = (gsl_permutation *) malloc (sizeof (gsl_permutation)); if (p == 0) { GSL_ERROR_VAL ("failed to allocate space for permutation struct", GSL_ENOMEM, 0); } p->data = (size_t *) malloc (n * sizeof (size_t)); if (p->data == 0) { free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for permutation data", GSL_ENOMEM, 0); } p->size = n; return p; }
_gsl_vector_match_const_view gsl_vector_match_const_view_array_with_stride (const gsl_vector_match * base, size_t stride, size_t n) { _gsl_vector_match_const_view view = {{0, 0, 0, 0, 0}}; if (n == 0) { GSL_ERROR_VAL ("vector length n must be positive integer", GSL_EINVAL, view); } if (stride == 0) { GSL_ERROR_VAL ("stride must be positive integer", GSL_EINVAL, view); } { gsl_vector_match v = {0, 0, 0, 0, 0}; v.data = (alder_match_t *)base ; v.size = n; v.stride = stride; v.block = 0; v.owner = 0; view.vector = v; return view; } }
/* This function allocates memory for a block of n elements of * alder_vector_interval_data_t, returning a pointer to the block struct. * The block is not initialized and so the values of its elements are * undefined. Use the function * alder_vector_interval_data_t_calloc if you want to ensure that all the * elements are initialized to zero. * Argument: * n - size of the elements * Return: * A point to the block struct if successful. * A null pointer is returned if insufficient memory is available to * create the block. */ alder_vector_interval_block_t * alder_vector_interval_block_t_alloc (const size_t n) { alder_vector_interval_block_t * b; if (n == 0) { GSL_ERROR_VAL ("block length n must be positive integer", GSL_EINVAL, 0); } b = (alder_vector_interval_block_t *) malloc (sizeof (alder_vector_interval_block_t)); if (b == 0) { GSL_ERROR_VAL ("failed to allocate space for block struct", GSL_ENOMEM, 0); } b->data = (alder_vector_interval_data_t *) calloc (1, 1 * n * sizeof (alder_vector_interval_data_t)); if (b->data == 0) { free (b); GSL_ERROR_VAL ("failed to allocate space for block data", GSL_ENOMEM, 0); } b->size = n; return b; }
gsl_vector_match * gsl_vector_match_init () { gsl_block_match * block; gsl_vector_match * v; v = (gsl_vector_match *) malloc (sizeof (gsl_vector_match)); if (v == 0) { GSL_ERROR_VAL ("failed to allocate space for vector struct", GSL_ENOMEM, 0); } block = gsl_block_match_alloc (GSLVECTORMATCHINITSIZE); if (block == 0) { free (v) ; GSL_ERROR_VAL ("failed to allocate space for block", GSL_ENOMEM, 0); } v->data = block->data ; v->size = 0; v->stride = 1; v->block = block; v->owner = 1; return v; }
gsl_qrng * gsl_qrng_alloc (const gsl_qrng_type * T, unsigned int dimension) { gsl_qrng * q = (gsl_qrng *) malloc (sizeof (gsl_qrng)); if (q == 0) { GSL_ERROR_VAL ("allocation failed for qrng struct", GSL_ENOMEM, 0); }; q->dimension = dimension; q->state_size = T->state_size(dimension); q->state = malloc (q->state_size); if (q->state == 0) { free (q); GSL_ERROR_VAL ("allocation failed for qrng state", GSL_ENOMEM, 0); }; q->type = T; T->init_state(q->state, q->dimension); return q; }
gsl_histogram2d_pdf * gsl_histogram2d_pdf_alloc (const size_t nx, const size_t ny) { const size_t n = nx * ny; gsl_histogram2d_pdf *p; if (n == 0) { GSL_ERROR_VAL ("histogram2d pdf length n must be positive integer", GSL_EDOM, 0); } p = (gsl_histogram2d_pdf *) malloc (sizeof (gsl_histogram2d_pdf)); if (p == 0) { GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf struct", GSL_ENOMEM, 0); } p->xrange = (double *) malloc ((nx + 1) * sizeof (double)); if (p->xrange == 0) { free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf xranges", GSL_ENOMEM, 0); } p->yrange = (double *) malloc ((ny + 1) * sizeof (double)); if (p->yrange == 0) { free (p->xrange); free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf yranges", GSL_ENOMEM, 0); } p->sum = (double *) malloc ((n + 1) * sizeof (double)); if (p->sum == 0) { free (p->yrange); free (p->xrange); free (p); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for histogram2d pdf sums", GSL_ENOMEM, 0); } p->nx = nx; p->ny = ny; return p; }
double gsl_spmatrix_get(const gsl_spmatrix *m, const size_t i, const size_t j) { if (i >= m->size1) { GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0.0); } else if (j >= m->size2) { GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0.0); } else { if (GSL_SPMATRIX_ISTRIPLET(m)) { /* traverse binary tree to search for (i,j) element */ void *ptr = tree_find(m, i, j); double x = ptr ? *(double *) ptr : 0.0; return x; } else if (GSL_SPMATRIX_ISCCS(m)) { const size_t *mi = m->i; const size_t *mp = m->p; size_t p; /* loop over column j and search for row index i */ for (p = mp[j]; p < mp[j + 1]; ++p) { if (mi[p] == i) return m->data[p]; } } else if (GSL_SPMATRIX_ISCRS(m)) { const size_t *mi = m->i; const size_t *mp = m->p; size_t p; /* loop over row i and search for column index j */ for (p = mp[i]; p < mp[i + 1]; ++p) { if (mi[p] == j) return m->data[p]; } } else { GSL_ERROR_VAL("unknown sparse matrix type", GSL_EINVAL, 0.0); } /* element not found; return 0 */ return 0.0; } } /* gsl_spmatrix_get() */
gsl_integration_qawo_table * gsl_integration_qawo_table_alloc (double omega, double L, enum gsl_integration_qawo_enum sine, size_t n) { gsl_integration_qawo_table *t; double * chebmo; if (n == 0) { GSL_ERROR_VAL ("table length n must be positive integer", GSL_EDOM, 0); } t = (gsl_integration_qawo_table *) malloc (sizeof (gsl_integration_qawo_table)); if (t == 0) { GSL_ERROR_VAL ("failed to allocate space for qawo_table struct", GSL_ENOMEM, 0); } chebmo = (double *) malloc (25 * n * sizeof (double)); if (chebmo == 0) { free (t); GSL_ERROR_VAL ("failed to allocate space for chebmo block", GSL_ENOMEM, 0); } t->n = n; t->sine = sine; t->omega = omega; t->L = L; t->par = 0.5 * omega * L; t->chebmo = chebmo; /* precompute the moments */ { size_t i; double scale = 1.0; for (i = 0 ; i < t->n; i++) { compute_moments (t->par * scale, t->chebmo + 25*i); scale *= 0.5; } } return t; }
gsl_sum_levin_utrunc_workspace * gsl_sum_levin_utrunc_alloc (size_t n) { gsl_sum_levin_utrunc_workspace * w; if (n == 0) { GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0); } w = (gsl_sum_levin_utrunc_workspace *) malloc(sizeof(gsl_sum_levin_utrunc_workspace)); if (w == NULL) { GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0); } w->q_num = (double *) malloc (n * sizeof (double)); if (w->q_num == NULL) { free(w) ; /* error in constructor, prevent memory leak */ GSL_ERROR_VAL ("failed to allocate space for q_num", GSL_ENOMEM, 0); } w->q_den = (double *) malloc (n * sizeof (double)); if (w->q_den == NULL) { free (w->q_num); free (w) ; /* error in constructor, prevent memory leak */ GSL_ERROR_VAL ("failed to allocate space for q_den", GSL_ENOMEM, 0); } w->dsum = (double *) malloc (n * sizeof (double)); if (w->dsum == NULL) { free (w->q_den); free (w->q_num); free (w) ; /* error in constructor, prevent memory leak */ GSL_ERROR_VAL ("failed to allocate space for dsum", GSL_ENOMEM, 0); } w->size = n; w->terms_used = 0; w->sum_plain = 0; return w; }
quasi_monte_state* quasi_monte_alloc(size_t dim) { quasi_monte_state* s = (quasi_monte_state*)malloc(sizeof(quasi_monte_state)); if (s == NULL) { GSL_ERROR_VAL("failed to allocate space for quasi_monte_state", GSL_ENOMEM, 0); } s->x = (double*)malloc(dim * sizeof(double)); if (s->x == NULL) { free(s); GSL_ERROR_VAL("failed to allocate space for working vector", GSL_ENOMEM, 0); } s->dim = dim; return s; }
double mygsl_histogram3d_get(const mygsl_histogram3d * h, const size_t i, const size_t j, const size_t k) { const size_t nx = h->nx; const size_t ny = h->ny; const size_t nz = h->nz; if (i >= nx) GSL_ERROR_VAL ("index i lies outside valid range of 0 .. nx - 1", GSL_EDOM, 0); if (j >= ny) GSL_ERROR_VAL ("index j lies outside valid range of 0 .. ny - 1", GSL_EDOM, 0); if (k >= nz) GSL_ERROR_VAL ("index k lies outside valid range of 0 .. nz - 1", GSL_EDOM, 0); return h->bin[i*ny*nz + j*nz + k]; }
gsl_multimin_fminimizer * gsl_multimin_fminimizer_alloc (const gsl_multimin_fminimizer_type * T, size_t n) { int status; gsl_multimin_fminimizer *s = (gsl_multimin_fminimizer *) malloc (sizeof (gsl_multimin_fminimizer)); if (s == 0) { GSL_ERROR_VAL ("failed to allocate space for minimizer struct", GSL_ENOMEM, 0); } s->type = T; s->x = gsl_vector_calloc (n); if (s->x == 0) { free (s); GSL_ERROR_VAL ("failed to allocate space for x", GSL_ENOMEM, 0); } s->state = malloc (T->size); if (s->state == 0) { gsl_vector_free (s->x); free (s); GSL_ERROR_VAL ("failed to allocate space for minimizer state", GSL_ENOMEM, 0); } status = (T->alloc) (s->state, n); if (status != GSL_SUCCESS) { free (s->state); gsl_vector_free (s->x); free (s); GSL_ERROR_VAL ("failed to initialize minimizer state", GSL_ENOMEM, 0); } return s; }
int gsl_cheb_init(gsl_cheb_series * cs, const gsl_function *func, const double a, const double b) { size_t k, j; if(a >= b) { GSL_ERROR_VAL("null function interval [a,b]", GSL_EDOM, 0); } cs->a = a; cs->b = b; /* cs->err = 0.0; */ { double bma = 0.5 * (cs->b - cs->a); double bpa = 0.5 * (cs->b + cs->a); double fac = 2.0/(cs->order +1.0); for(k = 0; k<=cs->order; k++) { double y = cos(M_PI * (k+0.5)/(cs->order+1)); cs->f[k] = GSL_FN_EVAL(func, (y*bma + bpa)); } for(j = 0; j<=cs->order; j++) { double sum = 0.0; for(k = 0; k<=cs->order; k++) sum += cs->f[k]*cos(M_PI * j*(k+0.5)/(cs->order+1)); cs->c[j] = fac * sum; } } return GSL_SUCCESS; }
double gsl_histogram_pdf_sample (const gsl_histogram_pdf * p, double r) { size_t i; int status; /* Wrap the exclusive top of the bin down to the inclusive bottom of the bin. Since this is a single point it should not affect the distribution. */ if (r == 1.0) { r = 0.0; } status = find (p->n, p->sum, r, &i); if (status) { GSL_ERROR_VAL ("cannot find r in cumulative pdf", GSL_EDOM, 0); } else { double delta = (r - p->sum[i]) / (p->sum[i + 1] - p->sum[i]); double x = p->range[i] + delta * (p->range[i + 1] - p->range[i]); return x; } }
FUNCTION(gsl_matrix, view_array_with_tda) (QUALIFIER ATOMIC * base, const size_t n1, const size_t n2, const size_t tda) { QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; if (n2 > tda) { GSL_ERROR_VAL ("matrix dimension n2 must not exceed tda", GSL_EINVAL, view); } { TYPE(gsl_matrix) m = NULL_MATRIX; m.data = (ATOMIC *)base; m.size1 = n1; m.size2 = n2; m.tda = tda; m.block = 0; m.owner = 0; view.matrix = m; return view; } }
gsl_multiset * gsl_multiset_alloc (const size_t n, const size_t k) { gsl_multiset * c; if (n == 0) { GSL_ERROR_VAL ("multiset parameter n must be positive integer", GSL_EDOM, 0); } if (k > n) { GSL_ERROR_VAL ("multiset length k must be an integer less than or equal to n", GSL_EDOM, 0); } c = (gsl_multiset *) malloc (sizeof (gsl_multiset)); if (c == 0) { GSL_ERROR_VAL ("failed to allocate space for multiset struct", GSL_ENOMEM, 0); } if (k > 0) { c->data = (size_t *) malloc (k * sizeof (size_t)); if (c->data == 0) { free (c); /* exception in constructor, avoid memory leak */ GSL_ERROR_VAL ("failed to allocate space for multiset data", GSL_ENOMEM, 0); } } else { c->data = 0; } c->n = n; c->k = k; return c; }