GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
chNDArray.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <string>
28 
29 #include "Array-util.h"
30 #include "chNDArray.h"
31 #include "mx-base.h"
32 #include "lo-ieee.h"
33 #include "lo-mappers.h"
34 #include "mx-op-defs.h"
35 #include "str-vec.h"
36 
37 #include "bsxfun-defs.cc"
38 
40  : Array<char> ()
41 {
42  octave_idx_type n = 1;
43 
44  resize1 (n);
45 
46  elem (0) = c;
47 }
48 
50  : Array<char> ()
51 {
52  octave_idx_type n = (s ? strlen (s) : 0);
53 
54  resize1 (n);
55 
56  for (octave_idx_type i = 0; i < n; i++)
57  elem (i) = s[i];
58 }
59 
61  : Array<char> ()
62 {
63  octave_idx_type n = s.length ();
64 
65  resize1 (n);
66 
67  for (octave_idx_type i = 0; i < n; i++)
68  elem (i) = s[i];
69 }
70 
71 charNDArray::charNDArray (const string_vector& s, char fill_value)
72  : Array<char> (dim_vector (s.numel (), s.max_length ()), fill_value)
73 {
74  octave_idx_type nr = rows ();
75 
76  for (octave_idx_type i = 0; i < nr; i++)
77  {
78  const std::string si = s(i);
79  octave_idx_type nc = si.length ();
80  for (octave_idx_type j = 0; j < nc; j++)
81  elem (i, j) = si[j];
82  }
83 }
84 
85 // FIXME: this is not quite the right thing.
86 
88 charNDArray::all (int dim) const
89 {
90  return do_mx_red_op<bool, char> (*this, dim, mx_inline_all);
91 }
92 
94 charNDArray::any (int dim) const
95 {
96  return do_mx_red_op<bool, char> (*this, dim, mx_inline_any);
97 }
98 
102 {
103  if (rb.numel () > 0)
104  insert (rb, ra_idx);
105  return *this;
106 }
107 
110 {
111  charNDArray tmp (rb.dims ());
112  octave_idx_type nel = rb.numel ();
113 
114  if (rb.isempty ())
115  return *this;
116 
117  for (octave_idx_type i = 0; i < nel; i++)
118  {
119  double d = rb.elem (i);
120 
121  if (octave::math::isnan (d))
122  (*current_liboctave_error_handler)
123  ("invalid conversion from NaN to character");
124 
126 
127  if (ival < 0 || ival > std::numeric_limits<unsigned char>::max ())
128  // FIXME: is there something better to do? Should we warn the user?
129  ival = 0;
130 
131  tmp.elem (i) = static_cast<char>(ival);
132  }
133 
134  insert (tmp, ra_idx);
135  return *this;
136 }
137 
139 charNDArray::max (int dim) const
140 {
141  return do_mx_minmax_op<char> (*this, dim, mx_inline_max);
142 }
143 
145 charNDArray::max (Array<octave_idx_type>& idx_arg, int dim) const
146 {
147  return do_mx_minmax_op<char> (*this, idx_arg, dim, mx_inline_max);
148 }
149 
151 charNDArray::min (int dim) const
152 {
153  return do_mx_minmax_op<char> (*this, dim, mx_inline_min);
154 }
155 
157 charNDArray::min (Array<octave_idx_type>& idx_arg, int dim) const
158 {
159  return do_mx_minmax_op<char> (*this, idx_arg, dim, mx_inline_min);
160 }
161 
164 {
165  Array<char>::insert (a, r, c);
166  return *this;
167 }
168 
171 {
173  return *this;
174 }
175 
176 void
178  const dim_vector& dimensions,
179  int start_dimension)
180 {
181  ::increment_index (ra_idx, dimensions, start_dimension);
182 }
183 
186  const dim_vector& dimensions)
187 {
189 }
190 
193 {
194  return Array<char>::diag (k);
195 }
196 
199 {
200  return Array<char>::diag (m, n);
201 }
202 
204 min (char d, const charNDArray& m)
205 {
208 }
209 
211 min (const charNDArray& m, char d)
212 {
214  char> (m, d, mx_inline_xmin);
215 }
216 
218 min (const charNDArray& a, const charNDArray& b)
219 {
223  mx_inline_xmin, "min");
224 }
225 
227 max (char d, const charNDArray& m)
228 {
231 }
232 
234 max (const charNDArray& m, char d)
235 {
237  char> (m, d, mx_inline_xmax);
238 }
239 
241 max (const charNDArray& a, const charNDArray& b)
242 {
246  mx_inline_xmax, "max");
247 }
248 
251 
254 
257 
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
octave_idx_type rows(void) const
Definition: Array.h:404
#define NDS_BOOL_OPS(ND, S)
Definition: mx-op-defs.h:255
#define NDS_CMP_OPS(ND, S)
Definition: mx-op-defs.h:238
Array< R > do_sm_binary_op(const X &x, const Array< Y > &y, void(*op)(size_t, R *, X, const Y *))
Definition: mx-inlines.cc:531
const octave_base_value const Array< octave_idx_type > & ra_idx
#define SND_CMP_OPS(S, ND)
Definition: mx-op-defs.h:285
boolNDArray any(int dim=-1) const
Definition: chNDArray.cc:94
bool isempty(void) const
Definition: Array.h:565
charNDArray min(int dim=-1) const
Definition: chNDArray.cc:151
for large enough k
Definition: lu.cc:617
charNDArray(void)
Definition: chNDArray.h:42
bool isnan(bool)
Definition: lo-mappers.h:187
charNDArray concat(const charNDArray &rb, const Array< octave_idx_type > &ra_idx)
Definition: chNDArray.cc:100
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:442
charNDArray diag(octave_idx_type k=0) const
Definition: chNDArray.cc:192
static void increment_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions, int start_dimension=0)
Definition: chNDArray.cc:177
char & elem(octave_idx_type n)
Definition: Array.h:488
void mx_inline_max(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:962
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
s
Definition: file-io.cc:2729
bool mx_inline_any(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
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
void mx_inline_xmin(size_t n, T *r, const T *x, const T *y)
Definition: mx-inlines.cc:335
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
#define NDND_CMP_OPS(ND1, ND2)
Definition: mx-op-defs.h:332
#define NDND_BOOL_OPS(ND1, ND2)
Definition: mx-op-defs.h:349
Array< R > do_mm_binary_op(const Array< X > &x, const Array< Y > &y, void(*op)(size_t, R *, const X *, const Y *), void(*op1)(size_t, R *, X, const Y *), void(*op2)(size_t, R *, const X *, Y), const char *opname)
Definition: mx-inlines.cc:497
void resize1(octave_idx_type n, const char &rfv)
Definition: Array.cc:897
boolNDArray all(int dim=-1) const
Definition: chNDArray.cc:88
double tmp
Definition: data.cc:6252
#define SND_BOOL_OPS(S, ND)
Definition: mx-op-defs.h:302
T::size_type strlen(const typename T::value_type *str)
Definition: oct-string.cc:75
charNDArray max(int dim=-1) const
Definition: chNDArray.cc:139
#define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY)
Definition: bsxfun-defs.cc:242
charNDArray & insert(const charNDArray &a, octave_idx_type r, octave_idx_type c)
Definition: chNDArray.cc:163
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:227
T::size_type numel(const T &str)
Definition: oct-string.cc:61
char element_type
Definition: Array.h:201
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:182
Array< T > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2530
b
Definition: cellfun.cc:400
for i
Definition: data.cc:5264
bool mx_inline_all(const T *v, octave_idx_type n)
Definition: mx-inlines.cc:753
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
static octave_idx_type compute_index(Array< octave_idx_type > &ra_idx, const dim_vector &dimensions)
Definition: chNDArray.cc:185
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
Array< R > do_ms_binary_op(const Array< X > &x, const Y &y, void(*op)(size_t, R *, const X *, Y))
Definition: mx-inlines.cc:521
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:204
void mx_inline_xmax(size_t n, T *r, const T *x, const T *y)
Definition: mx-inlines.cc:359
void mx_inline_min(const T *v, T *r, octave_idx_type n)
Definition: mx-inlines.cc:961