Changeset 4857 for trunk/psLib/src/math/psFunctions.c
- Timestamp:
- Aug 23, 2005, 1:23:05 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psFunctions.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psFunctions.c
r4581 r4857 7 7 * polynomials. It also contains a Gaussian functions. 8 8 * 9 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-0 7-20 01:21:13$9 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-08-23 23:23:05 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 20 20 /* INCLUDE FILES */ 21 21 /*****************************************************************************/ 22 #include <gsl/gsl_rng.h>23 #include <gsl/gsl_randist.h>24 25 22 #include <stdio.h> 26 23 #include <stdbool.h> … … 28 25 #include <math.h> 29 26 27 #include "psRandom.h" 30 28 #include "psMemory.h" 31 29 #include "psVector.h" … … 36 34 #include "psFunctions.h" 37 35 #include "psConstants.h" 38 39 36 #include "psErrorText.h" 40 37 … … 688 685 This private routine (formerly a psLib API routine) creates a psVector of the 689 686 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. 695 688 *****************************************************************************/ 696 689 psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts) … … 698 691 PS_ASSERT_INT_NONNEGATIVE(Npts, NULL); 699 692 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 717 700 return(gauss); 718 701 }
Note:
See TracChangeset
for help on using the changeset viewer.
