Mercurial > hg > octave-nkf
annotate liboctave/boolNDArray.h @ 8780:ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 17 Feb 2009 14:23:35 +0100 |
parents | b756ce0002db |
children | eb63fbe60fab |
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" | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
29 #include "mx-op-decl.h" |
4514 | 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; |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8774
diff
changeset
|
70 NDArray cumsum (int dim = -1) const; |
7113 | 71 |
5275 | 72 boolNDArray concat (const boolNDArray& rb, const Array<octave_idx_type>& ra_idx); |
4964 | 73 |
5275 | 74 boolNDArray& insert (const boolNDArray& a, octave_idx_type r, octave_idx_type c); |
75 boolNDArray& insert (const boolNDArray& a, const Array<octave_idx_type>& ra_idx); | |
4964 | 76 |
4514 | 77 boolMatrix matrix_value (void) const; |
78 | |
4532 | 79 boolNDArray squeeze (void) const { return ArrayN<bool>::squeeze (); } |
80 | |
5275 | 81 static void increment_index (Array<octave_idx_type>& ra_idx, |
4532 | 82 const dim_vector& dimensions, |
83 int start_dimension = 0); | |
84 | |
5275 | 85 static octave_idx_type compute_index (Array<octave_idx_type>& ra_idx, |
4556 | 86 const dim_vector& dimensions); |
87 | |
4514 | 88 // i/o |
89 | |
90 // friend std::ostream& operator << (std::ostream& os, const NDArray& a); | |
91 // friend std::istream& operator >> (std::istream& is, NDArray& a); | |
92 | |
93 static bool resize_fill_value (void) { return false; } | |
94 | |
95 // bool all_elements_are_real (void) const; | |
96 // bool all_integers (double& max_val, double& min_val) const; | |
97 | |
5602 | 98 octave_idx_type nnz (void) const |
99 { | |
100 octave_idx_type retval = 0; | |
101 | |
102 const bool *d = this->data (); | |
103 | |
104 octave_idx_type nel = this->numel (); | |
105 | |
106 for (octave_idx_type i = 0; i < nel; i++) | |
107 { | |
108 if (d[i]) | |
109 retval++; | |
110 } | |
111 | |
112 return retval; | |
113 } | |
114 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
115 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
|
116 |
4514 | 117 private: |
118 | |
4587 | 119 boolNDArray (bool *d, dim_vector& dv) : ArrayN<bool> (d, dv) { } |
4514 | 120 }; |
121 | |
6708 | 122 NDND_BOOL_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) |
123 NDND_CMP_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) | |
4543 | 124 |
6708 | 125 NDS_BOOL_OP_DECLS (boolNDArray, bool, OCTAVE_API) |
126 NDS_CMP_OP_DECLS (boolNDArray, bool, OCTAVE_API) | |
4669 | 127 |
6708 | 128 SND_BOOL_OP_DECLS (bool, boolNDArray, OCTAVE_API) |
129 SND_CMP_OP_DECLS (bool, boolNDArray, OCTAVE_API) | |
4669 | 130 |
4514 | 131 #endif |
132 | |
133 /* | |
134 ;;; Local Variables: *** | |
135 ;;; mode: C++ *** | |
136 ;;; End: *** | |
137 */ |