GNU Octave  4.2.1
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
fCRowVector.cc
Go to the documentation of this file.
1 // RowVector manipulations.
2 /*
3 
4 Copyright (C) 1994-2017 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 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <iostream>
29 
30 #include "Array-util.h"
31 #include "functor.h"
32 #include "lo-blas-proto.h"
33 #include "lo-error.h"
34 #include "mx-base.h"
35 #include "mx-inlines.cc"
36 #include "oct-cmplx.h"
37 
38 // FloatComplex Row Vector class
39 
40 bool
42 {
43  octave_idx_type len = numel ();
44  if (len != a.numel ())
45  return 0;
46  return mx_inline_equal (len, data (), a.data ());
47 }
48 
49 bool
51 {
52  return !(*this == a);
53 }
54 
55 // destructive insert/delete/reorder operations
56 
59 {
60  octave_idx_type a_len = a.numel ();
61 
62  if (c < 0 || c + a_len > numel ())
63  (*current_liboctave_error_handler) ("range error for insert");
64 
65  if (a_len > 0)
66  {
67  make_unique ();
68 
69  for (octave_idx_type i = 0; i < a_len; i++)
70  xelem (c+i) = a.elem (i);
71  }
72 
73  return *this;
74 }
75 
79 {
80  octave_idx_type a_len = a.numel ();
81 
82  if (c < 0 || c + a_len > numel ())
83  (*current_liboctave_error_handler) ("range error for insert");
84 
85  if (a_len > 0)
86  {
87  make_unique ();
88 
89  for (octave_idx_type i = 0; i < a_len; i++)
90  xelem (c+i) = a.elem (i);
91  }
92 
93  return *this;
94 }
95 
98 {
99  octave_idx_type len = numel ();
100 
101  if (len > 0)
102  {
103  make_unique ();
104 
105  for (octave_idx_type i = 0; i < len; i++)
106  xelem (i) = val;
107  }
108 
109  return *this;
110 }
111 
114 {
115  octave_idx_type len = numel ();
116 
117  if (len > 0)
118  {
119  make_unique ();
120 
121  for (octave_idx_type i = 0; i < len; i++)
122  xelem (i) = val;
123  }
124 
125  return *this;
126 }
127 
130 {
131  octave_idx_type len = numel ();
132 
133  if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len)
134  (*current_liboctave_error_handler) ("range error for fill");
135 
136  if (c1 > c2) { std::swap (c1, c2); }
137 
138  if (c2 >= c1)
139  {
140  make_unique ();
141 
142  for (octave_idx_type i = c1; i <= c2; i++)
143  xelem (i) = val;
144  }
145 
146  return *this;
147 }
148 
152 {
153  octave_idx_type len = numel ();
154 
155  if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len)
156  (*current_liboctave_error_handler) ("range error for fill");
157 
158  if (c1 > c2) { std::swap (c1, c2); }
159 
160  if (c2 >= c1)
161  {
162  make_unique ();
163 
164  for (octave_idx_type i = c1; i <= c2; i++)
165  xelem (i) = val;
166  }
167 
168  return *this;
169 }
170 
173 {
174  octave_idx_type len = numel ();
175  octave_idx_type nc_insert = len;
176  FloatComplexRowVector retval (len + a.numel ());
177  retval.insert (*this, 0);
178  retval.insert (a, nc_insert);
179  return retval;
180 }
181 
184 {
185  octave_idx_type len = numel ();
186  octave_idx_type nc_insert = len;
187  FloatComplexRowVector retval (len + a.numel ());
188  retval.insert (*this, 0);
189  retval.insert (a, nc_insert);
190  return retval;
191 }
192 
195 {
197 }
198 
201 {
203 }
204 
207 {
208  return do_mx_unary_map<FloatComplex, FloatComplex, std::conj<float> > (a);
209 }
210 
211 // resize is the destructive equivalent for this one
212 
215 {
216  if (c1 > c2) { std::swap (c1, c2); }
217 
218  octave_idx_type new_c = c2 - c1 + 1;
219 
221 
222  for (octave_idx_type i = 0; i < new_c; i++)
223  result.elem (i) = elem (c1+i);
224 
225  return result;
226 }
227 
230 {
232 
233  for (octave_idx_type i = 0; i < n; i++)
234  result.elem (i) = elem (r1+i);
235 
236  return result;
237 }
238 
239 // row vector by row vector -> row vector operations
240 
243 {
244  octave_idx_type len = numel ();
245 
246  octave_idx_type a_len = a.numel ();
247 
248  if (len != a_len)
249  octave::err_nonconformant ("operator +=", len, a_len);
250 
251  if (len == 0)
252  return *this;
253 
254  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
255 
256  mx_inline_add2 (len, d, a.data ());
257  return *this;
258 }
259 
262 {
263  octave_idx_type len = numel ();
264 
265  octave_idx_type a_len = a.numel ();
266 
267  if (len != a_len)
268  octave::err_nonconformant ("operator -=", len, a_len);
269 
270  if (len == 0)
271  return *this;
272 
273  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
274 
275  mx_inline_sub2 (len, d, a.data ());
276  return *this;
277 }
278 
279 // row vector by matrix -> row vector
280 
283 {
285 
286  octave_idx_type len = v.numel ();
287 
288  octave_idx_type a_nr = a.rows ();
289  octave_idx_type a_nc = a.cols ();
290 
291  if (a_nr != len)
292  octave::err_nonconformant ("operator *", 1, len, a_nr, a_nc);
293 
294  if (len == 0)
295  retval.resize (a_nc, 0.0);
296  else
297  {
298  // Transpose A to form A'*x == (x'*A)'
299 
300  octave_idx_type ld = a_nr;
301 
302  retval.resize (a_nc);
303  FloatComplex *y = retval.fortran_vec ();
304 
305  F77_XFCN (cgemv, CGEMV, (F77_CONST_CHAR_ARG2 ("T", 1),
306  a_nr, a_nc, 1.0, F77_CONST_CMPLX_ARG (a.data ()),
307  ld, F77_CONST_CMPLX_ARG (v.data ()), 1, 0.0, F77_CMPLX_ARG (y), 1
308  F77_CHAR_ARG_LEN (1)));
309  }
310 
311  return retval;
312 }
313 
316 {
318  return tmp * a;
319 }
320 
321 // other operations
322 
325 {
326  octave_idx_type len = numel ();
327  if (len == 0)
328  return FloatComplex (0.0);
329 
330  FloatComplex res = elem (0);
331  float absres = std::abs (res);
332 
333  for (octave_idx_type i = 1; i < len; i++)
334  if (std::abs (elem (i)) < absres)
335  {
336  res = elem (i);
337  absres = std::abs (res);
338  }
339 
340  return res;
341 }
342 
345 {
346  octave_idx_type len = numel ();
347  if (len == 0)
348  return FloatComplex (0.0);
349 
350  FloatComplex res = elem (0);
351  float absres = std::abs (res);
352 
353  for (octave_idx_type i = 1; i < len; i++)
354  if (std::abs (elem (i)) > absres)
355  {
356  res = elem (i);
357  absres = std::abs (res);
358  }
359 
360  return res;
361 }
362 
363 // i/o
364 
365 std::ostream&
366 operator << (std::ostream& os, const FloatComplexRowVector& a)
367 {
368 // int field_width = os.precision () + 7;
369  for (octave_idx_type i = 0; i < a.numel (); i++)
370  os << " " /* setw (field_width) */ << a.elem (i);
371  return os;
372 }
373 
374 std::istream&
376 {
377  octave_idx_type len = a.numel ();
378 
379  if (len > 0)
380  {
382  for (octave_idx_type i = 0; i < len; i++)
383  {
384  is >> tmp;
385  if (is)
386  a.elem (i) = tmp;
387  else
388  break;
389  }
390  }
391  return is;
392 }
393 
394 // row vector by column vector -> scalar
395 
396 // row vector by column vector -> scalar
397 
400 {
402  return v * tmp;
403 }
404 
407 {
408  FloatComplex retval (0.0, 0.0);
409 
410  octave_idx_type len = v.numel ();
411 
412  octave_idx_type a_len = a.numel ();
413 
414  if (len != a_len)
415  octave::err_nonconformant ("operator *", len, a_len);
416 
417  if (len != 0)
418  F77_FUNC (xcdotu, XCDOTU) (len, F77_CONST_CMPLX_ARG (v.data ()), 1,
419  F77_CONST_CMPLX_ARG (a.data ()), 1, F77_CMPLX_ARG (&retval));
420 
421  return retval;
422 }
423 
424 // other operations
425 
428 {
430 
431  if (n < 1)
432  return retval;
433  else
434  retval.clear (n);
435 
436  retval(0) = x1;
437 
438  FloatComplex delta = (x2 - x1) / (n - 1.0f);
439  for (octave_idx_type i = 1; i < n-1; i++)
440  retval(i) = x1 + static_cast<float> (i)*delta;
441 
442  retval(n-1) = x2;
443 
444  return retval;
445 }
bool operator==(const FloatComplexRowVector &a) const
Definition: fCRowVector.cc:41
void mx_inline_add2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:127
FloatComplexRowVector conj(const FloatComplexRowVector &a)
Definition: fCRowVector.cc:206
void mx_inline_sub2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:128
FloatComplexRowVector & fill(float val)
Definition: fCRowVector.cc:97
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
std::ostream & operator<<(std::ostream &os, const FloatComplexRowVector &a)
Definition: fCRowVector.cc:366
MArray< T > transpose(void) const
Definition: MArray.h:103
FloatComplexRowVector extract_n(octave_idx_type c1, octave_idx_type n) const
Definition: fCRowVector.cc:229
FloatComplexColumnVector transpose(void) const
Definition: fCRowVector.cc:200
FloatComplexRowVector operator*(const FloatComplexRowVector &v, const FloatComplexMatrix &a)
Definition: fCRowVector.cc:282
T & elem(octave_idx_type n)
Definition: Array.h:482
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:52
FloatComplexRowVector & operator+=(const FloatRowVector &a)
Definition: fCRowVector.cc:242
octave_idx_type a_nc
Definition: sylvester.cc:72
octave_idx_type rows(void) const
Definition: Array.h:401
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
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:398
bool swap
Definition: load-save.cc:725
FloatComplexRowVector linspace(const FloatComplex &x1, const FloatComplex &x2, octave_idx_type n)
Definition: fCRowVector.cc:427
FloatComplexRowVector extract(octave_idx_type c1, octave_idx_type c2) const
Definition: fCRowVector.cc:214
octave_idx_type a_nr
Definition: sylvester.cc:71
void make_unique(void)
Definition: Array.h:185
const FloatComplex * data(void) const
Definition: Array.h:582
std::istream & operator>>(std::istream &is, FloatComplexRowVector &a)
Definition: fCRowVector.cc:375
double tmp
Definition: data.cc:6300
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
void resize(octave_idx_type n, const FloatComplex &rfv=FloatComplex(0))
Definition: fCRowVector.h:126
octave_value retval
Definition: data.cc:6294
F77_RET_T F77_FUNC(xstopx, XSTOPX) const
Definition: f77-fcn.c:53
FloatComplex max(void) const
Definition: fCRowVector.cc:344
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
MArray< T > hermitian(T(*fcn)(const T &)=0) const
Definition: MArray.h:106
FloatComplexColumnVector hermitian(void) const
Definition: fCRowVector.cc:194
With real return the complex result
Definition: data.cc:3375
FloatComplex & xelem(octave_idx_type n)
Definition: Array.h:455
bool operator!=(const FloatComplexRowVector &a) const
Definition: fCRowVector.cc:50
#define F77_CMPLX_ARG(x)
Definition: f77-fcn.h:339
This is a simple wrapper template that will subclass an Array type or any later type derived from ...
Definition: Array.h:888
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
OCTAVE_EXPORT octave_value_list return the value of the option it must match the dimension of the state and the relative tolerance must also be a vector of the same length tem it must match the dimension of the state and the absolute tolerance must also be a vector of the same length The local error test applied at each integration step is xample roup abs(local error in x(i))<
the element is set to zero In other the statement xample y
Definition: data.cc:5342
#define F77_CONST_CMPLX_ARG(x)
Definition: f77-fcn.h:342
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
FloatComplexRowVector & insert(const FloatRowVector &a, octave_idx_type c)
Definition: fCRowVector.cc:58
FloatComplexRowVector append(const FloatRowVector &a) const
Definition: fCRowVector.cc:172
const FloatComplex * fortran_vec(void) const
Definition: Array.h:584
bool mx_inline_equal(size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:532
octave_idx_type cols(void) const
Definition: Array.h:409
write the output to stdout if nargout is
Definition: load-save.cc:1576
subroutine xcdotu(n, zx, incx, zy, incy, retval)
Definition: xcdotu.f:1
FloatComplexRowVector & operator-=(const FloatRowVector &a)
Definition: fCRowVector.cc:261
FloatComplex min(void) const
Definition: fCRowVector.cc:324