root/ext/mt-random/mt-lib.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mt_lib_mt_random_set_seedX
  2. mt_lib_mt_random_get_state
  3. mt_lib_mt_random_set_stateX
  4. mt_lib_mt_random_real
  5. mt_lib_mt_random_real0
  6. mt_lib__25mt_random_integer
  7. mt_lib__25mt_random_uint32
  8. mt_lib_mt_random_fill_u32vectorX
  9. mt_lib_mt_random_fill_f32vectorX
  10. mt_lib_mt_random_fill_f64vectorX
  11. Scm_Init_mt_lib

   1 /* Generated by genstub.  Do not edit. */
   2 #include <gauche.h>
   3 #if defined(__CYGWIN__) || defined(__MINGW32__)
   4 #define SCM_CGEN_CONST /*empty*/
   5 #else
   6 #define SCM_CGEN_CONST const
   7 #endif
   8 
   9 #include "mt-random.h"
  10 
  11 static ScmObj mt_lib_mt_random_set_seedX(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  12 {
  13   ScmObj mt_scm;
  14   ScmMersenneTwister* mt;
  15   ScmObj init_scm;
  16   ScmObj init;
  17   SCM_ENTER_SUBR("mt-random-set-seed!");
  18   mt_scm = SCM_ARGREF(0);
  19   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
  20   mt = SCM_MERSENNE_TWISTER(mt_scm);
  21   init_scm = SCM_ARGREF(1);
  22   init = (init_scm);
  23   {
  24 if (SCM_INTP(init)) {
  25     Scm_MTInitByUI(mt, Scm_GetUInteger(init));
  26   } else if (SCM_BIGNUMP(init)) {
  27     int i; unsigned long s = 0;
  28     for (i=0; i<SCM_BIGNUM_SIZE(init); i++) {
  29       s ^= SCM_BIGNUM(init)->values[i];
  30     }
  31     Scm_MTInitByUI(mt, s);
  32   } else if (SCM_U32VECTORP(init)) {
  33     Scm_MTInitByArray(mt, (ScmInt32*)SCM_U32VECTOR_ELEMENTS(init), SCM_U32VECTOR_SIZE(init));
  34   } else {
  35     Scm_Error("bad random seed: must be an exact integer or u32vector, but got %S", init);
  36   }
  37   SCM_RETURN(SCM_UNDEFINED);
  38   }
  39 }
  40 
  41 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_set_seedX__NAME, "mt-random-set-seed!", 19, 19);
  42 static SCM_DEFINE_SUBR(mt_lib_mt_random_set_seedX__STUB, 2, 0, SCM_OBJ(&mt_lib_mt_random_set_seedX__NAME), mt_lib_mt_random_set_seedX, NULL, NULL);
  43 
  44 static ScmObj mt_lib_mt_random_get_state(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  45 {
  46   ScmObj mt_scm;
  47   ScmMersenneTwister* mt;
  48   SCM_ENTER_SUBR("mt-random-get-state");
  49   mt_scm = SCM_ARGREF(0);
  50   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
  51   mt = SCM_MERSENNE_TWISTER(mt_scm);
  52   {
  53 
  54    ScmObj v = Scm_MakeU32Vector(N+1, 0);
  55    int i;
  56    for (i=0; i<N; i++) SCM_U32VECTOR_ELEMENTS(v)[i] = mt->mt[i];
  57    SCM_U32VECTOR_ELEMENTS(v)[N] = mt->mti;
  58    SCM_RETURN(v);
  59    
  60   }
  61 }
  62 
  63 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_get_state__NAME, "mt-random-get-state", 19, 19);
  64 static SCM_DEFINE_SUBR(mt_lib_mt_random_get_state__STUB, 1, 0, SCM_OBJ(&mt_lib_mt_random_get_state__NAME), mt_lib_mt_random_get_state, NULL, NULL);
  65 
  66 static ScmObj mt_lib_mt_random_set_stateX(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  67 {
  68   ScmObj mt_scm;
  69   ScmMersenneTwister* mt;
  70   ScmObj state_scm;
  71   ScmU32Vector* state;
  72   SCM_ENTER_SUBR("mt-random-set-state!");
  73   mt_scm = SCM_ARGREF(0);
  74   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
  75   mt = SCM_MERSENNE_TWISTER(mt_scm);
  76   state_scm = SCM_ARGREF(1);
  77   if (!SCM_U32VECTORP(state_scm)) Scm_Error("<u32vector> required, but got %S", state_scm);
  78   state = SCM_U32VECTOR(state_scm);
  79   {
  80 int i;
  81   if (SCM_U32VECTOR_SIZE(state) != N+1) {
  82     Scm_Error("u32vector of length %d is required, but got length %d", N+1, SCM_U32VECTOR_SIZE(state));
  83   }
  84   for (i=0; i<N; i++) mt->mt[i] = SCM_U32VECTOR_ELEMENTS(state)[i];
  85   mt->mti = SCM_U32VECTOR_ELEMENTS(state)[N];
  86   SCM_RETURN(SCM_UNDEFINED);
  87   }
  88 }
  89 
  90 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_set_stateX__NAME, "mt-random-set-state!", 20, 20);
  91 static SCM_DEFINE_SUBR(mt_lib_mt_random_set_stateX__STUB, 2, 0, SCM_OBJ(&mt_lib_mt_random_set_stateX__NAME), mt_lib_mt_random_set_stateX, NULL, NULL);
  92 
  93 static ScmObj mt_lib_mt_random_real(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  94 {
  95   ScmObj mt_scm;
  96   ScmMersenneTwister* mt;
  97   SCM_ENTER_SUBR("mt-random-real");
  98   mt_scm = SCM_ARGREF(0);
  99   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 100   mt = SCM_MERSENNE_TWISTER(mt_scm);
 101   {
 102 {
 103 double SCM_RESULT;
 104  SCM_RESULT = (Scm_MTGenrandF64(mt, TRUE));
 105 SCM_RETURN(Scm_MakeFlonum(SCM_RESULT));
 106 }
 107   }
 108 }
 109 
 110 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_real__NAME, "mt-random-real", 14, 14);
 111 static SCM_DEFINE_SUBR(mt_lib_mt_random_real__STUB, 1, 0, SCM_OBJ(&mt_lib_mt_random_real__NAME), mt_lib_mt_random_real, NULL, NULL);
 112 
 113 static ScmObj mt_lib_mt_random_real0(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 114 {
 115   ScmObj mt_scm;
 116   ScmMersenneTwister* mt;
 117   SCM_ENTER_SUBR("mt-random-real0");
 118   mt_scm = SCM_ARGREF(0);
 119   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 120   mt = SCM_MERSENNE_TWISTER(mt_scm);
 121   {
 122 {
 123 double SCM_RESULT;
 124  SCM_RESULT = (Scm_MTGenrandF64(mt, FALSE));
 125 SCM_RETURN(Scm_MakeFlonum(SCM_RESULT));
 126 }
 127   }
 128 }
 129 
 130 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_real0__NAME, "mt-random-real0", 15, 15);
 131 static SCM_DEFINE_SUBR(mt_lib_mt_random_real0__STUB, 1, 0, SCM_OBJ(&mt_lib_mt_random_real0__NAME), mt_lib_mt_random_real0, NULL, NULL);
 132 
 133 static ScmObj mt_lib__25mt_random_integer(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 134 {
 135   ScmObj mt_scm;
 136   ScmMersenneTwister* mt;
 137   ScmObj n_scm;
 138   ScmObj n;
 139   SCM_ENTER_SUBR("%mt-random-integer");
 140   mt_scm = SCM_ARGREF(0);
 141   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 142   mt = SCM_MERSENNE_TWISTER(mt_scm);
 143   n_scm = SCM_ARGREF(1);
 144   n = (n_scm);
 145   {
 146 {
 147 ScmObj SCM_RESULT;
 148 SCM_RESULT = Scm_MTGenrandInt(mt, n);
 149 SCM_RETURN(SCM_OBJ_SAFE(SCM_RESULT));
 150 }
 151   }
 152 }
 153 
 154 static SCM_DEFINE_STRING_CONST(mt_lib__25mt_random_integer__NAME, "%mt-random-integer", 18, 18);
 155 static SCM_DEFINE_SUBR(mt_lib__25mt_random_integer__STUB, 2, 0, SCM_OBJ(&mt_lib__25mt_random_integer__NAME), mt_lib__25mt_random_integer, NULL, NULL);
 156 
 157 static ScmObj mt_lib__25mt_random_uint32(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 158 {
 159   ScmObj mt_scm;
 160   ScmMersenneTwister* mt;
 161   SCM_ENTER_SUBR("%mt-random-uint32");
 162   mt_scm = SCM_ARGREF(0);
 163   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 164   mt = SCM_MERSENNE_TWISTER(mt_scm);
 165   {
 166 {
 167 u_long SCM_RESULT;
 168 SCM_RESULT = Scm_MTGenrandU32(mt);
 169 SCM_RETURN(Scm_MakeIntegerFromUI(SCM_RESULT));
 170 }
 171   }
 172 }
 173 
 174 static SCM_DEFINE_STRING_CONST(mt_lib__25mt_random_uint32__NAME, "%mt-random-uint32", 17, 17);
 175 static SCM_DEFINE_SUBR(mt_lib__25mt_random_uint32__STUB, 1, 0, SCM_OBJ(&mt_lib__25mt_random_uint32__NAME), mt_lib__25mt_random_uint32, NULL, NULL);
 176 
 177 static ScmObj mt_lib_mt_random_fill_u32vectorX(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 178 {
 179   ScmObj mt_scm;
 180   ScmMersenneTwister* mt;
 181   ScmObj v_scm;
 182   ScmU32Vector* v;
 183   SCM_ENTER_SUBR("mt-random-fill-u32vector!");
 184   mt_scm = SCM_ARGREF(0);
 185   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 186   mt = SCM_MERSENNE_TWISTER(mt_scm);
 187   v_scm = SCM_ARGREF(1);
 188   if (!SCM_U32VECTORP(v_scm)) Scm_Error("<u32vector> required, but got %S", v_scm);
 189   v = SCM_U32VECTOR(v_scm);
 190   {
 191  int len = SCM_U32VECTOR_SIZE(v), i;
 192   ScmUInt32 *p = SCM_U32VECTOR_ELEMENTS(v);
 193   for (i=0; i<len; i++) *p++ = Scm_MTGenrandU32(mt);
 194   SCM_RETURN(SCM_OBJ(v));
 195   }
 196 }
 197 
 198 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_fill_u32vectorX__NAME, "mt-random-fill-u32vector!", 25, 25);
 199 static SCM_DEFINE_SUBR(mt_lib_mt_random_fill_u32vectorX__STUB, 2, 0, SCM_OBJ(&mt_lib_mt_random_fill_u32vectorX__NAME), mt_lib_mt_random_fill_u32vectorX, NULL, NULL);
 200 
 201 static ScmObj mt_lib_mt_random_fill_f32vectorX(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 202 {
 203   ScmObj mt_scm;
 204   ScmMersenneTwister* mt;
 205   ScmObj v_scm;
 206   ScmF32Vector* v;
 207   SCM_ENTER_SUBR("mt-random-fill-f32vector!");
 208   mt_scm = SCM_ARGREF(0);
 209   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 210   mt = SCM_MERSENNE_TWISTER(mt_scm);
 211   v_scm = SCM_ARGREF(1);
 212   if (!SCM_F32VECTORP(v_scm)) Scm_Error("<f32vector> required, but got %S", v_scm);
 213   v = SCM_F32VECTOR(v_scm);
 214   {
 215  int len = SCM_F32VECTOR_SIZE(v), i;
 216   float *p = SCM_F32VECTOR_ELEMENTS(v);
 217   for (i=0; i<len; i++) *p++ = Scm_MTGenrandF32(mt, TRUE);
 218   SCM_RETURN(SCM_OBJ(v));
 219   }
 220 }
 221 
 222 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_fill_f32vectorX__NAME, "mt-random-fill-f32vector!", 25, 25);
 223 static SCM_DEFINE_SUBR(mt_lib_mt_random_fill_f32vectorX__STUB, 2, 0, SCM_OBJ(&mt_lib_mt_random_fill_f32vectorX__NAME), mt_lib_mt_random_fill_f32vectorX, NULL, NULL);
 224 
 225 static ScmObj mt_lib_mt_random_fill_f64vectorX(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
 226 {
 227   ScmObj mt_scm;
 228   ScmMersenneTwister* mt;
 229   ScmObj v_scm;
 230   ScmF64Vector* v;
 231   SCM_ENTER_SUBR("mt-random-fill-f64vector!");
 232   mt_scm = SCM_ARGREF(0);
 233   if (!SCM_MERSENNE_TWISTER_P(mt_scm)) Scm_Error("<mersenne-twister> required, but got %S", mt_scm);
 234   mt = SCM_MERSENNE_TWISTER(mt_scm);
 235   v_scm = SCM_ARGREF(1);
 236   if (!SCM_F64VECTORP(v_scm)) Scm_Error("<f64vector> required, but got %S", v_scm);
 237   v = SCM_F64VECTOR(v_scm);
 238   {
 239  int len = SCM_F64VECTOR_SIZE(v), i;
 240   double *p = SCM_F64VECTOR_ELEMENTS(v);
 241   for (i=0; i<len; i++) *p++ = Scm_MTGenrandF64(mt, TRUE);
 242   SCM_RETURN(SCM_OBJ(v));
 243   }
 244 }
 245 
 246 static SCM_DEFINE_STRING_CONST(mt_lib_mt_random_fill_f64vectorX__NAME, "mt-random-fill-f64vector!", 25, 25);
 247 static SCM_DEFINE_SUBR(mt_lib_mt_random_fill_f64vectorX__STUB, 2, 0, SCM_OBJ(&mt_lib_mt_random_fill_f64vectorX__NAME), mt_lib_mt_random_fill_f64vectorX, NULL, NULL);
 248 
 249 void Scm_Init_mt_lib(ScmModule *module)
 250 {
 251 
 252   SCM_DEFINE(module, "mt-random-fill-f64vector!", SCM_OBJ(&mt_lib_mt_random_fill_f64vectorX__STUB));
 253   SCM_DEFINE(module, "mt-random-fill-f32vector!", SCM_OBJ(&mt_lib_mt_random_fill_f32vectorX__STUB));
 254   SCM_DEFINE(module, "mt-random-fill-u32vector!", SCM_OBJ(&mt_lib_mt_random_fill_u32vectorX__STUB));
 255   SCM_DEFINE(module, "%mt-random-uint32", SCM_OBJ(&mt_lib__25mt_random_uint32__STUB));
 256   SCM_DEFINE(module, "%mt-random-integer", SCM_OBJ(&mt_lib__25mt_random_integer__STUB));
 257   SCM_DEFINE(module, "mt-random-real0", SCM_OBJ(&mt_lib_mt_random_real0__STUB));
 258   SCM_DEFINE(module, "mt-random-real", SCM_OBJ(&mt_lib_mt_random_real__STUB));
 259   SCM_DEFINE(module, "mt-random-set-state!", SCM_OBJ(&mt_lib_mt_random_set_stateX__STUB));
 260   SCM_DEFINE(module, "mt-random-get-state", SCM_OBJ(&mt_lib_mt_random_get_state__STUB));
 261   SCM_DEFINE(module, "mt-random-set-seed!", SCM_OBJ(&mt_lib_mt_random_set_seedX__STUB));
 262 }

/* [<][>][^][v][top][bottom][index][help] */