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
op-bm-bm.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
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
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "gripes.h"
28 #include "oct-obj.h"
29 #include "ov.h"
30 #include "ov-bool-mat.h"
31 #include "ov-scalar.h"
32 #include "ov-range.h"
33 #include "ov-re-mat.h"
34 #include "ov-flt-re-mat.h"
35 #include "ov-re-sparse.h"
36 #include "ov-str-mat.h"
37 #include "ov-int8.h"
38 #include "ov-int16.h"
39 #include "ov-int32.h"
40 #include "ov-int64.h"
41 #include "ov-uint8.h"
42 #include "ov-uint16.h"
43 #include "ov-uint32.h"
44 #include "ov-uint64.h"
45 #include "ov-typeinfo.h"
46 #include "ov-null-mat.h"
47 #include "ops.h"
48 #include "xdiv.h"
49 #include "xpow.h"
50 
51 // unary bool matrix ops.
52 
53 DEFNDUNOP_OP (not, bool_matrix, bool_array, !)
54 DEFNDUNOP_OP (uplus, bool_matrix, array, +)
55 DEFNDUNOP_OP (uminus, bool_matrix, array, -)
56 
57 DEFNCUNOP_METHOD (invert, bool_matrix, invert)
58 
59 DEFUNOP (transpose, bool_matrix)
60 {
62 
63  if (v.ndims () > 2)
64  {
65  error ("transpose not defined for N-d objects");
66  return octave_value ();
67  }
68  else
69  return octave_value (v.bool_matrix_value ().transpose ());
70 }
71 
72 // bool matrix by bool matrix ops.
73 
74 DEFNDBINOP_FN (eq, bool_matrix, bool_matrix, bool_array, bool_array, mx_el_eq)
75 DEFNDBINOP_FN (ne, bool_matrix, bool_matrix, bool_array, bool_array, mx_el_ne)
76 
77 DEFNDBINOP_FN (el_and, bool_matrix, bool_matrix, bool_array, bool_array,
79 
80 DEFNDBINOP_FN (el_or, bool_matrix, bool_matrix, bool_array, bool_array,
82 
83 DEFNDBINOP_FN (el_not_and, bool_matrix, bool_matrix, bool_array, bool_array,
85 
86 DEFNDBINOP_FN (el_not_or, bool_matrix, bool_matrix, bool_array, bool_array,
88 
89 DEFNDBINOP_FN (el_and_not, bool_matrix, bool_matrix, bool_array, bool_array,
91 
92 DEFNDBINOP_FN (el_or_not, bool_matrix, bool_matrix, bool_array, bool_array,
94 
95 DEFNDCATOP_FN (bm_bm, bool_matrix, bool_matrix, bool_array, bool_array, concat)
96 DEFNDCATOP_FN (bm_m, bool_matrix, matrix, array, array, concat)
97 DEFNDCATOP_FN (m_bm, matrix, bool_matrix, array, array, concat)
98 DEFNDCATOP_FN (bm_fm, bool_matrix, float_matrix, float_array, float_array,
100 DEFNDCATOP_FN (fm_bm, float_matrix, bool_matrix, float_array, float_array,
102 
103 DEFNDASSIGNOP_FN (assign, bool_matrix, bool_matrix, bool_array, assign)
104 DEFNDASSIGNOP_FNOP (assign_and, bool_matrix, bool_matrix, bool_array,
106 DEFNDASSIGNOP_FNOP (assign_or, bool_matrix, bool_matrix, bool_array,
108 
109 DEFNULLASSIGNOP_FN (null_assign, bool_matrix, delete_elements)
110 
111 static octave_value
113  const octave_value_list& idx,
114  const octave_base_value& a2)
115 {
116  octave_bool_matrix& v1 = dynamic_cast<octave_bool_matrix&> (a1);
117 
118  // FIXME: perhaps add a warning for this conversion
119  // if the values are not all 0 or 1?
120 
121  boolNDArray v2 = a2.bool_array_value (true);
122 
123  if (! error_state)
124  v1.assign (idx, v2);
125 
126  return octave_value ();
127 }
128 
129 DEFCONVFN (matrix_to_bool_matrix, matrix, bool)
130 DEFCONVFN (scalar_to_bool_matrix, scalar, bool)
131 
132 void
134 {
140 
142 
145 
149  el_not_and);
151  el_not_or);
153  el_and_not);
155  el_or_not);
156 
162 
163  INSTALL_CONVOP (octave_matrix, octave_bool_matrix, matrix_to_bool_matrix);
164  INSTALL_CONVOP (octave_scalar, octave_bool_matrix, scalar_to_bool_matrix);
165 
167 
169  conv_and_assign);
171  conv_and_assign);
173  conv_and_assign);
174 
176  conv_and_assign);
177 
179  conv_and_assign);
180 
181  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int8_matrix,
182  conv_and_assign);
183  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int16_matrix,
184  conv_and_assign);
185  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int32_matrix,
186  conv_and_assign);
187  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_int64_matrix,
188  conv_and_assign);
189 
190  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint8_matrix,
191  conv_and_assign);
192  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint16_matrix,
193  conv_and_assign);
194  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint32_matrix,
195  conv_and_assign);
196  INSTALL_ASSIGNOP (op_asn_eq, octave_bool_matrix, octave_uint64_matrix,
197  conv_and_assign);
198 
200  null_assign);
202  null_assign);
204  null_assign);
205 
207  assign_and);
209  assign_or);
210 }