gslcpp
Modern-C++ Wrapper for GSL
v-iface.hpp
Go to the documentation of this file.
1 /// \dir include/gslcpp/vec
2 /// \brief Types and functions specific to interface to GSL's vectors.
3 
4 /// \file include/gslcpp/vec/v-iface.hpp
5 /// \copyright 2022 Thomas E. Vaughan, all rights reserved.
6 /// \brief Definition for gsl::v_iface.
7 
8 #pragma once
9 
10 #include "../wrap/add-constant.hpp" // add_constant
11 #include "../wrap/add.hpp" // add
12 #include "../wrap/axpby.hpp" // axpby
13 #include "../wrap/div.hpp" // div
14 #include "../wrap/element.hpp" // element_t
15 #include "../wrap/equal.hpp" // equal
16 #include "../wrap/fprintf.hpp" // fprintf
17 #include "../wrap/fread.hpp" // fread
18 #include "../wrap/fscanf.hpp" // fscanf
19 #include "../wrap/fwrite.hpp" // fwrite
20 #include "../wrap/get.hpp" // get
21 #include "../wrap/imag.hpp" // imag
22 #include "../wrap/isneg.hpp" // isneg
23 #include "../wrap/isnonneg.hpp" // isnonneg
24 #include "../wrap/isnull.hpp" // isnull
25 #include "../wrap/ispos.hpp" // ispos
26 #include "../wrap/max-index.hpp" // max_index
27 #include "../wrap/max.hpp" // max
28 #include "../wrap/memcpy.hpp" // memcpy
29 #include "../wrap/min-index.hpp" // min_index
30 #include "../wrap/min.hpp" // min
31 #include "../wrap/minmax-index.hpp" // minmax_index
32 #include "../wrap/minmax.hpp" // minmax
33 #include "../wrap/mul.hpp" // mul
34 #include "../wrap/ptr.hpp" // ptr
35 #include "../wrap/real.hpp" // real
36 #include "../wrap/reverse.hpp" // reverse
37 #include "../wrap/scale.hpp" // scale
38 #include "../wrap/set-all.hpp" // set_all
39 #include "../wrap/set-basis.hpp" // set_basis
40 #include "../wrap/set-zero.hpp" // set_zero
41 #include "../wrap/set.hpp" // set
42 #include "../wrap/sub.hpp" // sub
43 #include "../wrap/subvector.hpp" // subvector
44 #include "../wrap/sum.hpp" // sum
45 #include "../wrap/swap-elements.hpp" // swap_elements
46 #include "../wrap/swap.hpp" // swap
47 #include "v-iterator.hpp" // iterator
48 #include "v-view.hpp" // view
49 #include <iostream> // ostream
50 
51 namespace gsl {
52 
53 
54 using std::is_const_v;
55 
56 
57 /// Interface for every kind of vector.
58 /// \tparam T Type of each element in vector.
59 /// \tparam N Compile-time number of elements (0 means set at run-time).
60 /// \tparam S Type specifying interface to storage of elements.
61 template<typename T, size_t N, template<typename, size_t> class S>
62 struct v_iface: public S<T, N> {
63  /// Inherit constructors.
64  using S<T, N>::S;
65 
66  /// Reference to instance of w_vector<T>, which is gsl_vector,
67  /// gsl_vector_float, or the like.
68  using S<T, N>::v;
69 
70  enum { SIZE= N /**< Size at compile-time. */ };
71 
72  /// Element-type needed by gsl::v_iterator<v_iface>.
73  using E= T;
74 
75  /// Type of iterator that points to mutable element.
76  using iterator= v_iterator<v_iface>;
77 
78  /// Type of iterator that points to immutable element.
79  using const_iterator= v_iterator<v_iface const>;
80 
81  /// Iterator that points to first element.
82  /// @return Iterator that points to first element.
83  iterator begin() { return iterator(*this, 0); }
84 
85  /// Iterator that points to element just past last element.
86  /// @return Iterator that points to element just past last element.
87  iterator end() { return iterator(*this, size()); }
88 
89  /// Iterator that points to first element.
90  /// @return Iterator that points to first element.
91  const_iterator begin() const { return const_iterator(*this, 0); }
92 
93  /// Iterator that points to element just past last element.
94  /// @return Iterator that points to element just past last element.
95  const_iterator end() const { return const_iterator(*this, size()); }
96 
97  /// Size of vector.
98  /// @return Size of vector.
99  size_t size() const { return v()->size; }
100 
101  /// Pointer to first element in vector.
102  /// - Be careful to check `v()->stride` in case data be not contiguous.
103  /// @return Pointer to first element.
104  T *data() { return (T *)v()->data; /* Cast for complex. */ }
105 
106  /// Pointer to first element in immutable vector.
107  /// - Be careful to check `v()->stride` in case data be not contiguous.
108  /// @return Pointer to first immutable element.
109  T const *data() const {
110  return (T const *)v()->data; /* Cast for complex. */
111  }
112 
113  /// Read element with bounds-checking.
114  /// @param i Offset of element.
115  /// @return Value of element.
116  T get(size_t i) const { return w_get(v(), i); }
117 
118  /// Write element with bounds-checking.
119  /// @param i Offset of element.
120  /// @param x New value for element.
121  void set(size_t i, T const &x) { w_set(v(), i, x); }
122 
123  /// Read element without bounds-checking.
124  /// @param i Offset of element.
125  /// @return Reference to immutable element.
126  T const &operator[](size_t i) const { return data()[i * v()->stride]; }
127 
128  /// Write element without bounds-checking.
129  /// @param i Offset of element.
130  /// @return Reference to mutable element.
131  T &operator[](size_t i) { return data()[i * v()->stride]; }
132 
133  /// Retrieve pointer to `i`th element with bounds-checking.
134  /// This could be useful if stride unknown.
135  /// @param i Offset of element.
136  /// @return Pointer to mutable element.
137  T *ptr(size_t i) { return w_ptr(v(), i); }
138 
139  /// Retrieve pointer to `i`th element with bounds-checking.
140  /// This could be useful if stride unknown.
141  /// @param i Offset of element.
142  /// @return Pointer to immutable element.
143  T const *ptr(size_t i) const { return w_ptr(v(), i); }
144 
145  /// Set every element.
146  /// @param x Value to which each element should be set.
147  void set_all(T const &x) { w_set_all(v(), x); }
148 
149  /// Set every element to zero.
150  void set_zero() { w_set_zero(v()); }
151 
152  /// Set element at offset `i` to unity and every other element to zero.
153  /// @param i Offset of element set to unity.
154  /// @return TBD: GSL's documentation does not specify.
155  int set_basis(size_t i) { return w_set_basis(v(), i); }
156 
157  /// Write non-portable binary-image of vector to file.
158  /// @param f Pointer to structure for buffered interface.
159  /// @return Zero only on success.
160  int fwrite(FILE *f) const { return w_fwrite(f, v()); }
161 
162  /// Read non-portable binary-image of vector from file.
163  /// @param f Pointer to structure for buffered interface.
164  /// @return Zero only on success.
165  int fread(FILE *f) { return w_fread(f, v()); };
166 
167  /// Write ASCII-formatted representation of vector to file.
168  /// @param flp Pointer to structure for buffered interface.
169  /// @param fmt printf()-style format-string.
170  /// @return Zero only on success.
171  int fprintf(FILE *flp, char const *fmt) const {
172  return w_fprintf(flp, v(), fmt);
173  }
174 
175  /// Read ASCII-formatted representation of vector from file.
176  /// @param f Pointer to structure for buffered interface.
177  /// @return Zero only on success.
178  int fscanf(FILE *f) { return w_fscanf(f, v()); }
179 
180  /// View of real-part of complex vector.
181  /// \return View of real-part of complex vector.
182  v_iface<element_t<T>, N, v_view> real() { return w_real(v()); }
183 
184  /// View of real-part of complex vector.
185  /// \return View of real-part of complex vector.
186  v_iface<element_t<T> const, N, v_view> real() const { return w_real(v()); }
187 
188  /// View of imaginary-part of complex vector.
189  /// \return View of imaginary-part of complex vector.
190  v_iface<element_t<T>, N, v_view> imag() { return w_imag(v()); }
191 
192  /// View of imaginary-part of complex vector.
193  /// \return View of imaginary-part of complex vector.
194  v_iface<element_t<T> const, N, v_view> imag() const { return w_imag(v()); }
195 
196  /// View of subvector of vector. Arguments are reordered from those given to
197  /// gsl_vector_subvector_with_stride(). Putting initial offset and stride at
198  /// end allows each to have good default (0 for initial offset and 1 for
199  /// stride).
200  /// @param n Number of elements in view.
201  /// @param i Offset in vector of first element in view.
202  /// @param s Stride of view relative to vector.
203  /// @return View of subvector.
204  v_iface<T, N, v_view> subvector(size_t n, size_t i= 0, size_t s= 1) {
205  return w_subvector(v(), i, s, n);
206  }
207 
208  /// View of subvector of vector. Arguments are reordered from those given to
209  /// gsl_vector_subvector_with_stride(). Putting initial offset and stride at
210  /// end allows each to have good default (0 for initial offset and 1 for
211  /// stride).
212  /// @param n Number of elements in view.
213  /// @param i Offset in vector of first element in view.
214  /// @param s Stride of view relative to vector.
215  /// @return View of subvector.
216  v_iface<T const, N, v_view>
217  subvector(size_t n, size_t i= 0, size_t s= 1) const {
218  return w_subvector(v(), i, s, n);
219  }
220 
221  /// View of vector.
222  /// @return View of vector.
223  v_iface<T, N, v_view> view() { return w_subvector(v(), 0, 1, size()); }
224 
225  /// View of vector.
226  /// @return View of vector.
227  v_iface<T const, N, v_view> view() const {
228  return w_subvector(v(), 0, 1, size());
229  }
230 
231  /// Swap elements within this vector.
232  /// @param i Offset of one element.
233  /// @param j Offset of other element.
234  /// @return TBD: GSL's documentation does not specify.
235  int swap_elements(size_t i, size_t j) { return w_swap_elements(v(), i, j); }
236 
237  /// Reverse order of elements.
238  /// @return TBD: GSL's documentation does not specify.
239  int reverse() { return w_reverse(v()); }
240 
241  /// Add contents of `b` into this vector in place.
242  /// \tparam ON Compile-time number of elements in `b`.
243  /// \tparam OV Type of interface to storage for `b`.
244  /// \param b Vector whose contents should be added into this.
245  /// \return TBD: GSL's documentation does not specify.
246  template<size_t ON, template<typename, size_t> class OV>
247  int add(v_iface<T, ON, OV> const &b) {
248  static_assert(N == ON || N == 0 || ON == 0);
249  return w_add(v(), b.v());
250  }
251 
252  /// Subtract contents of `b` from this vector in place.
253  /// \tparam ON Compile-time number of elements in `b`.
254  /// \tparam OV Type of interface to storage for `b`.
255  /// \param b Vector whose contents should be subtracted from this.
256  /// \return TBD: GSL's documentation does not specify.
257  template<size_t ON, template<typename, size_t> class OV>
258  int sub(v_iface<T, ON, OV> const &b) {
259  static_assert(N == ON || N == 0 || ON == 0);
260  return w_sub(v(), b.v());
261  }
262 
263  /// Multiply contents of `b` into this vector in place.
264  /// \tparam ON Compile-time number of elements in `b`.
265  /// \tparam OV Type of interface to storage for `b`.
266  /// \param b Vector whose contents should be multiplied into this.
267  /// \return TBD: GSL's documentation does not specify.
268  template<size_t ON, template<typename, size_t> class OV>
269  int mul(v_iface<T, ON, OV> const &b) {
270  static_assert(N == ON || N == 0 || ON == 0);
271  return w_mul(v(), b.v());
272  }
273 
274  /// Divide contents of `b` into this vector in place.
275  /// \tparam ON Compile-time number of elements in `b`.
276  /// \tparam OV Type of interface to storage for `b`.
277  /// \param b Vector whose contents should be divided into this.
278  /// \return TBD: GSL's documentation does not specify.
279  template<size_t ON, template<typename, size_t> class OV>
280  int div(v_iface<T, ON, OV> const &b) {
281  static_assert(N == ON || N == 0 || ON == 0);
282  return w_div(v(), b.v());
283  }
284 
285  /// Add contents of `b` into this vector in place.
286  /// \tparam ON Compile-time number of elements in `b`.
287  /// \tparam OV Type of interface to storage for `b`.
288  /// \param b Vector whose contents should be added into this.
289  /// \return Reference to this vector after modification.
290  template<size_t ON, template<typename, size_t> class OV>
291  v_iface &operator+=(v_iface<T, ON, OV> const &b) {
292  static_assert(N == ON || N == 0 || ON == 0);
293  add(b);
294  return *this;
295  }
296 
297  /// Subtract contents of `b` from this vector in place.
298  /// \tparam ON Compile-time number of elements in `b`.
299  /// \tparam OV Type of interface to storage for `b`.
300  /// \param b Vector whose contents should be subtracted from this.
301  /// \return Reference to this vector after modification.
302  template<size_t ON, template<typename, size_t> class OV>
303  v_iface &operator-=(v_iface<T, ON, OV> const &b) {
304  static_assert(N == ON || N == 0 || ON == 0);
305  sub(b);
306  return *this;
307  }
308 
309  /// Multiply contents of `b` into this vector in place.
310  /// \tparam ON Compile-time number of elements in `b`.
311  /// \tparam OV Type of interface to storage for `b`.
312  /// \param b Vector whose contents should be multiplied into this.
313  /// \return Reference to this vector after modification.
314  template<size_t ON, template<typename, size_t> class OV>
315  v_iface &operator*=(v_iface<T, ON, OV> const &b) {
316  static_assert(N == ON || N == 0 || ON == 0);
317  mul(b);
318  return *this;
319  }
320 
321  /// Divide contents of `b` into this vector in place.
322  /// \tparam ON Compile-time number of elements in `b`.
323  /// \tparam OV Type of interface to storage for `b`.
324  /// \param b Vector whose contents should be divided into this.
325  /// @return Reference to this vector after modification.
326  template<size_t ON, template<typename, size_t> class OV>
327  v_iface &operator/=(v_iface<T, ON, OV> const &b) {
328  static_assert(N == ON || N == 0 || ON == 0);
329  div(b);
330  return *this;
331  }
332 
333  /// Copy contents of `b` into this vector.
334  /// \tparam ON Compile-time number of elements in `b`.
335  /// \tparam OV Type of interface to storage for `b`.
336  /// \param b Reference to vector whose data will be copied.
337  /// \return Reference to this instance after assignment.
338  template<size_t ON, template<typename, size_t> class OV>
339  v_iface &operator=(v_iface<T, ON, OV> const &b) {
340  static_assert(N == ON || N == 0 || ON == 0);
341  memcpy(*this, b);
342  return *this;
343  }
344 
345  /// Copy contents of `b` into this vector.
346  /// \param b Reference to vector whose data will be copied.
347  /// \return Reference to this instance after assignment.
348  v_iface &operator=(v_iface const &b) {
349  memcpy(*this, b);
350  return *this;
351  }
352 
353  /// Enable move-constructor in gsl::v_stor to work.
354  v_iface(v_iface &&)= default;
355 
356  /// Multiply scalar into this vector in place.
357  /// @param x Scalar to multiply into this.
358  /// @return TBD: GSL's documentation does not specify.
359  int scale(T const &x) { return w_scale(v(), x); }
360 
361  /// Multiply scalar into this vector in place.
362  /// @param x Scalar to multiply into this.
363  /// @return Reference to this vector after modification.
364  v_iface &operator*=(T const &x) {
365  scale(x);
366  return *this;
367  }
368 
369  /// Add constant into each element of this vector in place.
370  /// @param x Constant to add into this vector.
371  /// @return TBD: GSL's documentation does not specify.
372  int add_constant(T const &x) { return w_add_constant(v(), x); }
373 
374  /// Add constant into each element of this vector in place.
375  /// @param x Constant to add into this vector.
376  /// @return Reference to this vector after modification.
377  v_iface &operator+=(T const &x) {
379  return *this;
380  }
381 
382  /// Sum of elements.
383  /// @return Sum of elements.
384  T sum() const { return w_sum(v()); }
385 
386  /// Greatest value of any element.
387  /// @return Greatest value of any element.
388  T max() const { return w_max(v()); }
389 
390  /// Least value of any element.
391  /// @return Least value of any element.
392  T min() const { return w_min(v()); }
393 
394  /// Greatest value and least value of any element.
395  /// @param min On return, least value.
396  /// @param max On return, greatest value.
397  void minmax(T &min, T &max) const { w_minmax(v(), &min, &max); }
398 
399  /// Offset of greatest value.
400  /// @return Offset of greatest value.
401  size_t max_index() const { return w_max_index(v()); }
402 
403  /// Offset of least value.
404  /// @return Offset of least value.
405  size_t min_index() const { return w_min_index(v()); }
406 
407  /// Offset of least value and offset of greatest value.
408  /// @param imin On return, offset of least value.
409  /// @param imax On return, offset of greatest value.
410  void minmax_index(size_t &imin, size_t &imax) const {
411  w_minmax_index(v(), &imin, &imax);
412  }
413 
414  /// True only if every element have zero value.
415  /// @return True only if every element be zero.
416  bool isnull() const { return w_isnull(v()); }
417 
418  /// True only if every element be positive.
419  /// @return True only if every element be positive.
420  bool ispos() const { return w_ispos(v()); }
421 
422  /// True only if every element be negative.
423  /// @return True only if every element be negative.
424  bool isneg() const { return w_isneg(v()); }
425 
426  /// True only if every element be non-negative.
427  /// @return True only if every element be non-negative.
428  bool isnonneg() const { return w_isnonneg(v()); }
429 };
430 
431 
432 /// Test equality of two vectors.
433 /// @tparam T1 Type of element in first vector.
434 /// @tparam T2 Type of element in second vector.
435 /// @tparam N1 Compile-time number of elements in first vector.
436 /// @tparam N2 Compile-time number of elements in second vector.
437 /// @tparam V1 Type of storage for first vector.
438 /// @tparam V2 Type of storage for second vector.
439 /// @param v1 Reference to first vector.
440 /// @param v2 Reference to second vector.
441 /// @return True only if vectors be equal.
442 template<
443  typename T1,
444  typename T2,
445  size_t N1,
446  size_t N2,
447  template<typename, size_t>
448  class V1,
449  template<typename, size_t>
450  class V2>
451 bool equal(v_iface<T1, N1, V1> const &v1, v_iface<T2, N2, V2> const &v2) {
452  static_assert(N1 == N2 || N1 == 0 || N2 == 0);
453  return w_equal(v1.v(), v2.v());
454 }
455 
456 
457 /// Test equality of two vectors.
458 /// @tparam T1 Type of element in first vector.
459 /// @tparam T2 Type of element in second vector.
460 /// @tparam N1 Compile-time number of elements in first vector.
461 /// @tparam N2 Compile-time number of elements in second vector.
462 /// @tparam V1 Type of storage for first vector.
463 /// @tparam V2 Type of storage for second vector.
464 /// @param u Reference to first vector.
465 /// @param v Reference to second vector.
466 /// @return True only if vectors be equal.
467 template<
468  typename T1,
469  typename T2,
470  size_t N1,
471  size_t N2,
472  template<typename, size_t>
473  class V1,
474  template<typename, size_t>
475  class V2>
476 bool operator==(v_iface<T1, N1, V1> const &u, v_iface<T2, N2, V2> const &v) {
477  static_assert(
478  N1 == N2 || N1 == 0 || N2 == 0, "incompatible size at compile-time");
479  return equal(u, v);
480 }
481 
482 
483 /// Test inequality of two vectors.
484 /// @tparam T1 Type of element in first vector.
485 /// @tparam T2 Type of element in second vector.
486 /// @tparam N1 Compile-time number of elements in first vector.
487 /// @tparam N2 Compile-time number of elements in second vector.
488 /// @tparam V1 Type of storage for first vector.
489 /// @tparam V2 Type of storage for second vector.
490 /// @param u Reference to first vector.
491 /// @param v Reference to second vector.
492 /// @return True only if vectors be unequal.
493 template<
494  typename T1,
495  typename T2,
496  size_t N1,
497  size_t N2,
498  template<typename, size_t>
499  class V1,
500  template<typename, size_t>
501  class V2>
502 bool operator!=(v_iface<T1, N1, V1> const &u, v_iface<T2, N2, V2> const &v) {
503  static_assert(N1 == N2 || N1 == 0 || N2 == 0);
504  return !equal(u, v);
505 }
506 
507 
508 /// Print vector to output-stream.
509 /// @tparam T Type of element in vector.
510 /// @tparam N Number of elements in vector.
511 /// @tparam V Type of storage for vector.
512 /// @param os Reference to output-stream.
513 /// @param u Reference to vector.
514 /// @return Reference to modified output-stream.
515 template<typename T, size_t N, template<typename, size_t> class V>
516 std::ostream &operator<<(std::ostream &os, v_iface<T, N, V> const &u) {
517  os << "[";
518  int const last= int(u.size()) - 1;
519  for(int i= 0; i < last; ++i) os << u[i] << ",";
520  if(last >= 0) os << u[last];
521  os << "]";
522  return os;
523 }
524 
525 
526 /// Linearly combine vector `x` into vector `y` in place.
527 /// @tparam T1 Type of element in `x`.
528 /// @tparam T2 Type of element in `y`.
529 /// @tparam N1 Compile-time number of elements in `x`.
530 /// @tparam N2 Compile-time number of elements in `y`.
531 /// @tparam V1 Type of storage for `x`.
532 /// @tparam V2 Type of storage for `y`.
533 /// @param alpha Coeffient of `x`.
534 /// @param x First vector (source).
535 /// @param beta Coefficient of `y`.
536 /// @param y Second vector and (source and destination).
537 /// @return TBD: GSL's documentation does not specify.
538 template<
539  typename T1,
540  typename T2,
541  size_t N1,
542  size_t N2,
543  template<typename, size_t>
544  class V1,
545  template<typename, size_t>
546  class V2>
547 int axpby(
548  T1 const &alpha,
549  v_iface<T1, N1, V1> const &x,
550  T2 const &beta,
551  v_iface<T2, N2, V2> &y) {
552  static_assert(N1 == N2 || N1 == 0 || N2 == 0);
553  return w_axpby(alpha, x.v(), beta, y.v());
554 }
555 
556 
557 /// Copy data from `src`, whose length must be same as that of `dst`.
558 /// @tparam T1 Type of element in `dst`.
559 /// @tparam T2 Type of element in `src`.
560 /// @tparam N1 Compile-time number of elements in `dst`.
561 /// @tparam N2 Compile-time number of elements in `src`.
562 /// @tparam V1 Type of storage for `dst`.
563 /// @tparam V2 Type of storage for `src`.
564 /// @param dst Destination.
565 /// @param src Source.
566 /// @return TBD: GSL's documentation does not specify.
567 template<
568  typename T1,
569  typename T2,
570  size_t N1,
571  size_t N2,
572  template<typename, size_t>
573  class V1,
574  template<typename, size_t>
575  class V2>
576 int memcpy(v_iface<T1, N1, V1> &dst, v_iface<T2, N2, V2> const &src) {
577  static_assert(N1 == N2 || N1 == 0 || N2 == 0);
578  return w_memcpy(dst.v(), src.v());
579 }
580 
581 
582 /// Swap contents of one and other vector, each with same length.
583 /// @tparam T1 Type of element in first vector.
584 /// @tparam T2 Type of element in second vector.
585 /// @tparam N1 Compile-time number of elements in first vector.
586 /// @tparam N2 Compile-time number of elements in second vector.
587 /// @tparam V1 Type of storage for first vector.
588 /// @tparam V2 Type of storage for second vector.
589 /// @param v1 Reference to first vector.
590 /// @param v2 Reference to second vector.
591 /// @return TBD: GSL's documentation does not specify.
592 template<
593  typename T1,
594  typename T2,
595  size_t N1,
596  size_t N2,
597  template<typename, size_t>
598  class V1,
599  template<typename, size_t>
600  class V2>
601 int swap(v_iface<T1, N1, V1> &v1, v_iface<T2, N2, V2> &v2) {
602  return w_swap(v1.v(), v2.v());
603 }
604 
605 
606 } // namespace gsl
607 
608 // EOF
gsl::v_iface::data
const T * data() const
Pointer to first element in immutable vector.
Definition: v-iface.hpp:109
gsl::v_iface::add
int add(v_iface< T, ON, OV > const &b)
Add contents of b into this vector in place.
Definition: v-iface.hpp:247
gsl::v_iface::operator[]
T & operator[](size_t i)
Write element without bounds-checking.
Definition: v-iface.hpp:131
gsl::v_iface::fprintf
int fprintf(FILE *flp, char const *fmt) const
Write ASCII-formatted representation of vector to file.
Definition: v-iface.hpp:171
gsl::v_iface::operator*=
v_iface & operator*=(T const &x)
Multiply scalar into this vector in place.
Definition: v-iface.hpp:364
gsl::v_iface::fscanf
int fscanf(FILE *f)
Read ASCII-formatted representation of vector from file.
Definition: v-iface.hpp:178
gsl::v_iface::sum
T sum() const
Sum of elements.
Definition: v-iface.hpp:384
gsl::v_iface::v_iface
v_iface(v_iface &&)=default
Enable move-constructor in gsl::v_stor to work.
gsl::v_iface::operator/=
v_iface & operator/=(v_iface< T, ON, OV > const &b)
Divide contents of b into this vector in place.
Definition: v-iface.hpp:327
gsl::v_iface::ispos
bool ispos() const
True only if every element be positive.
Definition: v-iface.hpp:420
gsl::v_iface::sub
int sub(v_iface< T, ON, OV > const &b)
Subtract contents of b from this vector in place.
Definition: v-iface.hpp:258
gsl::v_iface::set
void set(size_t i, T const &x)
Write element with bounds-checking.
Definition: v-iface.hpp:121
gsl::v_iface::set_zero
void set_zero()
Set every element to zero.
Definition: v-iface.hpp:150
gsl::v_iface::operator+=
v_iface & operator+=(v_iface< T, ON, OV > const &b)
Add contents of b into this vector in place.
Definition: v-iface.hpp:291
gsl::v_iface::end
iterator end()
Iterator that points to element just past last element.
Definition: v-iface.hpp:87
gsl::v_iface::set_basis
int set_basis(size_t i)
Set element at offset i to unity and every other element to zero.
Definition: v-iface.hpp:155
gsl::v_iface::min_index
size_t min_index() const
Offset of least value.
Definition: v-iface.hpp:405
gsl::v_iface::operator=
v_iface & operator=(v_iface< T, ON, OV > const &b)
Copy contents of b into this vector.
Definition: v-iface.hpp:339
gsl::v_iface::max
T max() const
Greatest value of any element.
Definition: v-iface.hpp:388
gsl::v_iface::end
const_iterator end() const
Iterator that points to element just past last element.
Definition: v-iface.hpp:95
gsl::v_iface::min
T min() const
Least value of any element.
Definition: v-iface.hpp:392
gsl::v_iface::subvector
v_iface< T, N, v_view > subvector(size_t n, size_t i=0, size_t s=1)
View of subvector of vector.
Definition: v-iface.hpp:204
gsl::v_iface::size
size_t size() const
Size of vector.
Definition: v-iface.hpp:99
gsl::v_iface::ptr
T * ptr(size_t i)
Retrieve pointer to ith element with bounds-checking.
Definition: v-iface.hpp:137
gsl::v_iface::swap_elements
int swap_elements(size_t i, size_t j)
Swap elements within this vector.
Definition: v-iface.hpp:235
gsl::swap
int swap(v_iface< T1, N1, V1 > &v1, v_iface< T2, N2, V2 > &v2)
Swap contents of one and other vector, each with same length.
Definition: v-iface.hpp:601
gsl::v_iface::view
v_iface< T, N, v_view > view()
View of vector.
Definition: v-iface.hpp:223
gsl::v_iface::operator[]
const T & operator[](size_t i) const
Read element without bounds-checking.
Definition: v-iface.hpp:126
gsl::v_iface::operator=
v_iface & operator=(v_iface const &b)
Copy contents of b into this vector.
Definition: v-iface.hpp:348
gsl::v_iface::minmax_index
void minmax_index(size_t &imin, size_t &imax) const
Offset of least value and offset of greatest value.
Definition: v-iface.hpp:410
gsl::operator==
bool operator==(v_iface< T1, N1, V1 > const &u, v_iface< T2, N2, V2 > const &v)
Test equality of two vectors.
Definition: v-iface.hpp:476
gsl::v_iface::imag
v_iface< element_t< T >, N, v_view > imag()
View of imaginary-part of complex vector.
Definition: v-iface.hpp:190
gsl::v_iface::data
T * data()
Pointer to first element in vector.
Definition: v-iface.hpp:104
gsl::v_iface::isnull
bool isnull() const
True only if every element have zero value.
Definition: v-iface.hpp:416
gsl::v_iface::subvector
v_iface< T const, N, v_view > subvector(size_t n, size_t i=0, size_t s=1) const
View of subvector of vector.
Definition: v-iface.hpp:217
gsl::v_iface::div
int div(v_iface< T, ON, OV > const &b)
Divide contents of b into this vector in place.
Definition: v-iface.hpp:280
gsl::v_iface::scale
int scale(T const &x)
Multiply scalar into this vector in place.
Definition: v-iface.hpp:359
gsl::v_iface::get
T get(size_t i) const
Read element with bounds-checking.
Definition: v-iface.hpp:116
gsl::v_iface
Interface for every kind of vector.
Definition: v-iface.hpp:62
gsl::v_iface::imag
v_iface< element_t< T > const, N, v_view > imag() const
View of imaginary-part of complex vector.
Definition: v-iface.hpp:194
gsl::v_iface::view
v_iface< T const, N, v_view > view() const
View of vector.
Definition: v-iface.hpp:227
gsl::v_iface::operator*=
v_iface & operator*=(v_iface< T, ON, OV > const &b)
Multiply contents of b into this vector in place.
Definition: v-iface.hpp:315
gsl::v_iface::real
v_iface< element_t< T > const, N, v_view > real() const
View of real-part of complex vector.
Definition: v-iface.hpp:186
gsl::v_view
Interface to vector-storage not owned by interface.
Definition: v-view.hpp:17
gsl::v_iface::operator-=
v_iface & operator-=(v_iface< T, ON, OV > const &b)
Subtract contents of b from this vector in place.
Definition: v-iface.hpp:303
gsl::v_iface::fwrite
int fwrite(FILE *f) const
Write non-portable binary-image of vector to file.
Definition: v-iface.hpp:160
gsl::axpby
int axpby(T1 const &alpha, v_iface< T1, N1, V1 > const &x, T2 const &beta, v_iface< T2, N2, V2 > &y)
Linearly combine vector x into vector y in place.
Definition: v-iface.hpp:547
gsl::v_iface::real
v_iface< element_t< T >, N, v_view > real()
View of real-part of complex vector.
Definition: v-iface.hpp:182
gsl::v_iface::ptr
const T * ptr(size_t i) const
Retrieve pointer to ith element with bounds-checking.
Definition: v-iface.hpp:143
gsl::v_iface::SIZE
@ SIZE
Size at compile-time.
Definition: v-iface.hpp:70
gsl::v_iface::set_all
void set_all(T const &x)
Set every element.
Definition: v-iface.hpp:147
gsl::v_iface::fread
int fread(FILE *f)
Read non-portable binary-image of vector from file.
Definition: v-iface.hpp:165
gsl::v_iface::add_constant
int add_constant(T const &x)
Add constant into each element of this vector in place.
Definition: v-iface.hpp:372
gsl::v_iface::isnonneg
bool isnonneg() const
True only if every element be non-negative.
Definition: v-iface.hpp:428
gsl::v_iface::begin
iterator begin()
Iterator that points to first element.
Definition: v-iface.hpp:83
gsl::v_iface::begin
const_iterator begin() const
Iterator that points to first element.
Definition: v-iface.hpp:91
gsl::v_iface::operator+=
v_iface & operator+=(T const &x)
Add constant into each element of this vector in place.
Definition: v-iface.hpp:377
gsl::v_iface::minmax
void minmax(T &min, T &max) const
Greatest value and least value of any element.
Definition: v-iface.hpp:397
gsl::equal
bool equal(v_iface< T1, N1, V1 > const &v1, v_iface< T2, N2, V2 > const &v2)
Test equality of two vectors.
Definition: v-iface.hpp:451
gsl::v_iface::mul
int mul(v_iface< T, ON, OV > const &b)
Multiply contents of b into this vector in place.
Definition: v-iface.hpp:269
gsl::v_iface::isneg
bool isneg() const
True only if every element be negative.
Definition: v-iface.hpp:424
gsl::v_iface::max_index
size_t max_index() const
Offset of greatest value.
Definition: v-iface.hpp:401
gsl::operator!=
bool operator!=(v_iface< T1, N1, V1 > const &u, v_iface< T2, N2, V2 > const &v)
Test inequality of two vectors.
Definition: v-iface.hpp:502
gsl
Namespace for C++-interface to GSL.
Definition: v-iface.hpp:51
gsl::v_iface::reverse
int reverse()
Reverse order of elements.
Definition: v-iface.hpp:239
gsl::memcpy
int memcpy(v_iface< T1, N1, V1 > &dst, v_iface< T2, N2, V2 > const &src)
Copy data from src, whose length must be same as that of dst.
Definition: v-iface.hpp:576