Mercurial > hg > octave-nkf
changeset 8553:c7ff200e45f5
optimize range-scalar ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 21 Jan 2009 15:50:34 +0100 |
parents | 3591fe09f3b1 |
children | 8cd2277569c0 |
files | liboctave/ChangeLog liboctave/Range.cc liboctave/Range.h src/ChangeLog src/OPERATORS/op-range.cc |
diffstat | 5 files changed, 72 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,14 @@ +2009-01-21 Jaroslav Hajek <highegg@gmail.com> + + * Range.cc ( operator + (double x, const Range& r), + operator + (const Range& r, double x), + operator - (double x, const Range& r), + operator - (const Range& r, double x), + operator * (double x, const Range& r), + operator * (const Range& r, double x)): New operators. + * Range.h: Declare them. + + 2009-01-20 John W. Eaton <jwe@octave.org> * file-stat.h, file-stat.cc (class base_file_stat): New base class.
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -294,6 +294,37 @@ return Range (-r.base (), -r.limit (), -r.inc ()); } +Range operator + (double x, const Range& r) +{ + return Range (x + r.base (), x + r.limit (), r.inc ()); +} + +Range operator + (const Range& r, double x) +{ + return Range (r.base () + x, r.limit () + x, r.inc ()); +} + +Range operator - (double x, const Range& r) +{ + return Range (x - r.base (), x - r.limit (), -r.inc ()); +} + +Range operator - (const Range& r, double x) +{ + return Range (r.base () - x, r.limit () - x, r.inc ()); +} + +Range operator * (double x, const Range& r) +{ + return Range (x * r.base (), x * r.limit (), x * r.inc ()); +} + +Range operator * (const Range& r, double x) +{ + return Range (r.base () * x, r.limit () * x, r.inc () * x); +} + + // C See Knuth, Art Of Computer Programming, Vol. 1, Problem 1.2.4-5. // C // C===Tolerant FLOOR function.
--- a/liboctave/Range.h +++ b/liboctave/Range.h @@ -121,6 +121,18 @@ extern OCTAVE_API Range operator - (const Range& r); +extern OCTAVE_API Range operator + (double x, const Range& r); + +extern OCTAVE_API Range operator + (const Range& r, double x); + +extern OCTAVE_API Range operator - (double x, const Range& r); + +extern OCTAVE_API Range operator - (const Range& r, double x); + +extern OCTAVE_API Range operator * (double x, const Range& r); + +extern OCTAVE_API Range operator * (const Range& r, double x); + #endif /*
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2009-01-21 Jaroslav Hajek <highegg@gmail.com> + + * OPERATORS/op-range.cc: Define & register range-scalar ops. + 2009-01-21 Jaroslav Hajek <highegg@gmail.com> * ov.h (octave_value::subsref (..., bool auto_add)): New method.
--- a/src/OPERATORS/op-range.cc +++ b/src/OPERATORS/op-range.cc @@ -60,6 +60,13 @@ return octave_value (v.matrix_value().transpose ()); } +DEFBINOP_OP (addrs, range, scalar, +) +DEFBINOP_OP (addsr, scalar, range, +) +DEFBINOP_OP (subrs, range, scalar, -) +DEFBINOP_OP (subsr, scalar, range, -) +DEFBINOP_OP (mulrs, range, scalar, *) +DEFBINOP_OP (mulsr, scalar, range, *) + DEFNDCATOP_FN (r_r, range, range, array, array, concat) DEFNDCATOP_FN (r_s, range, scalar, array, array, concat) DEFNDCATOP_FN (r_m, range, matrix, array, array, concat) @@ -99,6 +106,13 @@ INSTALL_UNOP (op_transpose, octave_range, transpose); INSTALL_UNOP (op_hermitian, octave_range, transpose); + INSTALL_BINOP (op_add, octave_range, octave_scalar, addrs); + INSTALL_BINOP (op_add, octave_scalar, octave_range, addsr); + INSTALL_BINOP (op_sub, octave_range, octave_scalar, subrs); + INSTALL_BINOP (op_sub, octave_scalar, octave_range, subsr); + INSTALL_BINOP (op_mul, octave_range, octave_scalar, mulrs); + INSTALL_BINOP (op_mul, octave_scalar, octave_range, mulsr); + INSTALL_CATOP (octave_range, octave_range, r_r); INSTALL_CATOP (octave_range, octave_scalar, r_s); INSTALL_CATOP (octave_range, octave_matrix, r_m);