GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
boolNDArray.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
4 Copyright (C) 2009 VZLU Prague, a.s.
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include "Array-util.h"
29 #include "boolNDArray.h"
30 #include "CNDArray.h"
31 #include "mx-base.h"
32 #include "lo-ieee.h"
33 #include "mx-op-defs.h"
34 
35 #include "bsxfun-defs.cc"
36 
37 // unary operations
38 
41 {
42  return do_mx_unary_op<bool, bool> (*this, mx_inline_not);
43 }
44 
47 {
48  if (is_shared ())
49  *this = ! *this;
50  else
51  do_mx_inplace_op<bool> (*this, mx_inline_not2);
52 
53  return *this;
54 }
55 
56 // FIXME: this is not quite the right thing.
57 
59 boolNDArray::all (int dim) const
60 {
61  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all);
62 }
63 
65 boolNDArray::any (int dim) const
66 {
67  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any);
68 }
69 
70 NDArray
71 boolNDArray::sum (int dim) const
72 {
73  // NOTE: going via octave_idx_type is typically faster even though it
74  // requires a conversion.
75  return do_mx_red_op<octave_idx_type, bool> (*this, dim, mx_inline_count);
76 }
77 
78 NDArray
79 boolNDArray::cumsum (int dim) const
80 {
81  // In this case, it's better to sum directly to doubles.
82  return do_mx_cum_op<double , bool> (*this, dim, mx_inline_cumcount);
83 }
84 
88 {
89  if (rb.numel () > 0)
90  insert (rb, ra_idx);
91  return *this;
92 }
93 
96 {
97  Array<bool>::insert (a, r, c);
98  return *this;
99 }
100 
103 {
105  return *this;
106 }
107 
108 void
110  const dim_vector& dimensions,
111  int start_dimension)
112 {
113  ::increment_index (ra_idx, dimensions, start_dimension);
114 }
115 
118  const dim_vector& dimensions)
119 {
121 }
122 
125 {
126  return Array<bool>::diag (k);
127 }
128 
131 {
132  return Array<bool>::diag (m, n);
133 }
134 
137 
140 
143 
146 {
147  if (a.is_shared ())
148  a = mx_el_and (a, b);
149  else
150  do_mm_inplace_op<bool, bool> (a, b, mx_inline_and2, mx_inline_and2,
151  "operator &=");
152 
153  return a;
154 }
155 
158 {
159  if (a.is_shared ())
160  a = mx_el_or (a, b);
161  else
162  do_mm_inplace_op<bool, bool> (a, b, mx_inline_or2, mx_inline_or2,
163  "operator |=");
164 
165  return a;
166 }
167 
dim_vector dimensions
Definition: Array.h:216
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:175
#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:240
boolNDArray & invert(void)
Definition: boolNDArray.cc:46
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:219
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: boolNDArray.cc:109
boolNDArray mx_el_or(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:135
boolNDArray concat(const boolNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: boolNDArray.cc:86
for large enough k
Definition: lu.cc:617
void mx_inline_cumcount(const bool *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:859
boolNDArray all(int dim=-1) const
Definition: boolNDArray.cc:59
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
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:593
boolNDArray any(int dim=-1) const
Definition: boolNDArray.cc:65
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
boolNDArray operator!(void) const
Definition: boolNDArray.cc:40
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:1583
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:400
boolNDArray diag(octave_idx_type k=0) const
Definition: boolNDArray.cc:124
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:332
NDArray cumsum(int dim=-1) const
Definition: boolNDArray.cc:79
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:349
boolNDArray mx_el_and(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:135
void mx_inline_and2(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:224
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:302
boolNDArray & mx_el_and_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:145
void mx_inline_and(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:215
NDArray sum(int dim=-1) const
Definition: boolNDArray.cc:71
bool is_shared(void)
Definition: Array.h:588
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2530
void mx_inline_or(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:216
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: boolNDArray.cc:117
b
Definition: cellfun.cc:400
bool mx_inline_all(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:180
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
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:186
boolNDArray & mx_el_or_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:157
T mx_inline_count(const bool *v, octave_idx_type n)
Definition: mx-inlines.cc:752
boolNDArray & insert(const boolNDArray &a, octave_idx_type r, octave_idx_type c)
Definition: boolNDArray.cc:95