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
fCColVector.cc
Go to the documentation of this file.
1 // ColumnVector manipulations.
2 /*
3 
4 Copyright (C) 1994-2017 John W. Eaton
5 Copyright (C) 2010 VZLU Prague
6 
7 This file is part of Octave.
8 
9 Octave is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13 
14 Octave is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include <iostream>
30 
31 #include "Array-util.h"
32 #include "functor.h"
33 #include "lo-blas-proto.h"
34 #include "lo-error.h"
35 #include "mx-base.h"
36 #include "mx-inlines.cc"
37 #include "oct-cmplx.h"
38 
39 // FloatComplex Column Vector class
40 
42  : MArray<FloatComplex> (a)
43 { }
44 
45 bool
47 {
48  octave_idx_type len = numel ();
49  if (len != a.numel ())
50  return 0;
51  return mx_inline_equal (len, data (), a.data ());
52 }
53 
54 bool
56 {
57  return !(*this == a);
58 }
59 
60 // destructive insert/delete/reorder operations
61 
64 {
65  octave_idx_type a_len = a.numel ();
66 
67  if (r < 0 || r + a_len > numel ())
68  (*current_liboctave_error_handler) ("range error for insert");
69 
70  if (a_len > 0)
71  {
72  make_unique ();
73 
74  for (octave_idx_type i = 0; i < a_len; i++)
75  xelem (r+i) = a.elem (i);
76  }
77 
78  return *this;
79 }
80 
84 {
85  octave_idx_type a_len = a.numel ();
86 
87  if (r < 0 || r + a_len > numel ())
88  (*current_liboctave_error_handler) ("range error for insert");
89 
90  if (a_len > 0)
91  {
92  make_unique ();
93 
94  for (octave_idx_type i = 0; i < a_len; i++)
95  xelem (r+i) = a.elem (i);
96  }
97 
98  return *this;
99 }
100 
103 {
104  octave_idx_type len = numel ();
105 
106  if (len > 0)
107  {
108  make_unique ();
109 
110  for (octave_idx_type i = 0; i < len; i++)
111  xelem (i) = val;
112  }
113 
114  return *this;
115 }
116 
119 {
120  octave_idx_type len = numel ();
121 
122  if (len > 0)
123  {
124  make_unique ();
125 
126  for (octave_idx_type i = 0; i < len; i++)
127  xelem (i) = val;
128  }
129 
130  return *this;
131 }
132 
136 {
137  octave_idx_type len = numel ();
138 
139  if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len)
140  (*current_liboctave_error_handler) ("range error for fill");
141 
142  if (r1 > r2) { std::swap (r1, r2); }
143 
144  if (r2 >= r1)
145  {
146  make_unique ();
147 
148  for (octave_idx_type i = r1; i <= r2; i++)
149  xelem (i) = val;
150  }
151 
152  return *this;
153 }
154 
158 {
159  octave_idx_type len = numel ();
160 
161  if (r1 < 0 || r2 < 0 || r1 >= len || r2 >= len)
162  (*current_liboctave_error_handler) ("range error for fill");
163 
164  if (r1 > r2) { std::swap (r1, r2); }
165 
166  if (r2 >= r1)
167  {
168  make_unique ();
169 
170  for (octave_idx_type i = r1; i <= r2; i++)
171  xelem (i) = val;
172  }
173 
174  return *this;
175 }
176 
179 {
180  octave_idx_type len = numel ();
181  octave_idx_type nr_insert = len;
183  retval.insert (*this, 0);
184  retval.insert (a, nr_insert);
185  return retval;
186 }
187 
190 {
191  octave_idx_type len = numel ();
192  octave_idx_type nr_insert = len;
194  retval.insert (*this, 0);
195  retval.insert (a, nr_insert);
196  return retval;
197 }
198 
201 {
203 }
204 
207 {
209 }
210 
213 {
214  return do_mx_unary_map<float, FloatComplex, std::abs> (*this);
215 }
216 
219 {
220  return do_mx_unary_map<FloatComplex, FloatComplex, std::conj<float> > (a);
221 }
222 
223 // resize is the destructive equivalent for this one
224 
227 {
228  if (r1 > r2) { std::swap (r1, r2); }
229 
230  octave_idx_type new_r = r2 - r1 + 1;
231 
233 
234  for (octave_idx_type i = 0; i < new_r; i++)
235  result.elem (i) = elem (r1+i);
236 
237  return result;
238 }
239 
242  octave_idx_type n) const
243 {
245 
246  for (octave_idx_type i = 0; i < n; i++)
247  result.elem (i) = elem (r1+i);
248 
249  return result;
250 }
251 
252 // column vector by column vector -> column vector operations
253 
256 {
257  octave_idx_type len = numel ();
258 
259  octave_idx_type a_len = a.numel ();
260 
261  if (len != a_len)
262  octave::err_nonconformant ("operator +=", len, a_len);
263 
264  if (len == 0)
265  return *this;
266 
267  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
268 
269  mx_inline_add2 (len, d, a.data ());
270  return *this;
271 }
272 
275 {
276  octave_idx_type len = numel ();
277 
278  octave_idx_type a_len = a.numel ();
279 
280  if (len != a_len)
281  octave::err_nonconformant ("operator -=", len, a_len);
282 
283  if (len == 0)
284  return *this;
285 
286  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
287 
288  mx_inline_sub2 (len, d, a.data ());
289  return *this;
290 }
291 
292 // matrix by column vector -> column vector operations
293 
296 {
298  return m * tmp;
299 }
300 
303 {
305 
306  octave_idx_type nr = m.rows ();
307  octave_idx_type nc = m.cols ();
308 
309  octave_idx_type a_len = a.numel ();
310 
311  if (nc != a_len)
312  octave::err_nonconformant ("operator *", nr, nc, a_len, 1);
313 
314  retval.clear (nr);
315 
316  if (nr != 0)
317  {
318  if (nc == 0)
319  retval.fill (0.0);
320  else
321  {
322  FloatComplex *y = retval.fortran_vec ();
323 
324  F77_XFCN (cgemv, CGEMV, (F77_CONST_CHAR_ARG2 ("N", 1),
325  nr, nc, 1.0f, F77_CONST_CMPLX_ARG (m.data ()), nr,
326  F77_CONST_CMPLX_ARG (a.data ()), 1, 0.0f, F77_CMPLX_ARG (y), 1
327  F77_CHAR_ARG_LEN (1)));
328  }
329  }
330 
331  return retval;
332 }
333 
334 // matrix by column vector -> column vector operations
335 
338 {
340  return tmp * a;
341 }
342 
343 // diagonal matrix by column vector -> column vector operations
344 
347 {
348  octave_idx_type nr = m.rows ();
349  octave_idx_type nc = m.cols ();
350 
351  octave_idx_type a_len = a.numel ();
352 
353  if (nc != a_len)
354  octave::err_nonconformant ("operator *", nr, nc, a_len, 1);
355 
356  if (nc == 0 || nr == 0)
357  return FloatComplexColumnVector (0);
358 
360 
361  for (octave_idx_type i = 0; i < a_len; i++)
362  result.elem (i) = a.elem (i) * m.elem (i, i);
363 
364  for (octave_idx_type i = a_len; i < nr; i++)
365  result.elem (i) = 0.0;
366 
367  return result;
368 }
369 
372 {
373  octave_idx_type nr = m.rows ();
374  octave_idx_type nc = m.cols ();
375 
376  octave_idx_type a_len = a.numel ();
377 
378  if (nc != a_len)
379  octave::err_nonconformant ("operator *", nr, nc, a_len, 1);
380 
381  if (nc == 0 || nr == 0)
382  return FloatComplexColumnVector (0);
383 
385 
386  for (octave_idx_type i = 0; i < a_len; i++)
387  result.elem (i) = a.elem (i) * m.elem (i, i);
388 
389  for (octave_idx_type i = a_len; i < nr; i++)
390  result.elem (i) = 0.0;
391 
392  return result;
393 }
394 
397 {
398  octave_idx_type nr = m.rows ();
399  octave_idx_type nc = m.cols ();
400 
401  octave_idx_type a_len = a.numel ();
402 
403  if (nc != a_len)
404  octave::err_nonconformant ("operator *", nr, nc, a_len, 1);
405 
406  if (nc == 0 || nr == 0)
407  return FloatComplexColumnVector (0);
408 
410 
411  for (octave_idx_type i = 0; i < a_len; i++)
412  result.elem (i) = a.elem (i) * m.elem (i, i);
413 
414  for (octave_idx_type i = a_len; i < nr; i++)
415  result.elem (i) = 0.0;
416 
417  return result;
418 }
419 
420 // other operations
421 
424 {
425  octave_idx_type len = numel ();
426  if (len == 0)
427  return 0.0;
428 
429  FloatComplex res = elem (0);
430  float absres = std::abs (res);
431 
432  for (octave_idx_type i = 1; i < len; i++)
433  if (std::abs (elem (i)) < absres)
434  {
435  res = elem (i);
436  absres = std::abs (res);
437  }
438 
439  return res;
440 }
441 
444 {
445  octave_idx_type len = numel ();
446  if (len == 0)
447  return 0.0;
448 
449  FloatComplex res = elem (0);
450  float absres = std::abs (res);
451 
452  for (octave_idx_type i = 1; i < len; i++)
453  if (std::abs (elem (i)) > absres)
454  {
455  res = elem (i);
456  absres = std::abs (res);
457  }
458 
459  return res;
460 }
461 
462 // i/o
463 
464 std::ostream&
465 operator << (std::ostream& os, const FloatComplexColumnVector& a)
466 {
467 // int field_width = os.precision () + 7;
468  for (octave_idx_type i = 0; i < a.numel (); i++)
469  os << /* setw (field_width) << */ a.elem (i) << "\n";
470  return os;
471 }
472 
473 std::istream&
475 {
476  octave_idx_type len = a.numel ();
477 
478  if (len > 0)
479  {
480  float tmp;
481  for (octave_idx_type i = 0; i < len; i++)
482  {
483  is >> tmp;
484  if (is)
485  a.elem (i) = tmp;
486  else
487  break;
488  }
489  }
490  return is;
491 }
void mx_inline_add2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:127
FloatComplexColumnVector operator*(const FloatComplexMatrix &m, const FloatColumnVector &a)
Definition: fCColVector.cc:295
void mx_inline_sub2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:128
FloatComplexRowVector transpose(void) const
Definition: fCColVector.cc:206
T elem(octave_idx_type r, octave_idx_type c) const
Definition: DiagArray2.h:114
bool operator!=(const FloatComplexColumnVector &a) const
Definition: fCColVector.cc:55
FloatComplexColumnVector & operator-=(const FloatColumnVector &a)
Definition: fCColVector.cc:274
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
octave_idx_type rows(void) const
Definition: DiagArray2.h:88
MArray< T > transpose(void) const
Definition: MArray.h:103
FloatColumnVector abs(void) const
Definition: fCColVector.cc:212
std::istream & operator>>(std::istream &is, FloatComplexColumnVector &a)
Definition: fCColVector.cc:474
FloatComplex min(void) const
Definition: fCColVector.cc:423
T & elem(octave_idx_type n)
Definition: Array.h:482
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
FloatComplexColumnVector conj(const FloatComplexColumnVector &a)
Definition: fCColVector.cc:218
bool operator==(const FloatComplexColumnVector &a) const
Definition: fCColVector.cc:46
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:52
FloatComplex max(void) const
Definition: fCColVector.cc:443
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
FloatComplexColumnVector & operator+=(const FloatColumnVector &a)
Definition: fCColVector.cc:255
void make_unique(void)
Definition: Array.h:185
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
const FloatComplex * data(void) const
Definition: Array.h:582
double tmp
Definition: data.cc:6300
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
octave_value retval
Definition: data.cc:6294
MArray< T > hermitian(T(*fcn)(const T &)=0) const
Definition: MArray.h:106
With real return the complex result
Definition: data.cc:3375
FloatComplexColumnVector stack(const FloatColumnVector &a) const
Definition: fCColVector.cc:178
FloatComplexRowVector hermitian(void) const
Definition: fCColVector.cc:200
FloatComplex & xelem(octave_idx_type n)
Definition: Array.h:455
void clear(octave_idx_type n)
Definition: fCColVector.h:153
octave_idx_type cols(void) const
Definition: DiagArray2.h:89
#define F77_CMPLX_ARG(x)
Definition: f77-fcn.h:339
=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))<
FloatComplexColumnVector extract_n(octave_idx_type r1, octave_idx_type n) const
Definition: fCColVector.cc:241
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
FloatComplexColumnVector & fill(float val)
Definition: fCColVector.cc:102
std::ostream & operator<<(std::ostream &os, const FloatComplexColumnVector &a)
Definition: fCColVector.cc:465
FloatComplexColumnVector & insert(const FloatColumnVector &a, octave_idx_type r)
Definition: fCColVector.cc:63
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
const FloatComplex * fortran_vec(void) const
Definition: Array.h:584
FloatComplexColumnVector extract(octave_idx_type r1, octave_idx_type r2) const
Definition: fCColVector.cc:226
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