Mercurial > hg > octave-nkf
changeset 2384:d9147efd1a93
[project @ 1996-10-12 17:56:38 by jwe]
author | jwe |
---|---|
date | Sat, 12 Oct 1996 17:56:39 +0000 |
parents | 096529066838 |
children | 170053c0f75e |
files | liboctave/CMatrix.cc liboctave/CMatrix.h liboctave/chMatrix.cc liboctave/chMatrix.h |
diffstat | 4 files changed, 227 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -163,16 +163,16 @@ elem (i, j) = a.elem (i, j); } -int +bool ComplexMatrix::operator == (const ComplexMatrix& a) const { if (rows () != a.rows () || cols () != a.cols ()) - return 0; + return false; return equal (data (), a.data (), length ()); } -int +bool ComplexMatrix::operator != (const ComplexMatrix& a) const { return !(*this == a); @@ -1668,8 +1668,7 @@ int a_len = a.length (); if (len != a_len) - (*current_liboctave_error_handler) - ("nonconformant vector multiplication attempted"); + gripe_nonconformant ("operator *", len, 1, 1, a_len); else { if (len != 0) @@ -1785,10 +1784,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = rows (); + int a_nc = cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix += operation attempted"); + gripe_nonconformant ("operator +=", nr, nc, a_nr, a_nc); return *this; } @@ -1803,10 +1805,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = rows (); + int a_nc = cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix -= operation attempted"); + gripe_nonconformant ("operator -=", nr, nc, a_nr, a_nc); return *this; } @@ -1821,10 +1826,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = rows (); + int a_nc = cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix += operation attempted"); + gripe_nonconformant ("operator +=", nr, nc, a_nr, a_nc); return *this; } @@ -1839,10 +1847,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = rows (); + int a_nc = cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix -= operation attempted"); + gripe_nonconformant ("operator -=", nr, nc, a_nr, a_nc); return *this; } @@ -1857,10 +1868,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -1879,10 +1893,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -1908,8 +1925,7 @@ int a_nc = a.cols (); if (nc != a_nr) - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); else { if (nr == 0 || nc == 0 || a_nc == 0) @@ -1960,10 +1976,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -1982,10 +2001,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2004,12 +2026,13 @@ { int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); + if (nc != a_nr) { - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2052,10 +2075,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2074,10 +2100,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2096,12 +2125,13 @@ { int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); + if (nc != a_nr) { - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2144,10 +2174,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2166,10 +2199,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2188,12 +2224,13 @@ { int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); + if (nc != a_nr) { - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2238,10 +2275,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix += operation attempted"); + gripe_nonconformant ("operator +=", nr, nc, a_nr, a_nc); return *this; } @@ -2259,10 +2299,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix -= operation attempted"); + gripe_nonconformant ("operator -=", nr, nc, a_nr, a_nc); return *this; } @@ -2280,10 +2323,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix += operation attempted"); + gripe_nonconformant ("operator +=", nr, nc, a_nr, a_nc); return *this; } @@ -2301,10 +2347,13 @@ { int nr = rows (); int nc = cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix -= operation attempted"); + gripe_nonconformant ("operator -=", nr, nc, a_nr, a_nc); return *this; } @@ -2448,10 +2497,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2470,10 +2522,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2495,11 +2550,11 @@ int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); - if (nc != a.rows ()) - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + if (nc != a_nr) + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); else { if (nr == 0 || nc == 0 || a_nc == 0) @@ -2547,10 +2602,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2569,10 +2627,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2594,11 +2655,11 @@ int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); - if (nc != a.rows ()) - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + if (nc != a_nr) + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); else { if (nr == 0 || nc == 0 || a_nc == 0) @@ -2648,10 +2709,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2666,10 +2730,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2684,10 +2751,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix addition attempted"); + gripe_nonconformant ("operator +", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2699,10 +2769,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix subtraction attempted"); + gripe_nonconformant ("operator -", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2734,11 +2807,11 @@ int nr = m.rows (); int nc = m.cols (); + int a_nr = a.rows (); int a_nc = a.cols (); - if (nc != a.rows ()) - (*current_liboctave_error_handler) - ("nonconformant matrix multiplication attempted"); + if (nc != a_nr) + gripe_nonconformant ("operator *", nr, nc, a_nr, a_nc); else { if (nr == 0 || nc == 0 || a_nc == 0) @@ -2769,10 +2842,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix product attempted"); + gripe_nonconformant ("product", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2787,10 +2863,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix quotient attempted"); + gripe_nonconformant ("quotient", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2805,10 +2884,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix product attempted"); + gripe_nonconformant ("product", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2823,10 +2905,13 @@ { int nr = m.rows (); int nc = m.cols (); - if (nr != a.rows () || nc != a.cols ()) + + int a_nr = a.rows (); + int a_nc = a.cols (); + + if (nr != a_nr || nc != a_nc) { - (*current_liboctave_error_handler) - ("nonconformant matrix quotient attempted"); + gripe_nonconformant ("quotient", nr, nc, a_nr, a_nc); return ComplexMatrix (); } @@ -2854,15 +2939,32 @@ elem (i, j) = f (elem (i, j)); } +bool +ComplexMatrix::any_element_is_inf_or_nan (void) const +{ + int nr = rows (); + int nc = cols (); + + for (int j = 0; j < nc; j++) + for (int i = 0; i < nr; i++) + { + Complex val = elem (i, j); + if (xisinf (val) || xisnan (val)) + return true; + } + + return false; +} + // Return nonzero if any element of CM has a non-integer real or // imaginary part. Also extract the largest and smallest (real or // imaginary) values and return them in MAX_VAL and MIN_VAL. -int +bool ComplexMatrix::all_integers (double& max_val, double& min_val) const { int nr = rows (); - int nc = columns (); + int nc = cols (); if (nr > 0 && nc > 0) { @@ -2881,7 +2983,7 @@ min_val = i_val; } else - return 0; + return false; for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) @@ -2904,16 +3006,17 @@ min_val = i_val; if (D_NINT (r_val) != r_val || D_NINT (i_val) != i_val) - return 0; + return false; } - return 1; + + return true; } -int +bool ComplexMatrix::too_large_for_float (void) const { int nr = rows (); - int nc = columns (); + int nc = cols (); for (int j = 0; j < nc; j++) for (int i = 0; i < nr; i++) @@ -2927,10 +3030,10 @@ || i_val > FLT_MAX || r_val < FLT_MIN || i_val < FLT_MIN) - return 1; + return true; } - return 0; + return false; } Matrix
--- a/liboctave/CMatrix.h +++ b/liboctave/CMatrix.h @@ -69,8 +69,8 @@ return *this; } - int operator == (const ComplexMatrix& a) const; - int operator != (const ComplexMatrix& a) const; + bool operator == (const ComplexMatrix& a) const; + bool operator != (const ComplexMatrix& a) const; // destructive insert/delete/reorder operations @@ -320,8 +320,9 @@ friend ComplexMatrix map (c_c_Mapper f, const ComplexMatrix& a); void map (c_c_Mapper f); - int all_integers (double& max_val, double& min_val) const; - int too_large_for_float (void) const; + bool any_element_is_inf_or_nan (void) const; + bool all_integers (double& max_val, double& min_val) const; + bool too_large_for_float (void) const; Matrix all (void) const; Matrix any (void) const;
--- a/liboctave/chMatrix.cc +++ b/liboctave/chMatrix.cc @@ -73,7 +73,7 @@ } } -int +bool charMatrix::operator == (const charMatrix& a) const { if (rows () != a.rows () || cols () != a.cols ()) @@ -82,7 +82,7 @@ return equal (data (), a.data (), length ()); } -int +bool charMatrix::operator != (const charMatrix& a) const { return !(*this == a);
--- a/liboctave/chMatrix.h +++ b/liboctave/chMatrix.h @@ -59,8 +59,8 @@ return *this; } - int operator == (const charMatrix& a) const; - int operator != (const charMatrix& a) const; + bool operator == (const charMatrix& a) const; + bool operator != (const charMatrix& a) const; // destructive insert/delete/reorder operations