GNU Octave  4.2.1
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-2017 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 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include "Array-util.h"
30 #include "boolNDArray.h"
31 #include "CNDArray.h"
32 #include "mx-base.h"
33 #include "lo-ieee.h"
34 #include "mx-op-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 
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 void
111  const dim_vector& dimensions,
112  int start_dimension)
113 {
114  ::increment_index (ra_idx, dimensions, start_dimension);
115 }
116 
119  const dim_vector& dimensions)
120 {
121  return ::compute_index (ra_idx, dimensions);
122 }
123 
126 {
127  return Array<bool>::diag (k);
128 }
129 
132 {
133  return Array<bool>::diag (m, n);
134 }
135 
137 NDND_CMP_OPS (boolNDArray, boolNDArray)
138 
139 NDS_BOOL_OPS (boolNDArray, bool)
140 NDS_CMP_OPS (boolNDArray, bool)
141 
142 SND_BOOL_OPS (bool, boolNDArray)
143 SND_CMP_OPS (bool, boolNDArray)
144 
145 boolNDArray&
146 mx_el_and_assign (boolNDArray& a, const boolNDArray& b)
147 {
148  if (a.is_shared ())
149  a = mx_el_and (a, b);
150  else
151  do_mm_inplace_op<bool, bool> (a, b, mx_inline_and2, mx_inline_and2,
152  "operator &=");
153 
154  return a;
155 }
156 
159 {
160  if (a.is_shared ())
161  a = mx_el_or (a, b);
162  else
163  do_mm_inplace_op<bool, bool> (a, b, mx_inline_or2, mx_inline_or2,
164  "operator |=");
165 
166  return a;
167 }
168 
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:176
boolNDArray all(int dim=-1) const
Definition: boolNDArray.cc:60
#define NDS_BOOL_OPS(ND, S)
Definition: mx-op-defs.h:255
#define NDS_CMP_OPS(ND, S)
Definition: mx-op-defs.h:238
void mx_inline_or2(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:239
NDArray cumsum(int dim=-1) const
Definition: boolNDArray.cc:80
boolNDArray & invert(void)
Definition: boolNDArray.cc:47
const octave_base_value const Array< octave_idx_type > & ra_idx
#define SND_CMP_OPS(S, ND)
Definition: mx-op-defs.h:285
#define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP)
Definition: bsxfun-defs.cc:222
OCTAVE_EXPORT octave_value_list or class The return code an ordinary file in Octave s or(after appending @samp{.m}) a function file in Octave's ode
Definition: variables.cc:582
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: boolNDArray.cc:110
boolNDArray mx_el_or(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:136
boolNDArray concat(const boolNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: boolNDArray.cc:87
for large enough k
Definition: lu.cc:606
void mx_inline_cumcount(const bool *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:822
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2529
boolNDArray any(int dim=-1) const
Definition: boolNDArray.cc:66
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:716
Array< T > & insert(const Array< T > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array.cc:1601
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:332
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:349
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
boolNDArray mx_el_and(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:136
void mx_inline_and2(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:238
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:302
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
boolNDArray diag(octave_idx_type k=0) const
Definition: boolNDArray.cc:125
boolNDArray & mx_el_and_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:146
Restrict the maximum order of the solution method This option must be between and
Definition: DASPK-opts.cc:739
void mx_inline_and(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:217
bool is_shared(void)
Definition: Array.h:588
void mx_inline_or(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:218
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: boolNDArray.cc:118
b
Definition: cellfun.cc:398
bool mx_inline_all(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:716
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:182
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
void mx_inline_not2(size_t n, bool *r)
Definition: mx-inlines.cc:188
NDArray sum(int dim=-1) const
Definition: boolNDArray.cc:72
boolNDArray & mx_el_or_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:158
boolNDArray operator!(void) const
Definition: boolNDArray.cc:41
T mx_inline_count(const bool *v, octave_idx_type n)
Definition: mx-inlines.cc:715
boolNDArray & insert(const boolNDArray &a, octave_idx_type r, octave_idx_type c)
Definition: boolNDArray.cc:96