diff liboctave/boolNDArray.h @ 5602:dfa2da0563e5

[project @ 2006-01-31 03:43:40 by jwe]
author jwe
date Tue, 31 Jan 2006 03:43:41 +0000
parents 451ad352b288
children ace8d8d26933
line wrap: on
line diff
--- a/liboctave/boolNDArray.h
+++ b/liboctave/boolNDArray.h
@@ -93,6 +93,23 @@
   //  bool all_elements_are_real (void) const;
   //  bool all_integers (double& max_val, double& min_val) const;
 
+  octave_idx_type nnz (void) const
+    {
+      octave_idx_type retval = 0;
+
+      const bool *d = this->data ();
+
+      octave_idx_type nel = this->numel ();
+
+      for (octave_idx_type i = 0; i < nel; i++)
+	{
+	  if (d[i])
+	    retval++;
+	}
+
+      return retval;
+    }
+
 private:
 
   boolNDArray (bool *d, dim_vector& dv) : ArrayN<bool> (d, dv) { }