Mercurial > hg > octave-nkf
changeset 3962:e39b0ee1da6c
[project @ 2002-06-27 14:14:08 by jwe]
author | jwe |
---|---|
date | Thu, 27 Jun 2002 14:14:09 +0000 |
parents | 635209a37bf4 |
children | 05485f532599 |
files | scripts/ChangeLog scripts/statistics/distributions/gamma_pdf.m src/ChangeLog src/ov-mapper.cc src/pt-unop.cc |
diffstat | 5 files changed, 102 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2002-06-27 Paul Kienzle <pkienzle@jazz.ncnr.nist.gov> + + * statistics/distributions/gamma_pdf.m: Avoid overflow in more cases. + 2002-05-01 John W. Eaton <jwe@bevo.che.wisc.edu> * skip-autoheader: New file, for autogen.sh.
--- a/scripts/statistics/distributions/gamma_pdf.m +++ b/scripts/statistics/distributions/gamma_pdf.m @@ -50,12 +50,18 @@ pdf (k) = NaN * ones (length (k), 1); endif - k = find ((x > 0) & (a > 0) & (b > 0)); + k = find ((x > 0) & (a > 0) & (a <= 1) & (b > 0)); if (any (k)) pdf(k) = ((b(k) .^ a(k)) .* (x(k) .^ (a(k) - 1)) .* exp(-b(k) .* x(k)) ./ gamma (a(k))); endif + k = find ((x > 0) & (a > 1) & (b > 0)); + if (any (k)) + pdf(k) = exp (a(k) .* log (b(k)) + (a(k)-1) .* log (x(k)) + - b(k) .* x(k) - lgamma (a(k))); + endif + pdf = reshape (pdf, r, c); endfunction
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ +2002-06-26 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov-mapper.cc (MAPPER_LOOP, MAPPER_LOOP_1, MAPPER_LOOP_2): New macros. + (octave_mapper::apply): Use them to inline the mapper loops. + + * pt-unop.cc (tree_prefix_expression::rvalue): Ensure that the + operand is defined for op_incr and op_decr. + (tree_postfix_expression::rvalue): Likewise. + From Ben Sapp <bsapp@lanl.gov>. + +2002-06-25 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov-mapper.cc (octave_mapper::apply): Exit loops on error. + +2002-06-03 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov-struct.cc (octave_struct::print_raw): Print field names with + data types if Vstruct_levels_to_print is 0. + (octave_struct::print_name_tag): Don't emit newline if + Vstruct_levels_to_print is negative. + * ov.cc (struct_levels_to_print): Allow negative values too. + 2002-05-24 John W. Eaton <jwe@bevo.che.wisc.edu> * DLD-FUNCTIONS/lsode.cc (Flsode): Also return istate and error
--- a/src/ov-mapper.cc +++ b/src/ov-mapper.cc @@ -67,6 +67,39 @@ return false; } +// In most cases, we could use the map member function from the Matrix +// classes, but as currently implemented, they don't allow us to +// detect errors and abort properly. So use these macros to do the +// looping here instead. + +#define MAPPER_LOOP_2(T, F, M, CONV, R) \ + do \ + { \ + int nr = M.rows (); \ + int nc = M.cols (); \ + \ + T result (nr, nc); \ + \ + for (int j = 0; j < nc; j++) \ + { \ + for (int i = 0; i < nr; i++) \ + { \ + result (i, j) = CONV (F (M (i, j))); \ + \ + if (error_state) \ + return retval; \ + } \ + } \ + retval = R; \ + } \ + while (0) + +#define MAPPER_LOOP_1(T, F, M, CONV) \ + MAPPER_LOOP_2 (T, F, M, CONV, result) + +#define MAPPER_LOOP(T, F, M) \ + MAPPER_LOOP_1 (T, F, M, ) + octave_value octave_mapper::apply (const octave_value& arg) const { @@ -84,49 +117,19 @@ if (! error_state) { - int nr = chm.rows (); - int nc = chm.cols (); - switch (flag) { case 0: - { - boolMatrix result (nr, nc); - - // islapha and friends can return any nonzero value - // to mean true, but we want to return true or - // false only. - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - result (i, j) = ch_map_fcn (chm (i, j)) ? true : false; - - retval = result; - } + MAPPER_LOOP_1 (boolMatrix, ch_map_fcn, chm, bool); break; case 1: - { - Matrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - result (i, j) = ch_map_fcn (chm (i, j)); - - retval = result; - } + MAPPER_LOOP (Matrix, ch_map_fcn, chm); break; case 2: - { - charMatrix result (nr, nc); - - for (int j = 0; j < nc; j++) - for (int i = 0; i < nr; i++) - result (i, j) = ch_map_fcn (chm (i, j)); - - retval = octave_value (result, true); - } + MAPPER_LOOP_2 (charMatrix, ch_map_fcn, chm, , + octave_value (result, true)); break; default: @@ -172,18 +175,15 @@ || any_element_greater_than (m, upper_limit))) { if (c_c_map_fcn) - { - ComplexMatrix cm (m); - retval = cm.map (c_c_map_fcn); - } + MAPPER_LOOP (ComplexMatrix, c_c_map_fcn, m); else error ("%s: unable to handle real arguments", name().c_str ()); } else if (d_d_map_fcn) - retval = m.map (d_d_map_fcn); + MAPPER_LOOP (Matrix, d_d_map_fcn, m); else if (d_b_map_fcn) - retval = m.map (d_b_map_fcn); + MAPPER_LOOP (boolMatrix, d_b_map_fcn, m); else error ("%s: unable to handle real arguments", name().c_str ()); @@ -213,11 +213,11 @@ return retval; if (d_c_map_fcn) - retval = cm.map (d_c_map_fcn); + MAPPER_LOOP (Matrix, d_c_map_fcn, cm); else if (c_c_map_fcn) - retval = cm.map (c_c_map_fcn); + MAPPER_LOOP (ComplexMatrix, c_c_map_fcn, cm); else if (c_b_map_fcn) - retval = cm.map (c_b_map_fcn); + MAPPER_LOOP (boolMatrix, c_b_map_fcn, cm); else error ("%s: unable to handle complex arguments", name().c_str ());
--- a/src/pt-unop.cc +++ b/src/pt-unop.cc @@ -74,15 +74,20 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - octave_lvalue ref = op->lvalue (); + op->rvalue (); + + if (! error_state) + { + octave_lvalue ref = op->lvalue (); - if (error_state) - eval_error (); - else if (ref.is_defined ()) - { - ref.do_unary_op (etype); + if (! error_state && ref.is_defined ()) + { + ref.do_unary_op (etype); - retval = ref.value (); + retval = ref.value (); + } + else + eval_error (); } else eval_error (); @@ -91,9 +96,7 @@ { octave_value val = op->rvalue (); - if (error_state) - eval_error (); - else if (val.is_defined ()) + if (! error_state && val.is_defined ()) { retval = ::do_unary_op (etype, val); @@ -155,15 +158,20 @@ { if (etype == octave_value::op_incr || etype == octave_value::op_decr) { - octave_lvalue ref = op->lvalue (); + op->rvalue (); + + if (! error_state) + { + octave_lvalue ref = op->lvalue (); - if (error_state) - eval_error (); - else if (ref.is_defined ()) - { - retval = ref.value (); + if (! error_state && ref.is_defined ()) + { + retval = ref.value (); - ref.do_unary_op (etype); + ref.do_unary_op (etype); + } + else + eval_error (); } else eval_error (); @@ -172,9 +180,7 @@ { octave_value val = op->rvalue (); - if (error_state) - eval_error (); - else if (val.is_defined ()) + if (! error_state && val.is_defined ()) { retval = ::do_unary_op (etype, val);