Mercurial > hg > octave-terminal
changeset 8983:e781ab1aee39
optimize comparison ops
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 15 Mar 2009 00:38:41 +0100 |
parents | dc6bda6f9994 |
children | cda45dc441f7 |
files | liboctave/ChangeLog liboctave/mx-op-defs.h |
diffstat | 2 files changed, 31 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,7 +1,8 @@ 2009-03-14 Jaroslav Hajek <highegg@gmail.com> - * mx-op-decl.h (*BOOL_OP_DECLS): Support compound binary ops. - * mx-op-defs.h (*BOOL_OP): Ditto. Optimize. + * mx-op-decl.h (NDS_BOOL_OP_DECLS, SND_BOOL_OP_DECLS, NDND_BOOL_OP_DECLS): Support compound binary ops. + * mx-op-defs.h (NDS_BOOL_OPS, SND_BOOL_OPS, NDND_BOOL_OPS): Ditto. Optimize. + * mx-op-defs.h (NDS_CMP_OP, SND_CMP_OP, NDND_CMP_OP): Optimize. 2009-03-14 Jaroslav Hajek <highegg@gmail.com>
--- a/liboctave/mx-op-defs.h +++ b/liboctave/mx-op-defs.h @@ -424,14 +424,20 @@ boolNDArray \ F (const ND& m, const S& s) \ { \ - boolNDArray r; \ + boolNDArray r (m.dims ()); \ \ octave_idx_type len = m.length (); \ \ - r.resize (m.dims ()); \ - \ - for (octave_idx_type i = 0; i < len; i++) \ - r.elem(i) = NDC (m.elem(i)) OP SC (s); \ + if (s == S ()) \ + { \ + for (octave_idx_type i = 0; i < len; i++) \ + r.xelem(i) = NDC (m.elem(i)) OP SC (S ()); \ + } \ + else \ + { \ + for (octave_idx_type i = 0; i < len; i++) \ + r.xelem(i) = NDC (m.elem(i)) OP SC (s); \ + } \ \ return r; \ } @@ -448,12 +454,10 @@ boolNDArray \ F (const ND& m, const S& s) \ { \ - boolNDArray r; \ + boolNDArray r (m.dims ()); \ \ octave_idx_type len = m.length (); \ \ - r.resize (m.dims ()); \ - \ for (octave_idx_type i = 0; i < len; i++) \ r.elem(i) = operator OP <SPEC> (NDC (m.elem(i)), SC (s)); \ \ @@ -555,14 +559,20 @@ boolNDArray \ F (const S& s, const ND& m) \ { \ - boolNDArray r; \ + boolNDArray r (m.dims ()); \ \ octave_idx_type len = m.length (); \ \ - r.resize (m.dims ()); \ - \ - for (octave_idx_type i = 0; i < len; i++) \ - r.elem(i) = SC (s) OP NDC (m.elem(i)); \ + if (s == S ()) \ + { \ + for (octave_idx_type i = 0; i < len; i++) \ + r.xelem(i) = SC (S ()) OP NDC (m.elem(i)); \ + } \ + else \ + { \ + for (octave_idx_type i = 0; i < len; i++) \ + r.xelem(i) = SC (s) OP NDC (m.elem(i)); \ + } \ \ return r; \ } @@ -579,12 +589,10 @@ boolNDArray \ F (const S& s, const ND& m) \ { \ - boolNDArray r; \ + boolNDArray r (m.dims ()); \ \ octave_idx_type len = m.length (); \ \ - r.resize (m.dims ()); \ - \ for (octave_idx_type i = 0; i < len; i++) \ r.elem(i) = operator OP <SPEC> (SC (s), NDC (m.elem(i))); \ \ @@ -603,12 +611,10 @@ boolNDArray \ F (const S& s, const ND& m) \ { \ - boolNDArray r; \ + boolNDArray r (m.dims ()); \ \ octave_idx_type len = m.length (); \ \ - r.resize (m.dims ()); \ - \ for (octave_idx_type i = 0; i < len; i++) \ r.elem(i) = operator OP <SPEC1, SPEC2> (SC (s), NDC (m.elem(i))); \ \ @@ -675,7 +681,7 @@ gripe_nonconformant (#OP, m1_dims, m2_dims); \ else \ { \ - r.resize (m1_dims); \ + r = R (m1_dims); \ \ octave_idx_type len = m1.length (); \ \ @@ -703,10 +709,10 @@ \ if (m1_dims == m2_dims) \ { \ - r.resize (m1_dims); \ + r = boolNDArray (m1_dims); \ \ for (octave_idx_type i = 0; i < m1.length (); i++) \ - r.elem(i) = C1 (m1.elem(i)) OP C2 (m2.elem(i)); \ + r.xelem(i) = C1 (m1.elem(i)) OP C2 (m2.elem(i)); \ } \ else \ gripe_nonconformant (#F, m1_dims, m2_dims); \