GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "Array-util.h"
31 #include "boolNDArray.h"
32 #include "CNDArray.h"
33 #include "mx-base.h"
34 #include "lo-ieee.h"
35 #include "mx-op-defs.h"
36 
37 #include "bsxfun-defs.cc"
38 
39 // unary operations
40 
43 {
44  return do_mx_unary_op<bool, bool> (*this, mx_inline_not);
45 }
46 
49 {
50  if (is_shared ())
51  *this = ! *this;
52  else
53  do_mx_inplace_op<bool> (*this, mx_inline_not2);
54 
55  return *this;
56 }
57 
58 // FIXME: this is not quite the right thing.
59 
61 boolNDArray::all (int dim) const
62 {
63  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_all);
64 }
65 
67 boolNDArray::any (int dim) const
68 {
69  return do_mx_red_op<bool, bool> (*this, dim, mx_inline_any);
70 }
71 
75 {
76  if (rb.numel () > 0)
77  insert (rb, ra_idx);
78  return *this;
79 }
80 
83 {
84  Array<bool>::insert (a, r, c);
85  return *this;
86 }
87 
90 {
92  return *this;
93 }
94 
95 void
97  const dim_vector& dimensions,
98  int start_dimension)
99 {
100  ::increment_index (ra_idx, dimensions, start_dimension);
101 }
102 
105  const dim_vector& dimensions)
106 {
108 }
109 
112 {
113  return Array<bool>::diag (k);
114 }
115 
118 {
119  return Array<bool>::diag (m, n);
120 }
121 
124 
127 
130 
133 {
134  if (a.is_shared ())
135  a = mx_el_and (a, b);
136  else
137  do_mm_inplace_op<bool, bool> (a, b, mx_inline_and2, mx_inline_and2,
138  "operator &=");
139 
140  return a;
141 }
142 
145 {
146  if (a.is_shared ())
147  a = mx_el_or (a, b);
148  else
149  do_mm_inplace_op<bool, bool> (a, b, mx_inline_or2, mx_inline_or2,
150  "operator |=");
151 
152  return a;
153 }
154 
octave_idx_type compute_index(octave_idx_type n, const dim_vector &dims)
Definition: Array-util.cc:177
boolNDArray & mx_el_or_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:144
boolNDArray mx_el_and(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
boolNDArray mx_el_or(const boolNDArray &m1, const boolNDArray &m2)
Definition: boolNDArray.cc:122
boolNDArray & mx_el_and_assign(boolNDArray &a, const boolNDArray &b)
Definition: boolNDArray.cc:132
#define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP)
Definition: bsxfun-defs.cc:221
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:1584
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:377
dim_vector dimensions
Definition: Array.h:217
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2528
bool is_shared(void)
Definition: Array.h:587
boolNDArray any(int dim=-1) const
Definition: boolNDArray.cc:67
boolNDArray diag(octave_idx_type k=0) const
Definition: boolNDArray.cc:111
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: boolNDArray.cc:104
boolNDArray & insert(const boolNDArray &a, octave_idx_type r, octave_idx_type c)
Definition: boolNDArray.cc:82
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: boolNDArray.cc:96
boolNDArray & invert(void)
Definition: boolNDArray.cc:48
boolNDArray concat(const boolNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: boolNDArray.cc:73
boolNDArray all(int dim=-1) const
Definition: boolNDArray.cc:61
boolNDArray operator!(void) const
Definition: boolNDArray.cc:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
void mx_inline_and2(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:225
void mx_inline_not2(size_t n, bool *r)
Definition: mx-inlines.cc:187
void mx_inline_any(const T *v, bool *r, octave_idx_type l, octave_idx_type n, octave_idx_type u)
Definition: mx-inlines.cc:851
void mx_inline_or(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:217
void mx_inline_and(size_t n, bool *r, const X *x, const Y *y)
Definition: mx-inlines.cc:216
void mx_inline_not(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:181
void mx_inline_all(const T *v, bool *r, octave_idx_type m, octave_idx_type n)
Definition: mx-inlines.cc:817
T octave_idx_type m
Definition: mx-inlines.cc:773
void mx_inline_or2(size_t n, bool *r, const X *x)
Definition: mx-inlines.cc:241
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:350
#define NDS_BOOL_OPS(ND, S)
Definition: mx-op-defs.h:256
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:333
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:303
#define NDS_CMP_OPS(ND, S)
Definition: mx-op-defs.h:239
#define SND_CMP_OPS(S, ND)
Definition: mx-op-defs.h:286
const octave_base_value const Array< octave_idx_type > & ra_idx