Mercurial > hg > octave-nkf
changeset 8981:ed5055b0a476
fix & simplify ndarray->matrix conversions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 14 Mar 2009 19:42:50 +0100 |
parents | 80d499b82ff3 |
children | dc6bda6f9994 |
files | liboctave/CNDArray.cc liboctave/ChangeLog liboctave/dNDArray.cc liboctave/fCNDArray.cc liboctave/fNDArray.cc liboctave/fNDArray.h |
diffstat | 6 files changed, 31 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -830,24 +830,11 @@ { ComplexMatrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = ComplexMatrix (Array2<Complex> (*this, dimensions(0), 1)); - break; - - case 2: - retval = ComplexMatrix (Array2<Complex> (*this, dimensions(0), - dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of ComplexNDArray to ComplexMatrix"); - break; - } + if (ndims () == 2) + retval = ComplexMatrix (Array2<Complex> (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of ComplexNDArray to ComplexMatrix"); return retval; }
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2009-03-14 Jaroslav Hajek <highegg@gmail.com> + + * fNDArray.h (FloatMatrix::matrix_value): Fix return type. + * dNDArray.cc (Matrix::matrix_value): Simplify. + * fNDArray.cc (FloatMatrix::matrix_value): Simplify. + * CNDArray.cc (ComplexMatrix::matrix_value): Simplify. + * fCNDArray.cc (FloatComplexMatrix::matrix_value): Simplify. + 2009-03-13 Jaroslav Hajek <highegg@gmail.com> * Range.h (Range::Range (double, double, octave_idx_type)): Remove
--- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -879,23 +879,11 @@ { Matrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = Matrix (Array2<double> (*this, dimensions(0), 1)); - break; - - case 2: - retval = Matrix (Array2<double> (*this, dimensions(0), dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of NDArray to Matrix"); - break; - } + if (ndims () == 2) + retval = Matrix (Array2<double> (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of NDArray to Matrix"); return retval; }
--- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -825,24 +825,11 @@ { FloatComplexMatrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = FloatComplexMatrix (Array2<FloatComplex> (*this, dimensions(0), 1)); - break; - - case 2: - retval = FloatComplexMatrix (Array2<FloatComplex> (*this, dimensions(0), - dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of FloatComplexNDArray to FloatComplexMatrix"); - break; - } + if (ndims () == 2) + retval = FloatComplexMatrix (Array2<FloatComplex> (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of FloatComplexNDArray to FloatComplexMatrix"); return retval; }
--- a/liboctave/fNDArray.cc +++ b/liboctave/fNDArray.cc @@ -829,28 +829,16 @@ dims ()); } -Matrix +FloatMatrix FloatNDArray::matrix_value (void) const { - Matrix retval; - - int nd = ndims (); - - switch (nd) - { - case 1: - retval = Matrix (Array2<float> (*this, dimensions(0), 1)); - break; + FloatMatrix retval; - case 2: - retval = Matrix (Array2<float> (*this, dimensions(0), dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of FloatNDArray to Matrix"); - break; - } + if (ndims () == 2) + retval = FloatMatrix (Array2<float> (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of FloatNDArray to FloatMatrix"); return retval; }