Mercurial > octave-libgccjit
changeset 8834:8dd69187c4a2
specialize sqrt for diagonal matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 20 Feb 2009 21:49:26 +0100 |
parents | b86b42f77899 |
children | 1685c61542f8 |
files | src/ChangeLog src/ov-base-diag.cc src/ov-base-diag.h src/ov-cx-diag.cc src/ov-cx-diag.h src/ov-flt-cx-diag.cc src/ov-flt-cx-diag.h src/ov-flt-re-diag.cc src/ov-flt-re-diag.h src/ov-re-diag.cc src/ov-re-diag.h |
diffstat | 11 files changed, 85 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ChangeLog Fri Feb 20 21:49:26 2009 +0100 @@ -1,3 +1,15 @@ +2009-02-20 Jaroslav Hajek <highegg@gmail.com> + + * ov-base-diag.h (octave_base_diag::sqrt): Remove. + * ov-re-diag.cc (octave_diag_matrix::sqrt): New method. + * ov-re-diag.h: Declare it. + * ov-flt-re-diag.cc (octave_float_diag_matrix::sqrt): New method. + * ov-flt-re-diag.h: Declare it. + * ov-cx-diag.cc (octave_complex_diag_matrix::sqrt): New method. + * ov-cx-diag.h: Declare it. + * ov-flt-cx-diag.cc (octave_float_complex_diag_matrix::sqrt): New method. + * ov-flt-cx-diag.h: Declare it. + 2009-02-20 John W. Eaton <jwe@octave.org> * dynamic-ld.cc (octave_dynamic_loader::do_load_mex): Clear and
--- a/src/ov-base-diag.cc Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-base-diag.cc Fri Feb 20 21:49:26 2009 +0100 @@ -579,7 +579,6 @@ FORWARD_MAPPER (signum) FORWARD_MAPPER (sin) FORWARD_MAPPER (sinh) -FORWARD_MAPPER (sqrt) FORWARD_MAPPER (tan) FORWARD_MAPPER (tanh) FORWARD_MAPPER (finite)
--- a/src/ov-base-diag.h Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-base-diag.h Fri Feb 20 21:49:26 2009 +0100 @@ -216,7 +216,7 @@ void print_info (std::ostream& os, const std::string& prefix) const; - // We forward everything except abs, real, imag, conj. + // We forward everything except abs, real, imag, conj, sqrt. octave_value erf (void) const; octave_value erfc (void) const; octave_value gamma (void) const; @@ -245,7 +245,6 @@ octave_value signum (void) const; octave_value sin (void) const; octave_value sinh (void) const; - octave_value sqrt (void) const; octave_value tan (void) const; octave_value tanh (void) const; octave_value finite (void) const;
--- a/src/ov-cx-diag.cc Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-cx-diag.cc Fri Feb 20 21:49:26 2009 +0100 @@ -159,6 +159,21 @@ return ::imag (matrix); } +octave_value +octave_complex_diag_matrix::sqrt (void) const +{ + octave_value retval; + + static ComplexNDArray::cmapper csqrt = std::sqrt; + + ComplexColumnVector dvec = matrix.diag (); + retval = ComplexDiagMatrix (dvec.map (csqrt)); + + retval.resize (dims ()); + + return retval; +} + bool octave_complex_diag_matrix::save_binary (std::ostream& os, bool& save_as_floats) {
--- a/src/ov-cx-diag.h Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-cx-diag.h Fri Feb 20 21:49:26 2009 +0100 @@ -82,6 +82,7 @@ octave_value conj (void) const; octave_value imag (void) const; octave_value real (void) const; + octave_value sqrt (void) const; private:
--- a/src/ov-flt-cx-diag.cc Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-flt-cx-diag.cc Fri Feb 20 21:49:26 2009 +0100 @@ -143,6 +143,21 @@ return ::imag (matrix); } +octave_value +octave_float_complex_diag_matrix::sqrt (void) const +{ + octave_value retval; + + static FloatComplexNDArray::cmapper csqrt = std::sqrt; + + FloatComplexColumnVector dvec = matrix.diag (); + retval = FloatComplexDiagMatrix (dvec.map (csqrt)); + + retval.resize (dims ()); + + return retval; +} + bool octave_float_complex_diag_matrix::save_binary (std::ostream& os, bool& /* save_as_floats */)
--- a/src/ov-flt-cx-diag.h Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-flt-cx-diag.h Fri Feb 20 21:49:26 2009 +0100 @@ -80,6 +80,7 @@ octave_value conj (void) const; octave_value imag (void) const; octave_value real (void) const; + octave_value sqrt (void) const; private:
--- a/src/ov-flt-re-diag.cc Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-flt-re-diag.cc Fri Feb 20 21:49:26 2009 +0100 @@ -114,6 +114,25 @@ return DiagMatrix (matrix.rows (), matrix.cols (), 0.0f); } +octave_value +octave_float_diag_matrix::sqrt (void) const +{ + octave_value retval; + + static FloatNDArray::dmapper dsqrt = ::sqrtf; + static FloatNDArray::cmapper csqrt = std::sqrt; + + FloatColumnVector dvec = matrix.diag (); + if (FloatMatrix (dvec).any_element_is_negative ()) + retval = FloatComplexDiagMatrix (dvec.map (csqrt)); + else + retval = FloatDiagMatrix (dvec.map (dsqrt)); + + retval.resize (dims ()); + + return retval; +} + bool octave_float_diag_matrix::save_binary (std::ostream& os, bool& /* save_as_floats*/)
--- a/src/ov-flt-re-diag.h Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-flt-re-diag.h Fri Feb 20 21:49:26 2009 +0100 @@ -80,6 +80,7 @@ octave_value conj (void) const; octave_value imag (void) const; octave_value real (void) const; + octave_value sqrt (void) const; private:
--- a/src/ov-re-diag.cc Fri Feb 20 15:23:47 2009 -0500 +++ b/src/ov-re-diag.cc Fri Feb 20 21:49:26 2009 +0100 @@ -129,6 +129,25 @@ return DiagMatrix (matrix.rows (), matrix.cols (), 0.0); } +octave_value +octave_diag_matrix::sqrt (void) const +{ + octave_value retval; + + static NDArray::dmapper dsqrt = ::sqrt; + static NDArray::cmapper csqrt = std::sqrt; + + ColumnVector dvec = matrix.diag (); + if (Matrix (dvec).any_element_is_negative ()) + retval = ComplexDiagMatrix (dvec.map (csqrt)); + else + retval = DiagMatrix (dvec.map (dsqrt)); + + retval.resize (dims ()); + + return retval; +} + bool octave_diag_matrix::save_binary (std::ostream& os, bool& save_as_floats) {