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
chNDArray.cc
Go to the documentation of this file.
1 // N-D Array manipulations.
2 /*
3 
4 Copyright (C) 2003-2013 John W. Eaton
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 the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "Array-util.h"
29 #include "chNDArray.h"
30 #include "mx-base.h"
31 #include "lo-ieee.h"
32 #include "lo-mappers.h"
33 #include "mx-op-defs.h"
34 
35 #include "bsxfun-defs.cc"
36 
37 // FIXME: this is not quite the right thing.
38 
40 charNDArray::all (int dim) const
41 {
42  return do_mx_red_op<bool, char> (*this, dim, mx_inline_all);
43 }
44 
46 charNDArray::any (int dim) const
47 {
48  return do_mx_red_op<bool, char> (*this, dim, mx_inline_any);
49 }
50 
53  const Array<octave_idx_type>& ra_idx)
54 {
55  if (rb.numel () > 0)
56  insert (rb, ra_idx);
57  return *this;
58 }
59 
62 {
63  charNDArray tmp (rb.dims ());
64  octave_idx_type nel = rb.numel ();
65 
66  if (rb.numel () == 0)
67  return *this;
68 
69  for (octave_idx_type i = 0; i < nel; i++)
70  {
71  double d = rb.elem (i);
72 
73  if (xisnan (d))
74  {
75  (*current_liboctave_error_handler)
76  ("invalid conversion from NaN to character");
77  return *this;
78  }
79  else
80  {
81  octave_idx_type ival = NINTbig (d);
82 
83  if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
84  // FIXME: is there something better to do? Should we warn the user?
85  ival = 0;
86 
87  tmp.elem (i) = static_cast<char>(ival);
88  }
89  }
90 
91  insert (tmp, ra_idx);
92  return *this;
93 }
94 
96 charNDArray::max (int dim) const
97 {
98  return do_mx_minmax_op<char> (*this, dim, mx_inline_max);
99 }
100 
102 charNDArray::max (Array<octave_idx_type>& idx_arg, int dim) const
103 {
104  return do_mx_minmax_op<char> (*this, idx_arg, dim, mx_inline_max);
105 }
106 
108 charNDArray::min (int dim) const
109 {
110  return do_mx_minmax_op<char> (*this, dim, mx_inline_min);
111 }
112 
114 charNDArray::min (Array<octave_idx_type>& idx_arg, int dim) const
115 {
116  return do_mx_minmax_op<char> (*this, idx_arg, dim, mx_inline_min);
117 }
118 
121 {
122  Array<char>::insert (a, r, c);
123  return *this;
124 }
125 
128 {
129  Array<char>::insert (a, ra_idx);
130  return *this;
131 }
132 
135 {
136  return *this;
137 }
138 
139 void
141  const dim_vector& dimensions,
142  int start_dimension)
143 {
144  ::increment_index (ra_idx, dimensions, start_dimension);
145 }
146 
149  const dim_vector& dimensions)
150 {
151  return ::compute_index (ra_idx, dimensions);
152 }
153 
156 {
157  return Array<char>::diag (k);
158 }
159 
162 {
163  return Array<char>::diag (m, n);
164 }
165 
167 min (char d, const charNDArray& m)
168 {
170  charNDArray::element_type> (d, m, mx_inline_xmin);
171 }
172 
174 min (const charNDArray& m, char d)
175 {
177  char> (m, d, mx_inline_xmin);
178 }
179 
181 min (const charNDArray& a, const charNDArray& b)
182 {
184  charNDArray::element_type> (a, b, mx_inline_xmin,
186  mx_inline_xmin, "min");
187 }
188 
190 max (char d, const charNDArray& m)
191 {
193  charNDArray::element_type> (d, m, mx_inline_xmax);
194 }
195 
197 max (const charNDArray& m, char d)
198 {
200  char> (m, d, mx_inline_xmax);
201 }
202 
204 max (const charNDArray& a, const charNDArray& b)
205 {
207  charNDArray::element_type> (a, b, mx_inline_xmax,
209  mx_inline_xmax, "max");
210 }
211 
212 NDS_CMP_OPS (charNDArray, char)
214 
215 SND_CMP_OPS (char, charNDArray)
216 SND_BOOL_OPS (char, charNDArray)
217 
218 NDND_CMP_OPS (charNDArray, charNDArray)
219 NDND_BOOL_OPS (charNDArray, charNDArray)
220 
221 BSXFUN_STDREL_DEFS_MXLOOP (charNDArray)