changeset 2365:7c60f8a6e6a0

[project @ 1996-10-11 23:03:52 by jwe]
author jwe
date Fri, 11 Oct 1996 23:05:38 +0000
parents 5eb0af0730d6
children c90105b99479
files src/timefns.cc src/xpow.cc
diffstat 2 files changed, 66 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/src/timefns.cc
+++ b/src/timefns.cc
@@ -31,7 +31,7 @@
 #include "help.h"
 #include "oct-map.h"
 #include "systime.h"
-#include "pt-const.h"
+#include "ov.h"
 #include "oct-obj.h"
 #include "utils.h"
 
--- a/src/xpow.cc
+++ b/src/xpow.cc
@@ -36,25 +36,10 @@
 #include "oct-cmplx.h"
 
 #include "error.h"
-#include "pt-const.h"
+#include "ov.h"
 #include "utils.h"
 #include "xpow.h"
 
-// This function also appears in tree-const.cc.  Maybe it should be a
-// member function of the Matrix class.
-
-static int
-any_element_is_negative (const Matrix& a)
-{
-  int nr = a.rows ();
-  int nc = a.columns ();
-  for (int j = 0; j < nc; j++)
-    for (int i = 0; i < nr; i++)
-      if (a (i, j) < 0.0)
-	return 1;
-  return 0;
-}
-
 static inline int
 xisint (double x)
 {
@@ -69,14 +54,12 @@
 //            +--   +---+---+----+----+
 //   scalar   |     | 1 | 5 |  7 | 11 |
 //                  +---+---+----+----+
-//   matrix         | 2 | E |  8 |  E |
+//   matrix         | 2 | * |  8 |  * |
 //                  +---+---+----+----+
 //   complex_scalar | 3 | 6 |  9 | 12 |
 //                  +---+---+----+----+
-//   complex_matrix | 4 | E | 10 |  E |
+//   complex_matrix | 4 | * | 10 |  * |
 //                  +---+---+----+----+
-//
-//   E -> error, trapped in arith-ops.cc.
 
 // -*- 1 -*-
 octave_value
@@ -98,7 +81,7 @@
   octave_value retval;
 
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
     error ("for x^A, A must be square");
@@ -141,12 +124,10 @@
   octave_value retval;
 
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for x^A, A must be square");
-    }
+    error ("for x^A, A must be square");
   else
     {
       EIG b_eig (b);
@@ -176,12 +157,10 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for A^b, A must be square");
-    }
+    error ("for A^b, A must be square");
   else
     {
       if ((int) b == b)
@@ -246,12 +225,10 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for A^b, A must be square");
-    }
+    error ("for A^b, A must be square");
   else
     {
       EIG a_eig (a);
@@ -290,12 +267,10 @@
   octave_value retval;
 
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for x^A, A must be square");
-    }
+    error ("for x^A, A must be square");
   else
     {
       EIG b_eig (b);
@@ -334,12 +309,10 @@
   octave_value retval;
 
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for x^A, A must be square");
-    }
+    error ("for x^A, A must be square");
   else
     {
       EIG b_eig (b);
@@ -369,12 +342,10 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for A^b, A must be square");
-    }
+    error ("for A^b, A must be square");
   else
     {
       if ((int) b == b)
@@ -439,12 +410,10 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   if (nr == 0 || nc == 0 || nr != nc)
-    {
-      error ("for A^b, A must be square");
-    }
+    error ("for A^b, A must be square");
   else
     {
       EIG a_eig (a);
@@ -484,7 +453,7 @@
   octave_value retval;
 
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   // For now, assume the worst.
 
@@ -516,7 +485,7 @@
 elem_xpow (double a, const ComplexMatrix& b)
 {
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -533,9 +502,9 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
-  if ((int) b != b && any_element_is_negative (a))
+  if ((int) b != b && a.any_element_is_negative ())
     {
       ComplexMatrix result (nr, nc);
       for (int j = 0; j < nc; j++)
@@ -567,9 +536,16 @@
   octave_value retval;
 
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
+
+  int b_nr = b.rows ();
+  int b_nc = b.cols ();
 
-  assert (nr == b.rows () && nc == b.columns ());
+  if (nr != b_nr || nc != b_nc)
+    {
+      gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
+      return octave_value ();
+    }
 
   int convert_to_complex = 0;
   for (int j = 0; j < nc; j++)
@@ -584,7 +560,7 @@
 	  }
       }
 
- done:
+done:
 
   if (convert_to_complex)
     {
@@ -619,7 +595,7 @@
 elem_xpow (const Matrix& a, const Complex& b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -634,9 +610,16 @@
 elem_xpow (const Matrix& a, const ComplexMatrix& b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
+
+  int b_nr = b.rows ();
+  int b_nc = b.cols ();
 
-  assert (nr == b.rows () && nc == b.columns ());
+  if (nr != b_nr || nc != b_nc)
+    {
+      gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
+      return octave_value ();
+    }
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -651,7 +634,7 @@
 elem_xpow (const Complex& a, const Matrix& b)
 {
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -672,7 +655,7 @@
 elem_xpow (const Complex& a, const ComplexMatrix& b)
 {
   int nr = b.rows ();
-  int nc = b.columns ();
+  int nc = b.cols ();
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -687,7 +670,7 @@
 elem_xpow (const ComplexMatrix& a, double b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   ComplexMatrix result (nr, nc);
 
@@ -712,9 +695,16 @@
 elem_xpow (const ComplexMatrix& a, const Matrix& b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
+
+  int b_nr = b.rows ();
+  int b_nc = b.cols ();
 
-  assert (nr == b.rows () && nc == b.columns ());
+  if (nr != b_nr || nc != b_nc)
+    {
+      gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
+      return octave_value ();
+    }
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -735,7 +725,7 @@
 elem_xpow (const ComplexMatrix& a, const Complex& b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
 
   ComplexMatrix result (nr, nc);
   for (int j = 0; j < nc; j++)
@@ -750,10 +740,18 @@
 elem_xpow (const ComplexMatrix& a, const ComplexMatrix& b)
 {
   int nr = a.rows ();
-  int nc = a.columns ();
+  int nc = a.cols ();
+
+  int b_nr = b.rows ();
+  int b_nc = b.cols ();
+
+  if (nr != b_nr || nc != b_nc)
+    {
+      gripe_nonconformant ("operator .^", nr, nc, b_nr, b_nc);
+      return octave_value ();
+    }
 
   ComplexMatrix result (nr, nc);
-
   for (int j = 0; j < nc; j++)
     for (int i = 0; i < nr; i++)
       result (i, j) = pow (a (i, j), b (i, j));