# HG changeset patch # User Jaroslav Hajek # Date 1237056170 -3600 # Node ID ed5055b0a4763958b8d3e6269404a913e746ae75 # Parent 80d499b82ff3dc7825b3629c369cf1b62138f157 fix & simplify ndarray->matrix conversions diff --git a/liboctave/CNDArray.cc b/liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -830,24 +830,11 @@ { ComplexMatrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = ComplexMatrix (Array2 (*this, dimensions(0), 1)); - break; - - case 2: - retval = ComplexMatrix (Array2 (*this, dimensions(0), - dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of ComplexNDArray to ComplexMatrix"); - break; - } + if (ndims () == 2) + retval = ComplexMatrix (Array2 (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of ComplexNDArray to ComplexMatrix"); return retval; } diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2009-03-14 Jaroslav Hajek + + * 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 * Range.h (Range::Range (double, double, octave_idx_type)): Remove diff --git a/liboctave/dNDArray.cc b/liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -879,23 +879,11 @@ { Matrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = Matrix (Array2 (*this, dimensions(0), 1)); - break; - - case 2: - retval = Matrix (Array2 (*this, dimensions(0), dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of NDArray to Matrix"); - break; - } + if (ndims () == 2) + retval = Matrix (Array2 (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of NDArray to Matrix"); return retval; } diff --git a/liboctave/fCNDArray.cc b/liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -825,24 +825,11 @@ { FloatComplexMatrix retval; - int nd = ndims (); - - switch (nd) - { - case 1: - retval = FloatComplexMatrix (Array2 (*this, dimensions(0), 1)); - break; - - case 2: - retval = FloatComplexMatrix (Array2 (*this, dimensions(0), - dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of FloatComplexNDArray to FloatComplexMatrix"); - break; - } + if (ndims () == 2) + retval = FloatComplexMatrix (Array2 (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of FloatComplexNDArray to FloatComplexMatrix"); return retval; } diff --git a/liboctave/fNDArray.cc b/liboctave/fNDArray.cc --- 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 (*this, dimensions(0), 1)); - break; + FloatMatrix retval; - case 2: - retval = Matrix (Array2 (*this, dimensions(0), dimensions(1))); - break; - - default: - (*current_liboctave_error_handler) - ("invalid conversion of FloatNDArray to Matrix"); - break; - } + if (ndims () == 2) + retval = FloatMatrix (Array2 (*this)); + else + (*current_liboctave_error_handler) + ("invalid conversion of FloatNDArray to FloatMatrix"); return retval; } diff --git a/liboctave/fNDArray.h b/liboctave/fNDArray.h --- a/liboctave/fNDArray.h +++ b/liboctave/fNDArray.h @@ -121,7 +121,7 @@ friend class FloatComplexNDArray; - Matrix matrix_value (void) const; + FloatMatrix matrix_value (void) const; FloatNDArray squeeze (void) const { return MArrayN::squeeze (); }