IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 23, 2005, 1:23:05 PM (21 years ago)
Author:
gusciora
Message:

Eliminated gsl calls in psFunctions.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psFunctions.c

    r4581 r4857  
    77*  polynomials.  It also contains a Gaussian functions.
    88*
    9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2005-07-20 01:21:13 $
     9*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2005-08-23 23:23:05 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020/*  INCLUDE FILES                                                            */
    2121/*****************************************************************************/
    22 #include <gsl/gsl_rng.h>
    23 #include <gsl/gsl_randist.h>
    24 
    2522#include <stdio.h>
    2623#include <stdbool.h>
     
    2825#include <math.h>
    2926
     27#include "psRandom.h"
    3028#include "psMemory.h"
    3129#include "psVector.h"
     
    3634#include "psFunctions.h"
    3735#include "psConstants.h"
    38 
    3936#include "psErrorText.h"
    4037
     
    688685 This private routine (formerly a psLib API routine) creates a psVector of the
    689686 specified size and type F32 and fills it with a random Gaussian distribution
    690  of numbers with the specified mean and sigma.  This routine makes use of the
    691  GSL routines for generating both uniformly distributed numbers and the
    692  Gaussian distribution as well.
    693  
    694 XXX: There is no way to seed the random generator.
     687 of numbers with the specified mean and sigma.
    695688 *****************************************************************************/
    696689psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts)
     
    698691    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
    699692
    700     psVector* gauss = NULL;
    701     const gsl_rng_type *T = NULL;
    702     gsl_rng *r = NULL;
    703     psS32 i = 0;
    704 
    705 
    706     gauss = psVectorAlloc(Npts, PS_TYPE_F32);
    707     gauss->n = Npts;
    708     gsl_rng_env_setup();
    709     T = gsl_rng_default;
    710     r = gsl_rng_alloc(T);
    711 
    712     for (i = 0; i < Npts; i++) {
    713         gauss->data.F32[i] = mean + gsl_ran_gaussian(r, sigma);
    714     }
    715 
    716     // XXX: Should I free r, T as well?  This is a memory leak.
     693    psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, p_psRandomGetSystemSeed());
     694    psVector* gauss = psVectorAlloc(Npts, PS_TYPE_F32);
     695    for (psS32 i = 0; i < Npts; i++) {
     696        gauss->data.F32[i] = mean + p_psRandomGaussian(r, sigma);
     697    }
     698    psFree(r);
     699
    717700    return(gauss);
    718701}
Note: See TracChangeset for help on using the changeset viewer.