--- configure +++ configure @@ -28771,7 +28771,7 @@ ### Do the substitutions in all the Makefiles. -ac_config_files="$ac_config_files Makefile octMakefile Makeconf test/Makefile dlfcn/Makefile doc/Makefile doc/faq/Makefile doc/interpreter/Makefile doc/liboctave/Makefile doc/refcard/Makefile emacs/Makefile examples/Makefile liboctave/Makefile liboctave/oct-types.h src/Makefile libcruft/Makefile libcruft/Makerules libcruft/amos/Makefile libcruft/blas/Makefile libcruft/daspk/Makefile libcruft/dasrt/Makefile libcruft/dassl/Makefile libcruft/fftpack/Makefile libcruft/lapack/Makefile libcruft/minpack/Makefile libcruft/misc/Makefile libcruft/odepack/Makefile libcruft/ordered-qz/Makefile libcruft/quadpack/Makefile libcruft/ranlib/Makefile libcruft/slatec-fn/Makefile libcruft/slatec-err/Makefile libcruft/villad/Makefile libcruft/blas-xtra/Makefile libcruft/lapack-xtra/Makefile" +ac_config_files="$ac_config_files Makefile octMakefile Makeconf test/Makefile dlfcn/Makefile doc/Makefile doc/faq/Makefile doc/interpreter/Makefile doc/liboctave/Makefile doc/refcard/Makefile emacs/Makefile examples/Makefile liboctave/Makefile liboctave/oct-types.h src/Makefile libcruft/Makefile libcruft/Makerules libcruft/amos/Makefile libcruft/blas/Makefile libcruft/daspk/Makefile libcruft/dasrt/Makefile libcruft/dassl/Makefile libcruft/fftpack/Makefile libcruft/lapack/Makefile libcruft/minpack/Makefile libcruft/misc/Makefile libcruft/odepack/Makefile libcruft/ordered-qz/Makefile libcruft/quadpack/Makefile libcruft/slatec-fn/Makefile libcruft/slatec-err/Makefile libcruft/villad/Makefile libcruft/blas-xtra/Makefile libcruft/lapack-xtra/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -29356,7 +29356,6 @@ "libcruft/odepack/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/odepack/Makefile" ;; "libcruft/ordered-qz/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/ordered-qz/Makefile" ;; "libcruft/quadpack/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/quadpack/Makefile" ;; - "libcruft/ranlib/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/ranlib/Makefile" ;; "libcruft/slatec-fn/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/slatec-fn/Makefile" ;; "libcruft/slatec-err/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/slatec-err/Makefile" ;; "libcruft/villad/Makefile") CONFIG_FILES="$CONFIG_FILES libcruft/villad/Makefile" ;; --- libcruft/Makefile.in +++ libcruft/Makefile.in @@ -30,7 +30,7 @@ CRUFT_DIRS = amos @BLAS_DIR@ blas-xtra daspk dasrt dassl \ @FFT_DIR@ @LAPACK_DIR@ lapack-xtra minpack \ - misc odepack ordered-qz quadpack ranlib \ + misc odepack ordered-qz quadpack \ slatec-err slatec-fn villad SUBDIRS = $(CRUFT_DIRS) --- liboctave/oct-rand.cc +++ liboctave/oct-rand.cc @@ -50,39 +50,7 @@ static int current_distribution = uniform_dist; // Has the seed/state been set yet? -static bool old_initialized = false; static bool new_initialized = false; -static bool use_old_generators = false; - -extern "C" -{ - F77_RET_T - F77_FUNC (dgennor, DGENNOR) (const double&, const double&, double&); - - F77_RET_T - F77_FUNC (dgenunf, DGENUNF) (const double&, const double&, double&); - - F77_RET_T - F77_FUNC (dgenexp, DGENEXP) (const double&, double&); - - F77_RET_T - F77_FUNC (dignpoi, DIGNPOI) (const double&, double&); - - F77_RET_T - F77_FUNC (dgengam, DGENGAM) (const double&, const double&, double&); - - F77_RET_T - F77_FUNC (setall, SETALL) (const octave_idx_type&, const octave_idx_type&); - - F77_RET_T - F77_FUNC (getsd, GETSD) (octave_idx_type&, octave_idx_type&); - - F77_RET_T - F77_FUNC (setsd, SETSD) (const octave_idx_type&, const octave_idx_type&); - - F77_RET_T - F77_FUNC (setcgn, SETCGN) (const octave_idx_type&); -} static octave_idx_type force_to_fit_range (octave_idx_type i, octave_idx_type lo, octave_idx_type hi) @@ -104,97 +72,14 @@ // technique used below will cycle monthly, but it it does seem to // work ok to give fairly different seeds each time Octave starts. -static void -do_old_initialization (void) -{ - octave_localtime tm; - int stored_distribution = current_distribution; - F77_FUNC (setcgn, SETCGN) (uniform_dist); - - int hour = tm.hour() + 1; - int minute = tm.min() + 1; - int second = tm.sec() + 1; - - octave_idx_type s0 = tm.mday() * hour * minute * second; - octave_idx_type s1 = hour * minute * second; - - s0 = force_to_fit_range (s0, 1, 2147483563); - s1 = force_to_fit_range (s1, 1, 2147483399); - - F77_FUNC (setall, SETALL) (s0, s1); - F77_FUNC (setcgn, SETCGN) (stored_distribution); - - old_initialized = true; -} - static inline void maybe_initialize (void) { - if (use_old_generators) - { - if (! old_initialized) - do_old_initialization (); - } - else - { if (! new_initialized) { oct_init_by_entropy (); new_initialized = true; } - } -} - -double -octave_rand::seed (void) -{ - if (! old_initialized) - do_old_initialization (); - - union d2i { double d; octave_idx_type i[2]; }; - union d2i u; - - oct_mach_info::float_format ff = oct_mach_info::native_float_format (); - - switch (ff) - { - case oct_mach_info::flt_fmt_ieee_big_endian: - F77_FUNC (getsd, GETSD) (u.i[1], u.i[0]); - break; - default: - F77_FUNC (getsd, GETSD) (u.i[0], u.i[1]); - break; - } - - return u.d; -} - -void -octave_rand::seed (double s) -{ - use_old_generators = true; - maybe_initialize (); - - int i0, i1; - union d2i { double d; octave_idx_type i[2]; }; - union d2i u; - u.d = s; - - oct_mach_info::float_format ff = oct_mach_info::native_float_format (); - - switch (ff) - { - case oct_mach_info::flt_fmt_ieee_big_endian: - i1 = force_to_fit_range (u.i[0], 1, 2147483563); - i0 = force_to_fit_range (u.i[1], 1, 2147483399); - break; - default: - i0 = force_to_fit_range (u.i[0], 1, 2147483563); - i1 = force_to_fit_range (u.i[1], 1, 2147483399); - break; - } - - F77_FUNC (setsd, SETSD) (i0, i1); } ColumnVector @@ -217,7 +102,6 @@ void octave_rand::state (const ColumnVector &s) { - use_old_generators = false; maybe_initialize (); octave_idx_type len = s.length(); @@ -277,8 +161,6 @@ maybe_initialize (); current_distribution = uniform_dist; - - F77_FUNC (setcgn, SETCGN) (uniform_dist); } void @@ -287,8 +169,6 @@ maybe_initialize (); current_distribution = normal_dist; - - F77_FUNC (setcgn, SETCGN) (normal_dist); } void @@ -297,8 +177,6 @@ maybe_initialize (); current_distribution = expon_dist; - - F77_FUNC (setcgn, SETCGN) (expon_dist); } void @@ -307,8 +185,6 @@ maybe_initialize (); current_distribution = poisson_dist; - - F77_FUNC (setcgn, SETCGN) (poisson_dist); } void @@ -317,8 +193,6 @@ maybe_initialize (); current_distribution = gamma_dist; - - F77_FUNC (setcgn, SETCGN) (gamma_dist); } @@ -329,47 +203,6 @@ double retval = 0.0; - if (use_old_generators) - { - switch (current_distribution) - { - case uniform_dist: - F77_FUNC (dgenunf, DGENUNF) (0.0, 1.0, retval); - break; - - case normal_dist: - F77_FUNC (dgennor, DGENNOR) (0.0, 1.0, retval); - break; - - case expon_dist: - F77_FUNC (dgenexp, DGENEXP) (1.0, retval); - break; - - case poisson_dist: - if (a < 0.0 || xisnan(a) || xisinf(a)) - retval = octave_NaN; - else - { - // workaround bug in ignpoi, by calling with different Mu - F77_FUNC (dignpoi, DIGNPOI) (a + 1, retval); - F77_FUNC (dignpoi, DIGNPOI) (a, retval); - } - break; - - case gamma_dist: - if (a <= 0.0 || xisnan(a) || xisinf(a)) - retval = octave_NaN; - else - F77_FUNC (dgengam, DGENGAM) (1.0, a, retval); - break; - - default: - abort (); - break; - } - } - else - { switch (current_distribution) { case uniform_dist: @@ -396,24 +229,10 @@ abort (); break; } - } return retval; } -#define MAKE_RAND(len) \ - do \ - { \ - double val; \ - for (volatile octave_idx_type i = 0; i < len; i++) \ - { \ - OCTAVE_QUIT; \ - RAND_FUNC (val); \ - v[i] = val; \ - } \ - } \ - while (0) - static void fill_rand (octave_idx_type len, double *v, double a) { @@ -425,72 +244,22 @@ switch (current_distribution) { case uniform_dist: - if (use_old_generators) - { -#define RAND_FUNC(x) F77_FUNC (dgenunf, DGENUNF) (0.0, 1.0, x) - MAKE_RAND (len); -#undef RAND_FUNC - } - else oct_fill_randu (len, v); break; case normal_dist: - if (use_old_generators) - { -#define RAND_FUNC(x) F77_FUNC (dgennor, DGENNOR) (0.0, 1.0, x) - MAKE_RAND (len); -#undef RAND_FUNC - } - else oct_fill_randn (len, v); break; case expon_dist: - if (use_old_generators) - { -#define RAND_FUNC(x) F77_FUNC (dgenexp, DGENEXP) (1.0, x) - MAKE_RAND (len); -#undef RAND_FUNC - } - else oct_fill_rande (len, v); break; case poisson_dist: - if (use_old_generators) - { - if (a < 0.0 || xisnan(a) || xisinf(a)) -#define RAND_FUNC(x) x = octave_NaN; - MAKE_RAND (len); -#undef RAND_FUNC - else - { - // workaround bug in ignpoi, by calling with different Mu - double tmp; - F77_FUNC (dignpoi, DIGNPOI) (a + 1, tmp); -#define RAND_FUNC(x) F77_FUNC (dignpoi, DIGNPOI) (a, x) - MAKE_RAND (len); -#undef RAND_FUNC - } - } - else oct_fill_randp (a, len, v); break; case gamma_dist: - if (use_old_generators) - { - if (a <= 0.0 || xisnan(a) || xisinf(a)) -#define RAND_FUNC(x) x = octave_NaN; - MAKE_RAND (len); -#undef RAND_FUNC - else -#define RAND_FUNC(x) F77_FUNC (dgengam, DGENGAM) (1.0, a, x) - MAKE_RAND (len); -#undef RAND_FUNC - } - else oct_fill_randg (a, len, v); break; --- liboctave/oct-rand.h +++ liboctave/oct-rand.h @@ -34,12 +34,6 @@ OCTAVE_API octave_rand { - // Return the current seed. - static double seed (void); - - // Set the seed. - static void seed (double s); - // Return the current state. static ColumnVector state (void); --- src/DLD-FUNCTIONS/rand.cc +++ src/DLD-FUNCTIONS/rand.cc @@ -109,7 +109,8 @@ } else if (s_arg == "seed") { - retval = octave_rand::seed (); + retval = octave_rand::state (); + warning("do_rand(): using state() instead of removed seed()\n"); } else if (s_arg == "state" || s_arg == "twister") { @@ -236,10 +237,14 @@ { if (args(idx+1).is_real_scalar ()) { - double d = args(idx+1).double_value (); + ColumnVector s = + ColumnVector (args(idx+1).vector_value(false, true)); if (! error_state) - octave_rand::seed (d); + { + warning("do_rand(): using state() instead of seed()\n"); + octave_rand::state (s); + } } else error ("%s: seed must be a real scalar", fcn);