# HG changeset patch # User David Bateman # Date 1276723678 -7200 # Node ID 92a85ed5b86ecd0ee01099f0c83de701c8e0df55 # Parent 2786b7ae3f80b345adc8cd098a603dec9b81ab80 Don't special case color_property type when emitting factory default (bug #30118) diff -r 2786b7ae3f80 -r 92a85ed5b86e liboctave/oct-rand.cc --- a/liboctave/oct-rand.cc Wed Jun 16 14:36:23 2010 +0200 +++ b/liboctave/oct-rand.cc Wed Jun 16 23:27:58 2010 +0200 @@ -165,6 +165,13 @@ F77_FUNC (setsd, SETSD) (i0, i1); } +void +octave_rand::do_reset (void) +{ + use_old_generators = true; + initialize_ranlib_generators (); +} + ColumnVector octave_rand::do_state (const std::string& d) { @@ -193,6 +200,27 @@ rand_states[old_dist] = saved_state; } +void +octave_rand::do_reset (const std::string& d) +{ + use_old_generators = false; + + int old_dist = current_distribution; + + int new_dist = d.empty () ? current_distribution : get_dist_id (d); + + ColumnVector saved_state; + + if (old_dist != new_dist) + saved_state = get_internal_state (); + + oct_init_by_entropy (); + rand_states[new_dist] = get_internal_state (); + + if (old_dist != new_dist) + rand_states[old_dist] = saved_state; +} + std::string octave_rand::do_distribution (void) { diff -r 2786b7ae3f80 -r 92a85ed5b86e liboctave/oct-rand.h --- a/liboctave/oct-rand.h Wed Jun 16 14:36:23 2010 +0200 +++ b/liboctave/oct-rand.h Wed Jun 16 23:27:58 2010 +0200 @@ -58,6 +58,13 @@ instance->do_seed (s); } + // Reset the seed. + static void reset (void) + { + if (instance_ok ()) + instance->do_reset (); + } + // Return the current state. static ColumnVector state (const std::string& d = std::string ()) { @@ -72,6 +79,13 @@ instance->do_state (s, d); } + // Reset the current state/ + static void reset (const std::string& d) + { + if (instance_ok ()) + instance->do_reset (d); + } + // Return the current distribution. static std::string distribution (void) { @@ -172,12 +186,18 @@ // Set the seed. void do_seed (double s); + // Reset the seed. + void do_reset (); + // Return the current state. ColumnVector do_state (const std::string& d); // Set the current state/ void do_state (const ColumnVector &s, const std::string& d); + // Reset the current state/ + void do_reset (const std::string& d); + // Return the current distribution. std::string do_distribution (void); diff -r 2786b7ae3f80 -r 92a85ed5b86e src/ChangeLog --- a/src/ChangeLog Wed Jun 16 14:36:23 2010 +0200 +++ b/src/ChangeLog Wed Jun 16 23:27:58 2010 +0200 @@ -1,3 +1,8 @@ +2010-06-11 David Bateman + + * genprops.awk : Don't special case the color_property in the + factory default methods. + 2010-06-16 Jaroslav Hajek * data.cc (Fsort): Fix invalid tests. diff -r 2786b7ae3f80 -r 92a85ed5b86e src/DLD-FUNCTIONS/rand.cc --- a/src/DLD-FUNCTIONS/rand.cc Wed Jun 16 14:36:23 2010 +0200 +++ b/src/DLD-FUNCTIONS/rand.cc Wed Jun 16 23:27:58 2010 +0200 @@ -243,16 +243,25 @@ if (! error_state) octave_rand::seed (d); } + else if (args(idx+1).is_string () + && args(idx+1).string_value() == "reset") + octave_rand::reset (); else error ("%s: seed must be a real scalar", fcn); } else if (ts == "state" || ts == "twister") { - ColumnVector s = - ColumnVector (args(idx+1).vector_value(false, true)); + if (args(idx+1).is_string () + && args(idx+1).string_value() == "reset") + octave_rand::reset (fcn); + else + { + ColumnVector s = + ColumnVector (args(idx+1).vector_value(false, true)); - if (! error_state) - octave_rand::state (s, fcn); + if (! error_state) + octave_rand::state (s, fcn); + } } else error ("%s: unrecognized string argument", fcn); @@ -314,7 +323,9 @@ @deftypefn {Loadable Function} {} rand (@var{x})\n\ @deftypefnx {Loadable Function} {} rand (@var{n}, @var{m})\n\ @deftypefnx {Loadable Function} {} rand (\"state\", @var{x})\n\ +@deftypefnx {Loadable Function} {} rand (\"state\", \"reset\")\n\ @deftypefnx {Loadable Function} {} rand (\"seed\", @var{x})\n\ +@deftypefnx {Loadable Function} {} rand (\"seed\", \"reset\")\n\ Return a matrix with random elements uniformly distributed on the\n\ interval (0, 1). The arguments are handled the same as the arguments\n\ for @code{eye}.\n\ @@ -376,6 +387,9 @@ @code{rand} to use the old generators, only setting the seed will.\n\ To cause @code{rand} to once again use the new generators, the\n\ keyword \"state\" should be used to reset the state of the @code{rand}.\n\ +\n\ +The state or seed of the generator can be reset to a new random value\n\ +using the \"reset\" keyword.\n\ @seealso{randn, rande, randg, randp}\n\ @end deftypefn") { @@ -474,7 +488,9 @@ @deftypefn {Loadable Function} {} randn (@var{x})\n\ @deftypefnx {Loadable Function} {} randn (@var{n}, @var{m})\n\ @deftypefnx {Loadable Function} {} randn (\"state\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randn (\"state\", \"reset\")\n\ @deftypefnx {Loadable Function} {} randn (\"seed\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randn (\"seed\", \"reset\")\n\ Return a matrix with normally distributed random\n\ elements having zero mean and variance one. The arguments are\n\ handled the same as the arguments for @code{rand}.\n\ @@ -547,7 +563,9 @@ @deftypefn {Loadable Function} {} rande (@var{x})\n\ @deftypefnx {Loadable Function} {} rande (@var{n}, @var{m})\n\ @deftypefnx {Loadable Function} {} rande (\"state\", @var{x})\n\ +@deftypefnx {Loadable Function} {} rande (\"state\", \"reset\")\n\ @deftypefnx {Loadable Function} {} rande (\"seed\", @var{x})\n\ +@deftypefnx {Loadable Function} {} rande (\"seed\", \"reset\")\n\ Return a matrix with exponentially distributed random elements. The\n\ arguments are handled the same as the arguments for @code{rand}.\n\ \n\ @@ -620,7 +638,9 @@ @deftypefn {Loadable Function} {} randg (@var{a}, @var{x})\n\ @deftypefnx {Loadable Function} {} randg (@var{a}, @var{n}, @var{m})\n\ @deftypefnx {Loadable Function} {} randg (\"state\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randg (\"state\", \"reset\")\n\ @deftypefnx {Loadable Function} {} randg (\"seed\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randg (\"seed\", \"reset\")\n\ Return a matrix with @code{gamma(@var{a},1)} distributed random elements.\n\ The arguments are handled the same as the arguments for @code{rand},\n\ except for the argument @var{a}.\n\ @@ -870,7 +890,9 @@ @deftypefn {Loadable Function} {} randp (@var{l}, @var{x})\n\ @deftypefnx {Loadable Function} {} randp (@var{l}, @var{n}, @var{m})\n\ @deftypefnx {Loadable Function} {} randp (\"state\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randp (\"state\", \"reset\")\n\ @deftypefnx {Loadable Function} {} randp (\"seed\", @var{x})\n\ +@deftypefnx {Loadable Function} {} randp (\"seed\", \"reset\")\n\ Return a matrix with Poisson distributed random elements with mean value\n\ parameter given by the first argument, @var{l}. The arguments\n\ are handled the same as the arguments for @code{rand}, except for the\n\ diff -r 2786b7ae3f80 -r 92a85ed5b86e src/genprops.awk --- a/src/genprops.awk Wed Jun 16 14:36:23 2010 +0200 +++ b/src/genprops.awk Wed Jun 16 23:27:58 2010 +0200 @@ -559,7 +559,7 @@ if (factory[i]) { dval = defval[i]; - if (type[i] == "radio_property" || type[i] == "color_property") + if (type[i] == "radio_property") { k = index (dval, "{"); dval = substr (dval, k+1);