diff options
Diffstat (limited to 'packages/base')
-rw-r--r-- | packages/base/THANKS.md | 3 | ||||
-rw-r--r-- | packages/base/hmatrix.cabal | 4 | ||||
-rw-r--r-- | packages/base/src/Internal/C/vector-aux.c | 49 |
3 files changed, 53 insertions, 3 deletions
diff --git a/packages/base/THANKS.md b/packages/base/THANKS.md index f29775a..f331dea 100644 --- a/packages/base/THANKS.md +++ b/packages/base/THANKS.md | |||
@@ -192,7 +192,8 @@ module reorganization, monadic mapVectorM, and many other improvements. | |||
192 | 192 | ||
193 | - Matt Peddie wrote the interfaces to the interpolation and simulated annealing modules. | 193 | - Matt Peddie wrote the interfaces to the interpolation and simulated annealing modules. |
194 | 194 | ||
195 | - "maxc01" solved uninstallability in FreeBSD and improved urandom | 195 | - "maxc01" solved uninstallability in FreeBSD, improved urandom, and fixed a Windows |
196 | link error using rand_s. | ||
196 | 197 | ||
197 | - "ntfrgl" added {take,drop}Last{Rows,Columns} and odeSolveVWith with generalized step control function | 198 | - "ntfrgl" added {take,drop}Last{Rows,Columns} and odeSolveVWith with generalized step control function |
198 | and fixed link errors related to mod/mod_l. | 199 | and fixed link errors related to mod/mod_l. |
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal index bacc629..0cfbd88 100644 --- a/packages/base/hmatrix.cabal +++ b/packages/base/hmatrix.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix |
2 | Version: 0.17.0.1 | 2 | Version: 0.17.0.2 |
3 | License: BSD3 | 3 | License: BSD3 |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -16,7 +16,7 @@ Description: Linear systems, matrix decompositions, and other numerical c | |||
16 | Code examples: <http://dis.um.es/~alberto/hmatrix/hmatrix.html> | 16 | Code examples: <http://dis.um.es/~alberto/hmatrix/hmatrix.html> |
17 | 17 | ||
18 | Category: Math | 18 | Category: Math |
19 | tested-with: GHC==7.8 | 19 | tested-with: GHC==7.10 |
20 | 20 | ||
21 | cabal-version: >=1.8 | 21 | cabal-version: >=1.8 |
22 | 22 | ||
diff --git a/packages/base/src/Internal/C/vector-aux.c b/packages/base/src/Internal/C/vector-aux.c index 9dbf536..1cef27d 100644 --- a/packages/base/src/Internal/C/vector-aux.c +++ b/packages/base/src/Internal/C/vector-aux.c | |||
@@ -945,6 +945,8 @@ int vectorScan(char * file, int* n, double**pp){ | |||
945 | /* Windows use thread-safe random | 945 | /* Windows use thread-safe random |
946 | See: http://stackoverflow.com/questions/143108/is-windows-rand-s-thread-safe | 946 | See: http://stackoverflow.com/questions/143108/is-windows-rand-s-thread-safe |
947 | */ | 947 | */ |
948 | #if defined (__APPLE__) || (__FreeBSD__) | ||
949 | |||
948 | inline double urandom() { | 950 | inline double urandom() { |
949 | /* the probalility of matching will be theoretically p^3(in fact, it is not) | 951 | /* the probalility of matching will be theoretically p^3(in fact, it is not) |
950 | p is matching probalility of random(). | 952 | p is matching probalility of random(). |
@@ -959,6 +961,22 @@ inline double urandom() { | |||
959 | return (double)nrand48(state) / (double)max_random; | 961 | return (double)nrand48(state) / (double)max_random; |
960 | } | 962 | } |
961 | 963 | ||
964 | #else | ||
965 | |||
966 | #define _CRT_RAND_S | ||
967 | inline double urandom() { | ||
968 | unsigned int number; | ||
969 | errno_t err; | ||
970 | err = rand_s(&number); | ||
971 | if (err!=0) { | ||
972 | printf("something wrong\n"); | ||
973 | return -1; | ||
974 | } | ||
975 | return (double)number / (double)UINT_MAX; | ||
976 | } | ||
977 | |||
978 | #endif | ||
979 | |||
962 | double gaussrand(int *phase, double *pV1, double *pV2, double *pS) | 980 | double gaussrand(int *phase, double *pV1, double *pV2, double *pS) |
963 | { | 981 | { |
964 | double V1=*pV1, V2=*pV2, S=*pS; | 982 | double V1=*pV1, V2=*pV2, S=*pS; |
@@ -985,6 +1003,35 @@ double gaussrand(int *phase, double *pV1, double *pV2, double *pS) | |||
985 | 1003 | ||
986 | } | 1004 | } |
987 | 1005 | ||
1006 | #if defined(_WIN32) || defined(WIN32) | ||
1007 | |||
1008 | int random_vector(unsigned int seed, int code, DVEC(r)) { | ||
1009 | int phase = 0; | ||
1010 | double V1,V2,S; | ||
1011 | |||
1012 | srand(seed); | ||
1013 | |||
1014 | int k; | ||
1015 | switch (code) { | ||
1016 | case 0: { // uniform | ||
1017 | for (k=0; k<rn; k++) { | ||
1018 | rp[k] = urandom(); | ||
1019 | } | ||
1020 | OK | ||
1021 | } | ||
1022 | case 1: { // gaussian | ||
1023 | for (k=0; k<rn; k++) { | ||
1024 | rp[k] = gaussrand(&phase,&V1,&V2,&S); | ||
1025 | } | ||
1026 | OK | ||
1027 | } | ||
1028 | |||
1029 | default: ERROR(BAD_CODE); | ||
1030 | } | ||
1031 | } | ||
1032 | |||
1033 | #else | ||
1034 | |||
988 | int random_vector(unsigned int seed, int code, DVEC(r)) { | 1035 | int random_vector(unsigned int seed, int code, DVEC(r)) { |
989 | int phase = 0; | 1036 | int phase = 0; |
990 | double V1,V2,S; | 1037 | double V1,V2,S; |
@@ -1010,6 +1057,8 @@ int random_vector(unsigned int seed, int code, DVEC(r)) { | |||
1010 | } | 1057 | } |
1011 | } | 1058 | } |
1012 | 1059 | ||
1060 | #endif | ||
1061 | |||
1013 | #else | 1062 | #else |
1014 | 1063 | ||
1015 | inline double urandom(struct random_data * buffer) { | 1064 | inline double urandom(struct random_data * buffer) { |