Mercurial > hg > octave-nkf
annotate liboctave/boolNDArray.h @ 8756:d0755c9db5ed
implement fast logical sum (counting)
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 16 Feb 2009 12:41:55 +0100 |
parents | 1dce30ab0e72 |
children | b756ce0002db |
rev | line source |
---|---|
4514 | 1 /* |
2 | |
7017 | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4514 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4514 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4514 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_boolNDArray_h) | |
24 #define octave_boolNDArray_h 1 | |
25 | |
26 #include "ArrayN.h" | |
27 | |
28 #include "mx-defs.h" | |
29 #include "mx-op-defs.h" | |
30 | |
4650 | 31 #include "boolMatrix.h" |
32 | |
4514 | 33 class |
6108 | 34 OCTAVE_API |
4514 | 35 boolNDArray : public ArrayN<bool> |
36 { | |
37 public: | |
5523 | 38 |
4514 | 39 boolNDArray (void) : ArrayN<bool> () { } |
40 | |
4730 | 41 boolNDArray (const dim_vector& dv) : ArrayN<bool> (dv) { } |
4514 | 42 |
4730 | 43 boolNDArray (const dim_vector& dv, const bool& val) |
4587 | 44 : ArrayN<bool> (dv, val) { } |
4514 | 45 |
46 boolNDArray (const boolNDArray& a) : ArrayN<bool> (a) { } | |
47 | |
48 boolNDArray (const boolMatrix& a) : ArrayN<bool> (a) { } | |
49 | |
50 boolNDArray (const ArrayN<bool>& a) : ArrayN<bool> (a) { } | |
51 | |
52 boolNDArray& operator = (const boolNDArray& a) | |
53 { | |
54 ArrayN<bool>::operator = (a); | |
55 return *this; | |
56 } | |
57 | |
4543 | 58 // unary operations |
59 | |
60 boolNDArray operator ! (void) const; | |
61 | |
8626
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
62 bool any_element_is_nan (void) const { return false; } |
1dce30ab0e72
don't convert NaN to logical in bool expressions
John W. Eaton <jwe@octave.org>
parents:
7620
diff
changeset
|
63 |
5775 | 64 // FIXME -- this is not quite the right thing. |
4514 | 65 |
4556 | 66 boolNDArray all (int dim = -1) const; |
67 boolNDArray any (int dim = -1) const; | |
4514 | 68 |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8626
diff
changeset
|
69 NDArray sum (int dim = -1) const; |
7113 | 70 |
5275 | 71 boolNDArray concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx); |
4964 | 72 |
5275 | 73 boolNDArray& insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c); |
74 boolNDArray& insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx); | |
4964 | 75 |
4514 | 76 boolMatrix matrix_value (void) const; |
77 | |
4532 | 78 boolNDArray squeeze (void) const { return ArrayN<bool>::squeeze (); } |
79 | |
5275 | 80 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 81 const dim_vector& dimensions, |
82 int start_dimension = 0); | |
83 | |
5275 | 84 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556 | 85 const dim_vector& dimensions); |
86 | |
4514 | 87 // i/o |
88 | |
89 // friend std::ostream& operator << (std::ostream& os, const NDArray& a); | |
90 // friend std::istream& operator >> (std::istream& is, NDArray& a); | |
91 | |
92 static bool resize_fill_value (void) { return false; } | |
93 | |
94 // bool all_elements_are_real (void) const; | |
95 // bool all_integers (double& max_val, double& min_val) const; | |
96 | |
5602 | 97 octave_idx_type nnz (void) const |
98 { | |
99 octave_idx_type retval = 0; | |
100 | |
101 const bool *d = this->data (); | |
102 | |
103 octave_idx_type nel = this->numel (); | |
104 | |
105 for (octave_idx_type i = 0; i < nel; i++) | |
106 { | |
107 if (d[i]) | |
108 retval++; | |
109 } | |
110 | |
111 return retval; | |
112 } | |
113 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
114 boolNDArray diag (octave_idx_type k = 0) const; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
115 |
4514 | 116 private: |
117 | |
4587 | 118 boolNDArray (bool *d, dim_vector& dv) : ArrayN<bool> (d, dv) { } |
4514 | 119 }; |
120 | |
6708 | 121 NDND_BOOL_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) |
122 NDND_CMP_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) | |
4543 | 123 |
6708 | 124 NDS_BOOL_OP_DECLS (boolNDArray, bool, OCTAVE_API) |
125 NDS_CMP_OP_DECLS (boolNDArray, bool, OCTAVE_API) | |
4669 | 126 |
6708 | 127 SND_BOOL_OP_DECLS (bool, boolNDArray, OCTAVE_API) |
128 SND_CMP_OP_DECLS (bool, boolNDArray, OCTAVE_API) | |
4669 | 129 |
4514 | 130 #endif |
131 | |
132 /* | |
133 ;;; Local Variables: *** | |
134 ;;; mode: C++ *** | |
135 ;;; End: *** | |
136 */ |