hmatrix 0.16.1.1 → 0.16.1.2
raw patch · 2 files changed
+59/−1 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- hmatrix.cabal +2/−1
- src/C/vector-aux.c +57/−0
hmatrix.cabal view
@@ -1,5 +1,5 @@ Name: hmatrix-Version: 0.16.1.1+Version: 0.16.1.2 License: BSD3 License-file: LICENSE Author: Alberto Ruiz@@ -118,6 +118,7 @@ if arch(i386) cc-options: -arch i386 frameworks: Accelerate+ cpp-options: -DOSX if os(freebsd) extra-lib-dirs: /usr/local/lib
src/C/vector-aux.c view
@@ -700,6 +700,61 @@ //////////////////////////////////////////////////////////////////////////////// +#ifdef OSX++#pragma message "randomVector is not thread-safe in OSX"++double gaussrand(int *phase, double *pV1, double *pV2, double *pS)+{+ double V1=*pV1, V2=*pV2, S=*pS;+ double X;++ if(*phase == 0) {+ do {+ double U1 = (double)random() / (double)RAND_MAX;+ double U2 = (double)random() / (double)RAND_MAX;++ V1 = 2 * U1 - 1;+ V2 = 2 * U2 - 1;+ S = V1 * V1 + V2 * V2;+ } while(S >= 1 || S == 0);++ X = V1 * sqrt(-2 * log(S) / S);+ } else+ X = V2 * sqrt(-2 * log(S) / S);++ *phase = 1 - *phase;+ *pV1=V1; *pV2=V2; *pS=S;++ return X;++}++int random_vector(unsigned int seed, int code, DVEC(r)) {+ int phase = 0;+ double V1,V2,S;+ + int k;+ switch (code) {+ case 0: { // uniform+ for (k=0; k<rn; k++) {+ rp[k] = (double)random() / (double)RAND_MAX;+ }+ OK+ }+ case 1: { // gaussian+ for (k=0; k<rn; k++) {+ rp[k] = gaussrand(&phase,&V1,&V2,&S);+ }+ OK+ }++ default: ERROR(BAD_CODE);+ }+}++#else+ inline double urandom(struct random_data * buffer) { int32_t res; random_r(buffer,&res);@@ -765,6 +820,8 @@ default: ERROR(BAD_CODE); } }++#endif ////////////////////////////////////////////////////////////////////////////////