# HG changeset patch # User Jaroslav Hajek # Date 1237056170 -3600 # Node ID ed5055b0a4763958b8d3e6269404a913e746ae75 # Parent 80d499b82ff3dc7825b3629c369cf1b62138f157 fix & simplify ndarray->matrix conversions diff -r 80d499b82ff3 -r ed5055b0a476 liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/CNDArray.cc Sat Mar 14 19:42:50 2009 +0100 @@ -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 -r 80d499b82ff3 -r ed5055b0a476 liboctave/ChangeLog --- a/liboctave/ChangeLog Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/ChangeLog Sat Mar 14 19:42:50 2009 +0100 @@ -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 -r 80d499b82ff3 -r ed5055b0a476 liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/dNDArray.cc Sat Mar 14 19:42:50 2009 +0100 @@ -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 -r 80d499b82ff3 -r ed5055b0a476 liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/fCNDArray.cc Sat Mar 14 19:42:50 2009 +0100 @@ -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 -r 80d499b82ff3 -r ed5055b0a476 liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/fNDArray.cc Sat Mar 14 19:42:50 2009 +0100 @@ -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 -r 80d499b82ff3 -r ed5055b0a476 liboctave/fNDArray.h --- a/liboctave/fNDArray.h Sat Mar 14 10:38:43 2009 +0100 +++ b/liboctave/fNDArray.h Sat Mar 14 19:42:50 2009 +0100 @@ -121,7 +121,7 @@ friend class FloatComplexNDArray; - Matrix matrix_value (void) const; + FloatMatrix matrix_value (void) const; FloatNDArray squeeze (void) const { return MArrayN::squeeze (); }