# HG changeset patch # User Jaroslav Hajek # Date 1237545565 -3600 # Node ID dc07bc4157b83e523f7cc4c376c9d637748ff2d3 # Parent a48fba01e4ac615f7b92bda5dc8d540340f77b41 allow empty matrices in stream input operators diff --git a/liboctave/CColVector.cc b/liboctave/CColVector.cc --- a/liboctave/CColVector.cc +++ b/liboctave/CColVector.cc @@ -524,9 +524,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { double tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/CMatrix.cc b/liboctave/CMatrix.cc --- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -3640,9 +3640,7 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { Complex tmp; for (octave_idx_type i = 0; i < nr; i++) diff --git a/liboctave/CNDArray.cc b/liboctave/CNDArray.cc --- a/liboctave/CNDArray.cc +++ b/liboctave/CNDArray.cc @@ -916,9 +916,7 @@ { octave_idx_type nel = a.nelem (); - if (nel < 1 ) - is.clear (std::ios::badbit); - else + if (nel > 0) { Complex tmp; for (octave_idx_type i = 0; i < nel; i++) diff --git a/liboctave/CRowVector.cc b/liboctave/CRowVector.cc --- a/liboctave/CRowVector.cc +++ b/liboctave/CRowVector.cc @@ -434,9 +434,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { Complex tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/CSparse.cc b/liboctave/CSparse.cc --- a/liboctave/CSparse.cc +++ b/liboctave/CSparse.cc @@ -7470,9 +7470,7 @@ octave_idx_type nc = a.cols (); octave_idx_type nz = a.nzmax (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { octave_idx_type itmp, jtmp, jold = 0; Complex tmp; diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,12 @@ +2009-03-20 Jaroslav Hajek + + + * CColVector.cc, CMatrix.cc, CNDArray.cc, CRowVector.cc, CSparse.cc, + boolSparse.cc, dColVector.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, + dSparse.cc, fCColVector.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, + fColVector.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc, intNDArray.cc: + Allow empty arrays in stream input operators. + 2009-03-20 Jaroslav Hajek * Array.h (Array::fastmap): New method. diff --git a/liboctave/boolSparse.cc b/liboctave/boolSparse.cc --- a/liboctave/boolSparse.cc +++ b/liboctave/boolSparse.cc @@ -184,9 +184,7 @@ octave_idx_type nc = a.cols (); octave_idx_type nz = a.nzmax (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { octave_idx_type itmp, jtmp, jold = 0; bool tmp; diff --git a/liboctave/dColVector.cc b/liboctave/dColVector.cc --- a/liboctave/dColVector.cc +++ b/liboctave/dColVector.cc @@ -321,9 +321,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { double tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/dMatrix.cc b/liboctave/dMatrix.cc --- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -3058,9 +3058,7 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { double tmp; for (octave_idx_type i = 0; i < nr; i++) diff --git a/liboctave/dNDArray.cc b/liboctave/dNDArray.cc --- a/liboctave/dNDArray.cc +++ b/liboctave/dNDArray.cc @@ -965,9 +965,7 @@ { octave_idx_type nel = a.nelem (); - if (nel < 1 ) - is.clear (std::ios::badbit); - else + if (nel > 0) { double tmp; for (octave_idx_type i = 0; i < nel; i++) diff --git a/liboctave/dRowVector.cc b/liboctave/dRowVector.cc --- a/liboctave/dRowVector.cc +++ b/liboctave/dRowVector.cc @@ -291,9 +291,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { double tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/dSparse.cc b/liboctave/dSparse.cc --- a/liboctave/dSparse.cc +++ b/liboctave/dSparse.cc @@ -7588,9 +7588,7 @@ octave_idx_type nc = a.cols (); octave_idx_type nz = a.nzmax (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { octave_idx_type itmp, jtmp, jold = 0; double tmp; diff --git a/liboctave/fCColVector.cc b/liboctave/fCColVector.cc --- a/liboctave/fCColVector.cc +++ b/liboctave/fCColVector.cc @@ -524,9 +524,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { float tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/fCMatrix.cc b/liboctave/fCMatrix.cc --- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -3633,9 +3633,7 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { FloatComplex tmp; for (octave_idx_type i = 0; i < nr; i++) diff --git a/liboctave/fCNDArray.cc b/liboctave/fCNDArray.cc --- a/liboctave/fCNDArray.cc +++ b/liboctave/fCNDArray.cc @@ -911,9 +911,7 @@ { octave_idx_type nel = a.nelem (); - if (nel < 1 ) - is.clear (std::ios::badbit); - else + if (nel > 0) { FloatComplex tmp; for (octave_idx_type i = 0; i < nel; i++) diff --git a/liboctave/fCRowVector.cc b/liboctave/fCRowVector.cc --- a/liboctave/fCRowVector.cc +++ b/liboctave/fCRowVector.cc @@ -434,9 +434,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { FloatComplex tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/fColVector.cc b/liboctave/fColVector.cc --- a/liboctave/fColVector.cc +++ b/liboctave/fColVector.cc @@ -321,9 +321,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { float tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/fMatrix.cc b/liboctave/fMatrix.cc --- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -3057,9 +3057,7 @@ octave_idx_type nr = a.rows (); octave_idx_type nc = a.cols (); - if (nr < 1 || nc < 1) - is.clear (std::ios::badbit); - else + if (nr > 0 && nc > 0) { float tmp; for (octave_idx_type i = 0; i < nr; i++) diff --git a/liboctave/fNDArray.cc b/liboctave/fNDArray.cc --- a/liboctave/fNDArray.cc +++ b/liboctave/fNDArray.cc @@ -920,9 +920,7 @@ { octave_idx_type nel = a.nelem (); - if (nel < 1 ) - is.clear (std::ios::badbit); - else + if (nel > 0) { float tmp; for (octave_idx_type i = 0; i < nel; i++) diff --git a/liboctave/fRowVector.cc b/liboctave/fRowVector.cc --- a/liboctave/fRowVector.cc +++ b/liboctave/fRowVector.cc @@ -291,9 +291,7 @@ { octave_idx_type len = a.length(); - if (len < 1) - is.clear (std::ios::badbit); - else + if (len > 0) { float tmp; for (octave_idx_type i = 0; i < len; i++) diff --git a/liboctave/intNDArray.cc b/liboctave/intNDArray.cc --- a/liboctave/intNDArray.cc +++ b/liboctave/intNDArray.cc @@ -146,9 +146,7 @@ { octave_idx_type nel = a.nelem (); - if (nel < 1 ) - is.clear (std::ios::badbit); - else + if (nel > 0) { T tmp; diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-03-20 Jaroslav Hajek + + * ov-re-mat.cc (octave_matrix::load_ascii): Simplify. + * ov-flt-re-mat.cc (octave_float_matrix::load_ascii): Simplify. + * ov-cx-mat.cc (octave_complex_matrix::load_ascii): Simplify. + * ov-flt-cx-mat.cc (octave_float_complex_matrix::load_ascii): Simplify. + 2009-03-20 Jaroslav Hajek * ov-re-mat.cc (octave_matrix::isnan, octave_matrix::isinf, diff --git a/src/ov-cx-mat.cc b/src/ov-cx-mat.cc --- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -353,20 +353,15 @@ { ComplexNDArray tmp(dv); - if (tmp.is_empty ()) - matrix = tmp; - else - { - is >> tmp; + is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } } else { diff --git a/src/ov-flt-cx-mat.cc b/src/ov-flt-cx-mat.cc --- a/src/ov-flt-cx-mat.cc +++ b/src/ov-flt-cx-mat.cc @@ -342,20 +342,15 @@ { FloatComplexNDArray tmp(dv); - if (tmp.is_empty ()) - matrix = tmp; - else - { - is >> tmp; + is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } } else { diff --git a/src/ov-flt-re-mat.cc b/src/ov-flt-re-mat.cc --- a/src/ov-flt-re-mat.cc +++ b/src/ov-flt-re-mat.cc @@ -372,20 +372,15 @@ { FloatNDArray tmp(dv); - if (tmp.is_empty ()) - matrix = tmp; - else - { - is >> tmp; + is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } } else { diff --git a/src/ov-re-mat.cc b/src/ov-re-mat.cc --- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -380,20 +380,15 @@ { NDArray tmp(dv); - if (tmp.is_empty ()) - matrix = tmp; - else - { - is >> tmp; + is >> tmp; - if (is) - matrix = tmp; - else - { - error ("load: failed to load matrix constant"); - success = false; - } - } + if (is) + matrix = tmp; + else + { + error ("load: failed to load matrix constant"); + success = false; + } } else {