gslcpp
Modern-C++ Wrapper for GSL
|
Go to the documentation of this file.
10 #include "../wrap/add-constant.hpp"
11 #include "../wrap/add.hpp"
12 #include "../wrap/axpby.hpp"
13 #include "../wrap/div.hpp"
14 #include "../wrap/element.hpp"
15 #include "../wrap/equal.hpp"
16 #include "../wrap/fprintf.hpp"
17 #include "../wrap/fread.hpp"
18 #include "../wrap/fscanf.hpp"
19 #include "../wrap/fwrite.hpp"
20 #include "../wrap/get.hpp"
21 #include "../wrap/imag.hpp"
22 #include "../wrap/isneg.hpp"
23 #include "../wrap/isnonneg.hpp"
24 #include "../wrap/isnull.hpp"
25 #include "../wrap/ispos.hpp"
26 #include "../wrap/max-index.hpp"
27 #include "../wrap/max.hpp"
28 #include "../wrap/memcpy.hpp"
29 #include "../wrap/min-index.hpp"
30 #include "../wrap/min.hpp"
31 #include "../wrap/minmax-index.hpp"
32 #include "../wrap/minmax.hpp"
33 #include "../wrap/mul.hpp"
34 #include "../wrap/ptr.hpp"
35 #include "../wrap/real.hpp"
36 #include "../wrap/reverse.hpp"
37 #include "../wrap/scale.hpp"
38 #include "../wrap/set-all.hpp"
39 #include "../wrap/set-basis.hpp"
40 #include "../wrap/set-zero.hpp"
41 #include "../wrap/set.hpp"
42 #include "../wrap/sub.hpp"
43 #include "../wrap/subvector.hpp"
44 #include "../wrap/sum.hpp"
45 #include "../wrap/swap-elements.hpp"
46 #include "../wrap/swap.hpp"
54 using std::is_const_v;
61 template<
typename T, size_t N,
template<
typename, size_t>
class S>
79 using const_iterator= v_iterator<
v_iface const>;
83 iterator
begin() {
return iterator(*
this, 0); }
91 const_iterator
begin()
const {
return const_iterator(*
this, 0); }
95 const_iterator
end()
const {
return const_iterator(*
this,
size()); }
99 size_t
size()
const {
return v()->size; }
104 T *
data() {
return (T *)v()->data; }
110 return (T
const *)v()->data;
116 T
get(size_t i)
const {
return w_get(v(), i); }
121 void set(size_t i, T
const &x) { w_set(v(), i, x); }
126 T
const &
operator[](size_t i)
const {
return data()[i * v()->stride]; }
131 T &
operator[](size_t i) {
return data()[i * v()->stride]; }
137 T *
ptr(size_t i) {
return w_ptr(v(), i); }
143 T
const *
ptr(size_t i)
const {
return w_ptr(v(), i); }
147 void set_all(T
const &x) { w_set_all(v(), x); }
160 int fwrite(FILE *f)
const {
return w_fwrite(f, v()); }
165 int fread(FILE *f) {
return w_fread(f, v()); };
171 int fprintf(FILE *flp,
char const *fmt)
const {
172 return w_fprintf(flp, v(), fmt);
178 int fscanf(FILE *f) {
return w_fscanf(f, v()); }
205 return w_subvector(v(), i, s, n);
218 return w_subvector(v(), i, s, n);
228 return w_subvector(v(), 0, 1,
size());
235 int swap_elements(size_t i, size_t j) {
return w_swap_elements(v(), i, j); }
246 template<size_t ON,
template<
typename, size_t>
class OV>
248 static_assert(N == ON || N == 0 || ON == 0);
249 return w_add(v(), b.v());
257 template<size_t ON,
template<
typename, size_t>
class OV>
259 static_assert(N == ON || N == 0 || ON == 0);
260 return w_sub(v(), b.v());
268 template<size_t ON,
template<
typename, size_t>
class OV>
270 static_assert(N == ON || N == 0 || ON == 0);
271 return w_mul(v(), b.v());
279 template<size_t ON,
template<
typename, size_t>
class OV>
281 static_assert(N == ON || N == 0 || ON == 0);
282 return w_div(v(), b.v());
290 template<size_t ON,
template<
typename, size_t>
class OV>
292 static_assert(N == ON || N == 0 || ON == 0);
302 template<size_t ON,
template<
typename, size_t>
class OV>
304 static_assert(N == ON || N == 0 || ON == 0);
314 template<size_t ON,
template<
typename, size_t>
class OV>
316 static_assert(N == ON || N == 0 || ON == 0);
326 template<size_t ON,
template<
typename, size_t>
class OV>
328 static_assert(N == ON || N == 0 || ON == 0);
338 template<size_t ON,
template<
typename, size_t>
class OV>
340 static_assert(N == ON || N == 0 || ON == 0);
359 int scale(T
const &x) {
return w_scale(v(), x); }
384 T
sum()
const {
return w_sum(v()); }
388 T
max()
const {
return w_max(v()); }
392 T
min()
const {
return w_min(v()); }
397 void minmax(T &min, T &max)
const { w_minmax(v(), &min, &max); }
411 w_minmax_index(v(), &imin, &imax);
416 bool isnull()
const {
return w_isnull(v()); }
420 bool ispos()
const {
return w_ispos(v()); }
424 bool isneg()
const {
return w_isneg(v()); }
447 template<
typename, size_t>
449 template<
typename, size_t>
452 static_assert(N1 == N2 || N1 == 0 || N2 == 0);
453 return w_equal(v1.v(), v2.v());
472 template<
typename, size_t>
474 template<
typename, size_t>
478 N1 == N2 || N1 == 0 || N2 == 0,
"incompatible size at compile-time");
498 template<
typename, size_t>
500 template<
typename, size_t>
503 static_assert(N1 == N2 || N1 == 0 || N2 == 0);
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) {
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];
543 template<
typename, size_t>
545 template<
typename, size_t>
552 static_assert(N1 == N2 || N1 == 0 || N2 == 0);
553 return w_axpby(alpha, x.v(), beta, y.v());
572 template<
typename, size_t>
574 template<
typename, size_t>
577 static_assert(N1 == N2 || N1 == 0 || N2 == 0);
578 return w_memcpy(dst.v(), src.v());
597 template<
typename, size_t>
599 template<
typename, size_t>
602 return w_swap(v1.v(), v2.v());
const T * data() const
Pointer to first element in immutable vector.
int add(v_iface< T, ON, OV > const &b)
Add contents of b into this vector in place.
T & operator[](size_t i)
Write element without bounds-checking.
int fprintf(FILE *flp, char const *fmt) const
Write ASCII-formatted representation of vector to file.
v_iface & operator*=(T const &x)
Multiply scalar into this vector in place.
int fscanf(FILE *f)
Read ASCII-formatted representation of vector from file.
T sum() const
Sum of elements.
v_iface(v_iface &&)=default
Enable move-constructor in gsl::v_stor to work.
v_iface & operator/=(v_iface< T, ON, OV > const &b)
Divide contents of b into this vector in place.
bool ispos() const
True only if every element be positive.
int sub(v_iface< T, ON, OV > const &b)
Subtract contents of b from this vector in place.
void set(size_t i, T const &x)
Write element with bounds-checking.
void set_zero()
Set every element to zero.
v_iface & operator+=(v_iface< T, ON, OV > const &b)
Add contents of b into this vector in place.
iterator end()
Iterator that points to element just past last element.
int set_basis(size_t i)
Set element at offset i to unity and every other element to zero.
size_t min_index() const
Offset of least value.
v_iface & operator=(v_iface< T, ON, OV > const &b)
Copy contents of b into this vector.
T max() const
Greatest value of any element.
const_iterator end() const
Iterator that points to element just past last element.
T min() const
Least value of any element.
v_iface< T, N, v_view > subvector(size_t n, size_t i=0, size_t s=1)
View of subvector of vector.
size_t size() const
Size of vector.
T * ptr(size_t i)
Retrieve pointer to ith element with bounds-checking.
int swap_elements(size_t i, size_t j)
Swap elements within this vector.
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.
v_iface< T, N, v_view > view()
View of vector.
const T & operator[](size_t i) const
Read element without bounds-checking.
v_iface & operator=(v_iface const &b)
Copy contents of b into this vector.
void minmax_index(size_t &imin, size_t &imax) const
Offset of least value and offset of greatest value.
bool operator==(v_iface< T1, N1, V1 > const &u, v_iface< T2, N2, V2 > const &v)
Test equality of two vectors.
v_iface< element_t< T >, N, v_view > imag()
View of imaginary-part of complex vector.
T * data()
Pointer to first element in vector.
bool isnull() const
True only if every element have zero value.
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.
int div(v_iface< T, ON, OV > const &b)
Divide contents of b into this vector in place.
int scale(T const &x)
Multiply scalar into this vector in place.
T get(size_t i) const
Read element with bounds-checking.
Interface for every kind of vector.
v_iface< element_t< T > const, N, v_view > imag() const
View of imaginary-part of complex vector.
v_iface< T const, N, v_view > view() const
View of vector.
v_iface & operator*=(v_iface< T, ON, OV > const &b)
Multiply contents of b into this vector in place.
v_iface< element_t< T > const, N, v_view > real() const
View of real-part of complex vector.
Interface to vector-storage not owned by interface.
v_iface & operator-=(v_iface< T, ON, OV > const &b)
Subtract contents of b from this vector in place.
int fwrite(FILE *f) const
Write non-portable binary-image of vector to file.
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.
v_iface< element_t< T >, N, v_view > real()
View of real-part of complex vector.
const T * ptr(size_t i) const
Retrieve pointer to ith element with bounds-checking.
@ SIZE
Size at compile-time.
void set_all(T const &x)
Set every element.
int fread(FILE *f)
Read non-portable binary-image of vector from file.
int add_constant(T const &x)
Add constant into each element of this vector in place.
bool isnonneg() const
True only if every element be non-negative.
iterator begin()
Iterator that points to first element.
const_iterator begin() const
Iterator that points to first element.
v_iface & operator+=(T const &x)
Add constant into each element of this vector in place.
void minmax(T &min, T &max) const
Greatest value and least value of any element.
bool equal(v_iface< T1, N1, V1 > const &v1, v_iface< T2, N2, V2 > const &v2)
Test equality of two vectors.
int mul(v_iface< T, ON, OV > const &b)
Multiply contents of b into this vector in place.
bool isneg() const
True only if every element be negative.
size_t max_index() const
Offset of greatest value.
bool operator!=(v_iface< T1, N1, V1 > const &u, v_iface< T2, N2, V2 > const &v)
Test inequality of two vectors.
Namespace for C++-interface to GSL.
int reverse()
Reverse order of elements.
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.