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 Array2<bool>& a) : ArrayN<bool> (a) { } |
|
51 |
|
52 boolNDArray (const ArrayN<bool>& a) : ArrayN<bool> (a) { } |
|
53 |
|
54 boolNDArray& operator = (const boolNDArray& a) |
|
55 { |
|
56 ArrayN<bool>::operator = (a); |
|
57 return *this; |
|
58 } |
|
59 |
4543
|
60 // unary operations |
|
61 |
|
62 boolNDArray operator ! (void) const; |
|
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 |
7113
|
69 boolNDArray sum (int dim = -1) const; |
|
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 |
4514
|
114 private: |
|
115 |
4587
|
116 boolNDArray (bool *d, dim_vector& dv) : ArrayN<bool> (d, dv) { } |
4514
|
117 }; |
|
118 |
6708
|
119 NDND_BOOL_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) |
|
120 NDND_CMP_OP_DECLS (boolNDArray, boolNDArray, OCTAVE_API) |
4543
|
121 |
6708
|
122 NDS_BOOL_OP_DECLS (boolNDArray, bool, OCTAVE_API) |
|
123 NDS_CMP_OP_DECLS (boolNDArray, bool, OCTAVE_API) |
4669
|
124 |
6708
|
125 SND_BOOL_OP_DECLS (bool, boolNDArray, OCTAVE_API) |
|
126 SND_CMP_OP_DECLS (bool, boolNDArray, OCTAVE_API) |
4669
|
127 |
4514
|
128 #endif |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; End: *** |
|
134 */ |