GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
boolNDArray.cc
Go to the documentation of this file.
1 // N-D Array manipulations.
2 /*
3 
4 Copyright (C) 1996-2013 John W. Eaton
5 Copyright (C) 2009 VZLU Prague, a.s.
6 
7 This file is part of Octave.
8 
9 Octave is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include "Array-util.h"
30 #include "CNDArray.h"
31 #include "mx-base.h"
32 #include "lo-ieee.h"
33 #include "mx-op-defs.h"
34 #include "MArray-defs.h"
35 
36 #include "bsxfun-defs.cc"
37 
38 // unary operations
39 
42 {
43  return do_mx_unary_op<bool, bool> (*this, mx_inline_not);
44 }
45 
48 {
49  if (is_shared ())
50  *this = ! *this;
51  else
52  do_mx_inplace_op<bool> (*this, mx_inline_not2);
53 
54  return *this;
55 }
56 
57 // FIXME: this is not quite the right thing.
58 
60 boolNDArray::all (int dim) const
61 {
62  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all);
63 }
64 
66 boolNDArray::any (int dim) const
67 {
68  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any);
69 }
70 
71 NDArray
72 boolNDArray::sum (int dim) const
73 {
74  // NOTE: going via octave_idx_type is typically faster even though it
75  // requires a conversion.
76  return do_mx_red_op<octave_idx_type, bool> (*this, dim, mx_inline_count);
77 }
78 
79 NDArray
80 boolNDArray::cumsum (int dim) const
81 {
82  // In this case, it's better to sum directly to doubles.
83  return do_mx_cum_op<double , bool> (*this, dim, mx_inline_cumcount);
84 }
85 
88  const Array<octave_idx_type>& ra_idx)
89 {
90  if (rb.numel () > 0)
91  insert (rb, ra_idx);
92  return *this;
93 }
94 
97 {
98  Array<bool>::insert (a, r, c);
99  return *this;
100 }
101 
104 {
105  Array<bool>::insert (a, ra_idx);
106  return *this;
107 }
108 
109 
110 
113 {
114  return *this;
115 }
116 
117 void
119  const dim_vector& dimensions,
120  int start_dimension)
121 {
122  ::increment_index (ra_idx, dimensions, start_dimension);
123 }
124 
127  const dim_vector& dimensions)
128 {
129  return ::compute_index (ra_idx, dimensions);
130 }
131 
134 {
135  return Array<bool>::diag (k);
136 }
137 
140 {
141  return Array<bool>::diag (m, n);
142 }
143 
145 NDND_CMP_OPS (boolNDArray, boolNDArray)
146 
147 NDS_BOOL_OPS (boolNDArray, bool)
148 NDS_CMP_OPS (boolNDArray, bool)
149 
150 SND_BOOL_OPS (bool, boolNDArray)
151 SND_CMP_OPS (bool, boolNDArray)
152 
153 boolNDArray&
154 mx_el_and_assign (boolNDArray& a, const boolNDArray& b)
155 {
156  if (a.is_shared ())
157  a = mx_el_and (a, b);
158  else
159  do_mm_inplace_op<bool, bool> (a, b, mx_inline_and2, mx_inline_and2,
160  "operator &=");
161 
162  return a;
163 }
164 
167 {
168  if (a.is_shared ())
169  a = mx_el_or (a, b);
170  else
171  do_mm_inplace_op<bool, bool> (a, b, mx_inline_or2, mx_inline_or2,
172  "operator |=");
173 
174  return a;
175 }
176