GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
fCRowVector.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-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 <iostream>
28 
29 #include "Array-util.h"
30 #include "functor.h"
31 #include "lo-blas-proto.h"
32 #include "lo-error.h"
33 #include "mx-base.h"
34 #include "mx-inlines.cc"
35 #include "oct-cmplx.h"
36 
37 // FloatComplex Row Vector class
38 
39 bool
41 {
42  octave_idx_type len = numel ();
43  if (len != a.numel ())
44  return 0;
45  return mx_inline_equal (len, data (), a.data ());
46 }
47 
48 bool
50 {
51  return !(*this == a);
52 }
53 
54 // destructive insert/delete/reorder operations
55 
58 {
59  octave_idx_type a_len = a.numel ();
60 
61  if (c < 0 || c + a_len > numel ())
62  (*current_liboctave_error_handler) ("range error for insert");
63 
64  if (a_len > 0)
65  {
66  make_unique ();
67 
68  for (octave_idx_type i = 0; i < a_len; i++)
69  xelem (c+i) = a.elem (i);
70  }
71 
72  return *this;
73 }
74 
78 {
79  octave_idx_type a_len = a.numel ();
80 
81  if (c < 0 || c + a_len > numel ())
82  (*current_liboctave_error_handler) ("range error for insert");
83 
84  if (a_len > 0)
85  {
86  make_unique ();
87 
88  for (octave_idx_type i = 0; i < a_len; i++)
89  xelem (c+i) = a.elem (i);
90  }
91 
92  return *this;
93 }
94 
97 {
98  octave_idx_type len = numel ();
99 
100  if (len > 0)
101  {
102  make_unique ();
103 
104  for (octave_idx_type i = 0; i < len; i++)
105  xelem (i) = val;
106  }
107 
108  return *this;
109 }
110 
113 {
114  octave_idx_type len = numel ();
115 
116  if (len > 0)
117  {
118  make_unique ();
119 
120  for (octave_idx_type i = 0; i < len; i++)
121  xelem (i) = val;
122  }
123 
124  return *this;
125 }
126 
129 {
130  octave_idx_type len = numel ();
131 
132  if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len)
133  (*current_liboctave_error_handler) ("range error for fill");
134 
135  if (c1 > c2) { std::swap (c1, c2); }
136 
137  if (c2 >= c1)
138  {
139  make_unique ();
140 
141  for (octave_idx_type i = c1; i <= c2; i++)
142  xelem (i) = val;
143  }
144 
145  return *this;
146 }
147 
151 {
152  octave_idx_type len = numel ();
153 
154  if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len)
155  (*current_liboctave_error_handler) ("range error for fill");
156 
157  if (c1 > c2) { std::swap (c1, c2); }
158 
159  if (c2 >= c1)
160  {
161  make_unique ();
162 
163  for (octave_idx_type i = c1; i <= c2; i++)
164  xelem (i) = val;
165  }
166 
167  return *this;
168 }
169 
172 {
173  octave_idx_type len = numel ();
174  octave_idx_type nc_insert = len;
175  FloatComplexRowVector retval (len + a.numel ());
176  retval.insert (*this, 0);
177  retval.insert (a, nc_insert);
178  return retval;
179 }
180 
183 {
184  octave_idx_type len = numel ();
185  octave_idx_type nc_insert = len;
186  FloatComplexRowVector retval (len + a.numel ());
187  retval.insert (*this, 0);
188  retval.insert (a, nc_insert);
189  return retval;
190 }
191 
194 {
196 }
197 
200 {
202 }
203 
206 {
207  return do_mx_unary_map<FloatComplex, FloatComplex, std::conj<float>> (a);
208 }
209 
210 // resize is the destructive equivalent for this one
211 
214 {
215  if (c1 > c2) { std::swap (c1, c2); }
216 
217  octave_idx_type new_c = c2 - c1 + 1;
218 
220 
221  for (octave_idx_type i = 0; i < new_c; i++)
222  result.elem (i) = elem (c1+i);
223 
224  return result;
225 }
226 
229 {
231 
232  for (octave_idx_type i = 0; i < n; i++)
233  result.elem (i) = elem (r1+i);
234 
235  return result;
236 }
237 
238 // row vector by row vector -> row vector operations
239 
242 {
243  octave_idx_type len = numel ();
244 
245  octave_idx_type a_len = a.numel ();
246 
247  if (len != a_len)
248  octave::err_nonconformant ("operator +=", len, a_len);
249 
250  if (len == 0)
251  return *this;
252 
253  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
254 
255  mx_inline_add2 (len, d, a.data ());
256  return *this;
257 }
258 
261 {
262  octave_idx_type len = numel ();
263 
264  octave_idx_type a_len = a.numel ();
265 
266  if (len != a_len)
267  octave::err_nonconformant ("operator -=", len, a_len);
268 
269  if (len == 0)
270  return *this;
271 
272  FloatComplex *d = fortran_vec (); // Ensures only 1 reference to my privates!
273 
274  mx_inline_sub2 (len, d, a.data ());
275  return *this;
276 }
277 
278 // row vector by matrix -> row vector
279 
282 {
284 
285  F77_INT len = octave::to_f77_int (v.numel ());
286 
287  F77_INT a_nr = octave::to_f77_int (a.rows ());
288  F77_INT a_nc = octave::to_f77_int (a.cols ());
289 
290  if (a_nr != len)
291  octave::err_nonconformant ("operator *", 1, len, a_nr, a_nc);
292 
293  if (len == 0)
294  retval.resize (a_nc, 0.0);
295  else
296  {
297  // Transpose A to form A'*x == (x'*A)'
298 
299  F77_INT ld = a_nr;
300 
301  retval.resize (a_nc);
302  FloatComplex *y = retval.fortran_vec ();
303 
304  F77_XFCN (cgemv, CGEMV, (F77_CONST_CHAR_ARG2 ("T", 1),
305  a_nr, a_nc, 1.0, F77_CONST_CMPLX_ARG (a.data ()),
306  ld, F77_CONST_CMPLX_ARG (v.data ()), 1, 0.0, F77_CMPLX_ARG (y), 1
307  F77_CHAR_ARG_LEN (1)));
308  }
309 
310  return retval;
311 }
312 
315 {
317  return tmp * a;
318 }
319 
320 // other operations
321 
324 {
325  octave_idx_type len = numel ();
326  if (len == 0)
327  return FloatComplex (0.0);
328 
329  FloatComplex res = elem (0);
330  float absres = std::abs (res);
331 
332  for (octave_idx_type i = 1; i < len; i++)
333  if (std::abs (elem (i)) < absres)
334  {
335  res = elem (i);
336  absres = std::abs (res);
337  }
338 
339  return res;
340 }
341 
344 {
345  octave_idx_type len = numel ();
346  if (len == 0)
347  return FloatComplex (0.0);
348 
349  FloatComplex res = elem (0);
350  float absres = std::abs (res);
351 
352  for (octave_idx_type i = 1; i < len; i++)
353  if (std::abs (elem (i)) > absres)
354  {
355  res = elem (i);
356  absres = std::abs (res);
357  }
358 
359  return res;
360 }
361 
362 // i/o
363 
364 std::ostream&
365 operator << (std::ostream& os, const FloatComplexRowVector& a)
366 {
367 // int field_width = os.precision () + 7;
368  for (octave_idx_type i = 0; i < a.numel (); i++)
369  os << ' ' /* setw (field_width) */ << a.elem (i);
370  return os;
371 }
372 
373 std::istream&
375 {
376  octave_idx_type len = a.numel ();
377 
378  if (len > 0)
379  {
381  for (octave_idx_type i = 0; i < len; i++)
382  {
383  is >> tmp;
384  if (is)
385  a.elem (i) = tmp;
386  else
387  break;
388  }
389  }
390  return is;
391 }
392 
393 // row vector by column vector -> scalar
394 
395 // row vector by column vector -> scalar
396 
399 {
401  return v * tmp;
402 }
403 
406 {
407  FloatComplex retval (0.0, 0.0);
408 
409  F77_INT len = octave::to_f77_int (v.numel ());
410 
411  F77_INT a_len = octave::to_f77_int (a.numel ());
412 
413  if (len != a_len)
414  octave::err_nonconformant ("operator *", len, a_len);
415 
416  if (len != 0)
417  F77_FUNC (xcdotu, XCDOTU) (len, F77_CONST_CMPLX_ARG (v.data ()), 1,
418  F77_CONST_CMPLX_ARG (a.data ()), 1, F77_CMPLX_ARG (&retval));
419 
420  return retval;
421 }
422 
423 // other operations
424 
427 {
429 
430  if (n < 1)
431  return retval;
432  else
433  retval.clear (n);
434 
435  retval(0) = x1;
436 
437  FloatComplex delta = (x2 - x1) / (n - 1.0f);
438  for (octave_idx_type i = 1; i < n-1; i++)
439  retval(i) = x1 + static_cast<float> (i)*delta;
440 
441  retval(n-1) = x2;
442 
443  return retval;
444 }
FloatComplexRowVector append(const FloatRowVector &a) const
Definition: fCRowVector.cc:171
void mx_inline_add2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:125
FloatComplexRowVector conj(const FloatComplexRowVector &a)
Definition: fCRowVector.cc:205
void mx_inline_sub2(size_t n, R *r, const X *x)
Definition: mx-inlines.cc:126
FloatComplexRowVector & fill(float val)
Definition: fCRowVector.cc:96
const FloatComplex * data(void) const
Definition: Array.h:582
MArray< T > hermitian(T(*fcn)(const T &)=nullptr) const
Definition: MArray.h:106
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
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 * f
std::ostream & operator<<(std::ostream &os, const FloatComplexRowVector &a)
Definition: fCRowVector.cc:365
const FloatComplex * fortran_vec(void) const
Definition: Array.h:584
FloatComplex min(void) const
Definition: fCRowVector.cc:323
FloatComplexColumnVector hermitian(void) const
Definition: fCRowVector.cc:193
static T abs(T x)
Definition: pr-output.cc:1696
FloatComplexRowVector operator*(const FloatComplexRowVector &v, const FloatComplexMatrix &a)
Definition: fCRowVector.cc:281
FloatComplex & elem(octave_idx_type n)
Definition: Array.h:488
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
MArray< T > transpose(void) const
Definition: MArray.h:103
#define F77_XFCN(f, F, args)
Definition: f77-fcn.h:41
FloatComplexRowVector & operator+=(const FloatRowVector &a)
Definition: fCRowVector.cc:241
octave_idx_type a_nc
Definition: sylvester.cc:74
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
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:511
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
bool swap
Definition: load-save.cc:738
bool operator==(const FloatComplexRowVector &a) const
Definition: fCRowVector.cc:40
FloatComplexRowVector linspace(const FloatComplex &x1, const FloatComplex &x2, octave_idx_type n)
Definition: fCRowVector.cc:426
octave_idx_type a_nr
Definition: sylvester.cc:73
void make_unique(void)
Definition: Array.h:187
std::istream & operator>>(std::istream &is, FloatComplexRowVector &a)
Definition: fCRowVector.cc:374
double tmp
Definition: data.cc:6252
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
octave_value retval
Definition: data.cc:6246
FloatComplex max(void) const
Definition: fCRowVector.cc:343
F77_RET_T F77_FUNC(xerbla, XERBLA)
Definition: xerbla.c:57
With real return the complex result
Definition: data.cc:3260
FloatComplex & xelem(octave_idx_type n)
Definition: Array.h:458
#define F77_CMPLX_ARG(x)
Definition: f77-fcn.h:309
This is a simple wrapper template that will subclass an Array<T> type or any later type derived from ...
Definition: Array.h:892
octave_f77_int_type F77_INT
Definition: f77-fcn.h:305
bool operator!=(const FloatComplexRowVector &a) const
Definition: fCRowVector.cc:49
FloatComplexRowVector extract_n(octave_idx_type c1, octave_idx_type n) const
Definition: fCRowVector.cc:228
the element is set to zero In other the statement xample y
Definition: data.cc:5264
FloatComplexColumnVector transpose(void) const
Definition: fCRowVector.cc:199
#define F77_CONST_CMPLX_ARG(x)
Definition: f77-fcn.h:312
for i
Definition: data.cc:5264
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
FloatComplexRowVector & insert(const FloatRowVector &a, octave_idx_type c)
Definition: fCRowVector.cc:57
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
bool mx_inline_equal(size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:569
write the output to stdout if nargout is
Definition: load-save.cc:1612
FloatComplexRowVector extract(octave_idx_type c1, octave_idx_type c2) const
Definition: fCRowVector.cc:213
subroutine xcdotu(n, zx, incx, zy, incy, retval)
Definition: xcdotu.f:2
octave::stream os
Definition: file-io.cc:627
FloatComplexRowVector & operator-=(const FloatRowVector &a)
Definition: fCRowVector.cc:260