diff liboctave/dNDArray.cc @ 4513:508238e65af7

[project @ 2003-09-19 21:40:57 by jwe]
author jwe
date Fri, 19 Sep 2003 21:41:21 +0000
parents 24af46b4ce84
children 01ee68d18069
line wrap: on
line diff
--- a/liboctave/dNDArray.cc
+++ b/liboctave/dNDArray.cc
@@ -1,4 +1,4 @@
-//N-D Array  manipulations.
+// N-D Array  manipulations.
 /*
 
 Copyright (C) 1996, 1997 John W. Eaton
@@ -29,10 +29,47 @@
 #include <config.h>
 #endif
 
-#include "NDArray.h"
+#include "dNDArray.h"
 #include "mx-base.h"
+#include "lo-error.h"
 #include "lo-ieee.h"
 
+// XXX FIXME XXX -- this is not quite the right thing.
+
+boolMatrix
+NDArray::all (int dim) const
+{
+  boolMatrix retval;
+
+  if (dimensions.length () == 2)
+    {
+      Matrix tmp = matrix_value ();
+      retval = tmp.all (dim);
+    }
+  else
+    (*current_liboctave_error_handler)
+      ("all is not yet implemented for N-d Arrays");
+
+  return retval;
+}
+
+boolMatrix
+NDArray::any (int dim) const
+{
+  boolMatrix retval;
+
+  if (dimensions.length () == 2)
+    {
+      Matrix tmp = matrix_value ();
+      retval = tmp.any (dim);
+    }
+  else
+    (*current_liboctave_error_handler)
+      ("any is not yet implemented for N-d Arrays");
+
+  return retval;
+}
+
 bool
 NDArray::any_element_is_negative (bool neg_zero) const
 {
@@ -82,3 +119,35 @@
 
   return true;
 }
+
+Matrix
+NDArray::matrix_value (void) const
+{
+  Matrix retval;
+
+  int nd = ndims ();
+
+  switch (nd)
+    {
+    case 1:
+      retval = Matrix (Array2<double> (*this, dimensions(0), 1));
+      break;
+
+    case 2:
+      retval = Matrix (Array2<double> (*this, dimensions(0), dimensions(1)));
+      break;
+
+    default:
+      (*current_liboctave_error_handler)
+	("invalid converstion of NDArray to Matrix");
+      break;
+    }
+
+  return retval;
+}
+
+/*
+;;; Local Variables: ***
+;;; mode: C++ ***
+;;; End: ***
+*/