20#ifndef CCGSL_VECTOR_COMPLEX_HPP
21#define CCGSL_VECTOR_COMPLEX_HPP
23#include<gsl/gsl_vector_complex_double.h>
26#ifdef __GXX_EXPERIMENTAL_CXX0X__
67 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
82 if(
n > 0 )
ccgsl_pointer = gsl_vector_complex_alloc(
static_cast<size_t>(
n ) );
84 gsl_error(
"failed tring to make a vector of negative length",
88 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
102 explicit vector_complex( gsl_vector_complex* v )
109#ifdef __GXX_EXPERIMENTAL_CXX0X__
116 size_t const n = initializer_list.size();
119 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
128 for(
auto x : initializer_list ){
129 *p =
complex( std::move( x ) ); ++p;
172 gsl_vector_complex_memcpy( copy.
get(),
get() );
235#ifdef __GXX_EXPERIMENTAL_CXX0X__
243 std::swap(
count, v.count );
244 v.ccgsl_pointer =
nullptr;
284 for(
size_t i = 0; i <
min; ++i ){
287 if( t < u )
return true;
288 if( u < t )
return false;
291 return size < v_size;
311 for(
size_t i = 0; i <
min; ++i ){
314 if( t > u )
return true;
315 if( u > t )
return false;
318 return size > v_size;
376 template<
typename container,
typename content,
bool reverse_t>
412 }
else if(
v->ccgsl_pointer == 0 ){
438 }
else if(
v->ccgsl_pointer == 0 ){
465 }
else if(
v->ccgsl_pointer == 0 ){
490 if(
v == 0 or i.
v == 0 ){
493 }
else if(
v->ccgsl_pointer == 0 or i.
v->ccgsl_pointer == 0 ){
498 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
499 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
532 if(
v == 0 or i.
v == 0 ){
537 if(
v->ccgsl_pointer != i.
v->ccgsl_pointer ){
538 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
554 }
else if(
v->ccgsl_pointer == 0 ){
571 }
else if(
v->ccgsl_pointer == 0 ){
588 }
else if(
v->ccgsl_pointer == 0 ){
736 if( this->
v == 0 or i.
v == 0 ){
745 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
774 if( this->
v == 0 or i.
v == 0 ){
780 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
805 :
public iterator_base<vector_complex const,double,reverse_t>{
922 if( this->
v == 0 or i.
v == 0 ){
931 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
972 if( this->
v == 0 or i.
v == 0 ){
978 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
1007 if( this->
v == 0 or i.
v == 0 ){
1013 gsl_error(
"trying to take difference of iterators for different vector_complex objects", __FILE__, __LINE__,
1103 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector", __FILE__, __LINE__, GSL_EFAULT );
1104#ifndef GSL_RANGE_CHECK_OFF
1106 gsl_error(
"vector does not have stride of size 1", __FILE__, __LINE__, GSL_EBADLEN );
1117 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector", __FILE__, __LINE__, GSL_EFAULT );
1118#ifndef GSL_RANGE_CHECK_OFF
1120 gsl_error(
"vector does not have stride of size 1", __FILE__, __LINE__, GSL_EBADLEN );
1191#ifndef GSL_RANGE_CHECK_OFF
1212#ifndef GSL_RANGE_CHECK_OFF
1263#ifdef __GXX_EXPERIMENTAL_CXX0X__
1290 int set_basis(
size_t i ){
return gsl_vector_complex_set_basis(
get(), i ); }
1309 return gsl_vector_complex_swap_elements(
get(), i, j ); }
1355 return gsl_vector_complex_axpby( alpha, x.
get(),
beta,
get() );
1361 int isnull()
const {
return gsl_vector_complex_isnull(
get() ); }
1366 int ispos()
const {
return gsl_vector_complex_ispos(
get() ); }
1371 int isneg()
const {
return gsl_vector_complex_isneg(
get() ); }
1382 complex get(
size_t const i )
const {
return gsl_vector_complex_get(
get(), i ); }
1412 int fread( FILE* stream ){
return gsl_vector_complex_fread( stream,
get() ); }
1418 int fwrite( FILE* stream )
const {
return gsl_vector_complex_fwrite( stream,
get() ); }
1424 int fscanf( FILE* stream ){
return gsl_vector_complex_fscanf( stream,
get() ); }
1431 int fprintf( FILE* stream,
char const* format )
const {
1432 return gsl_vector_complex_fprintf( stream,
get(), format ); }
1441 ccgsl_pointer = gsl_vector_complex_alloc_from_block(
b.get(), offset,
n, stride );
1443 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
1458 ccgsl_pointer = gsl_vector_complex_alloc_from_vector( v.
get(), offset,
n, stride );
1460 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
1522 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1523 *w = gsl_vector_complex_view_array( v,
n ).vector;
1536 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1537 *w = gsl_vector_complex_view_array_with_stride( base, stride,
n ).vector;
1549 gsl_vector_complex* w =
static_cast<gsl_vector_complex *
>( malloc(
sizeof( gsl_vector_complex ) ) );
1550 *w = gsl_vector_complex_const_view_array( v,
n ).vector;
1563 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1564 *w = gsl_vector_complex_const_view_array_with_stride( base, stride,
n ).vector;
1577 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1578 *w = gsl_vector_complex_const_view_array( v,
n ).vector;
1593 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1594 *w = gsl_vector_complex_const_view_array_with_stride( base, stride,
n ).vector;
1607 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1608 *w = gsl_vector_complex_subvector(
get(), i,
n ).vector;
1621 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1622 *w = gsl_vector_complex_subvector_with_stride(
get(), i, stride,
n ).vector;
1634 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1635 *w = gsl_vector_complex_const_subvector(
get(), i,
n ).vector;
1648 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1649 *w = gsl_vector_complex_const_subvector_with_stride(
get(), i, stride,
n ).vector;
1662 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1663 *w = gsl_vector_complex_const_subvector(
get(), i,
n ).vector;
1678 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1679 *w = gsl_vector_complex_const_subvector_with_stride(
get(), i, stride,
n ).vector;
1691 template<
typename ARRAY>
1697 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1698 *w = gsl_vector_complex_view_array( v.data(),
n ).vector;
1710 template<
typename ARRAY>
1713 n = base.size()/stride;
1714 if((
n-1)*stride > base.size())
1716 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1717 *w = gsl_vector_complex_view_array_with_stride( base.data(), stride,
n ).vector;
1728 template<
typename ARRAY>
1734 gsl_vector_complex* w =
static_cast<gsl_vector_complex *
>( malloc(
sizeof( gsl_vector_complex ) ) );
1735 *w = gsl_vector_complex_const_view_array( v.data(),
n ).vector;
1747 template<
typename ARRAY>
1750 n = base.size()/stride;
1751 if((
n-1)*stride > base.size())
1753 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1754 *w = gsl_vector_complex_const_view_array_with_stride( base.data(), stride,
n ).vector;
1766 template<
typename ARRAY>
1772 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1773 *w = gsl_vector_complex_const_view_array( v.data(),
n ).vector;
1787 template<
typename ARRAY>
1790 n = base.size()/stride;
1791 if((
n-1)*stride > base.size())
1793 gsl_vector_complex* w =
static_cast<gsl_vector_complex*
>( malloc(
sizeof( gsl_vector_complex ) ) );
1794 *w = gsl_vector_complex_const_view_array_with_stride( base.data(), stride,
n ).vector;
This class handles vector_complexs as shared handles.
This class can be used like a pointer for complex objects so that we can iterate over a vector (for e...
This class can be used like a reference for complex objects so that we can iterate over a vector (for...
This class handles complex numbers.
@ GSL_EDOM
input domain error, e.g sqrt(-1)
@ GSL_EFAILED
generic failure
@ GSL_EINVAL
invalid argument supplied by user
@ GSL_EBADLEN
matrix, vector lengths are not conformant
This class handles matrix_complex objects as shared handles.
A class template for the const iterators.
const_iterator_t< reverse_t > & operator+=(difference_type const n)
The += operator.
bool operator<(iterator_t< reverse_t > const &i) const
Comparison with non-const iterator.
const_iterator_t< reverse_t > & operator--()
The prefix – operator.
const_iterator_t< reverse_t > & operator++()
The prefix ++ operator.
difference_type operator-(const_iterator_t< reverse_t > const &i) const
The - operator: find distance between two iterators.
const_iterator_t(iterator_t< reverse_t > const &i)
A copy constructor.
bool operator!=(iterator_t< reverse_t > const &i) const
Comparison with non-const iterator.
iterator_base< vector_complexconst, double, reverse_t >::difference_type difference_type
Difference type.
const_iterator_t< reverse_t > & operator=(const_iterator_t< reverse_t > const &i)
We can assign one output iterator from another.
difference_type operator-(iterator_t< reverse_t > const &i) const
The - operator: find distance between two iterators.
const_iterator_t< reverse_t > operator++(int)
The postfix ++ operator.
const_iterator_t(vector_complex const *v, difference_type position)
This constructor allows vector_complex to create non-default iterators.
const_iterator_t< reverse_t > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
bool operator==(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
const_iterator_t< reverse_t > operator--(int)
The postfix – operator.
bool operator<(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
bool operator==(iterator_t< reverse_t > const &i) const
Comparison with non-const iterator.
const_iterator_t< reverse_t > & operator-=(difference_type const n)
The -= operator.
const_iterator_t()
The default constructor.
bool operator!=(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
const_iterator_t< reverse_t > operator+(difference_type const n) const
The + operator.
The container must have iterator types.
std::random_access_iterator_tag iterator_category
An iterator must have a pointer type.
difference_type operator-(iterator_base< container, content, reverse_t > const &i) const
The - operator: find distance between two iterators.
void shift(difference_type const n)
Shift iterator n places.
pointer operator->() const
Dereference the pointer.
bool operator!=(iterator_base< container, content, reverse_t > const &i) const
The != operator.
difference_type position
Mark position of iterator within vector_complex.
reference operator*() const
Dereference the pointer.
void decrement()
Decrement the iterator.
iterator_base()
The iterator is default constructible.
ptrdiff_t difference_type
An iterator must have a difference_type.
complex_ptr pointer
An iterator must have a pointer type.
complex value_type
An iterator must have a value_type.
bool operator==(iterator_base< container, content, reverse_t > const &i) const
The == operator.
bool operator<(iterator_base< container, content, reverse_t > const &i) const
The < operator is used to compare iterators.
iterator_base(container *v, difference_type position)
This constructor allows vector_complex to create non-default iterators.
void increment()
Increment the iterator.
container * v
Store a pointer to a vector_complex we can iterate over: 0 if no vector_complex.
complex_ref reference
An iterator must have a reference type.
reference operator[](difference_type const n) const
Get element at i + n by reference ([] operator).
A class template for the two non-const iterators.
bool operator!=(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
bool operator<(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
iterator_t(vector_complex *v, difference_type position)
This constructor allows vector_complex to create non-default iterators.
iterator_t< reverse_t > operator--(int)
The postfix – operator.
iterator_t< reverse_t > operator-(difference_type const n) const
The - operator: subtract distance from iterator.
difference_type operator-(iterator_t< reverse_t > const &i) const
The - operator: find distance between two iterators.
iterator_t< reverse_t > & operator-=(difference_type const n)
The -= operator.
iterator_t< reverse_t > operator+(difference_type const n) const
The + operator.
iterator_base< vector_complex, double, reverse_t >::difference_type difference_type
Difference type.
iterator_t< reverse_t > & operator++()
The prefix ++ operator.
iterator_t()
The default constructor.
iterator_t< reverse_t > & operator=(iterator_t< reverse_t > const &i)
We can assign one output iterator from another.
bool operator==(const_iterator_t< reverse_t > const &i) const
Comparison with const iterator.
iterator_t< reverse_t > operator++(int)
The postfix ++ operator.
iterator_t< reverse_t > & operator--()
The prefix – operator.
difference_type operator-(const_iterator_t< reverse_t > const &i) const
The - operator: find distance between two iterators.
iterator_t< reverse_t > & operator+=(difference_type const n)
The += operator.
This class handles vector_complex objects as shared handles.
const_iterator end() const
Get iterator pointing beyond last vector_complex element.
bool operator>=(vector_complex const &v) const
A container needs to define an ordering for sorting.
void set_zero()
C++ version of gsl_vector_complex_set_zero().
vector_complex(block_complex &b, size_t const offset, size_t const n, size_t const stride=1)
C++ version of gsl_vector_complex_alloc_from_block().
int fwrite(FILE *stream) const
C++ version of gsl_vector_complex_fwrite().
size_type size() const
The size (number of elements) of the vector_complex.
static vector_complex alloc_row_from_matrix(matrix_complex &m, size_t const i)
C++ version of gsl_vector_complex_alloc_row_from_matrix().
size_type max_size() const
The max size (number of elements) of the vector_complex.
int ispos() const
C++ version of gsl_vector_complex_ispos().
vector_complex(vector_complex &&v)
Move constructor.
double * data()
Give access to the data block.
bool operator==(vector_complex const &v) const
Two vector_complex objects are identically equal if their elements are identical.
vector_complex(vector_complex &v, size_t const offset, size_t const n, size_t const stride=1)
C++ version of gsl_vector_complex_alloc_from_vector().
const_iterator_t< false > const_iterator
The const_iterator type.
static vector_complex const const_view_array_with_stride(ARRAY const &base, size_t stride, size_t n=0)
C++ version of gsl_vector_complex_const_view_array_with_stride().
complex_ref operator[](size_t const n)
Get element at position n by reference ([] operator).
bool operator!=(vector_complex const &v) const
Two vector_complex objects are different equal if their elements are not identical.
static vector_complex calloc(size_t const n)
C++ version of gsl_vector_complex_calloc().
int reverse()
C++ version of gsl_vector_complex_reverse().
const_reverse_iterator rbegin() const
Get iterator pointing to first vector_complex element.
const_iterator::difference_type difference_type
A container must have a difference_type.
int div(vector_complex const &b)
C++ version of gsl_vector_complex_div().
static vector_complex alloc_col_from_matrix(matrix_complex &m, size_t const j)
C++ version of gsl_vector_complex_alloc_col_from_matrix().
vector_complex(size_t const n)
The default constructor creates a new vector_complex with n elements.
vector_complex clone() const
The clone function.
complex_ptr const const_ptr(size_t const i)
C++ version of gsl_vector_complex_const_ptr().
vector_complex & operator=(vector_complex const &v)
The assignment operator.
vector_complex subvector(size_t i, size_t n)
C++ version of gsl_vector_complex_subvector().
iterator end()
Get iterator pointing beyond last vector_complex element.
gsl::vector imag()
C++ version of gsl_vector_complex_imag().
void swap(vector_complex &v)
Swap two vector_complex objects.
int add(vector_complex const &b)
C++ version of gsl_vector_complex_add().
vector_complex & operator=(vector_complex &&v)
Move operator.
iterator begin()
Get iterator pointing to first vector_complex element.
const_iterator_t< true > const_reverse_iterator
The const_reverse_t type.
int add_constant(complex const x)
C++ version of gsl_vector_complex_add_constant().
complex_ref const operator[](size_t const n) const
Get element at position n by reference ([] operator).
gsl_vector_complex * get()
Get the gsl_vector_complex.
bool empty() const
Find if the vector_complex is empty.
static vector_complex view_array(ARRAY &v, size_t n=0)
C++ version of gsl_vector_complex_view_array().
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_vector_complex_fprintf().
bool owns_data
Used to allow a vector that does not own its data.
complex_ref reference
A container must have a reference type.
int axpby(complex const alpha, vector_complex const &x, complex const beta)
C++ version of gsl_vector_complex_axpby().
size_t use_count() const
Find how many vector_complex objects share this pointer.
complex value_type
A container must have a value_type.
void set_all(complex x)
C++ version of gsl_vector_complex_set_all().
vector_complex const const_subvector(size_t i, size_t n) const
C++ version of gsl_vector_complex_const_subvector().
void wrap_gsl_vector_complex_without_ownership(gsl_vector_complex *v)
This function is intended mainly for internal use.
int sub(vector_complex const &b)
C++ version of gsl_vector_complex_sub().
static vector_complex const const_view_array(ARRAY const &v, size_t n=0)
C++ version of gsl_vector_complex _const_view_array().
iterator_t< false > iterator
The iterator type.
static vector_complex view_array_with_stride(ARRAY &base, size_t stride, size_t n=0)
C++ version of gsl_vector_complex_view_array_with_stride().
gsl_vector_complex const * get() const
Get the gsl_vector_complex.
reference const const_reference
A container must have a constant reference type.
~vector_complex()
The destructor only deletes the pointers if count reaches zero.
int fread(FILE *stream)
C++ version of gsl_vector_complex_fread().
int memcpy(vector_complex const &src)
C++ version of gsl_vector_complex_memcpy().
complex_ptr ptr(size_t const i)
C++ version of gsl_vector_complex_ptr().
iterator_t< true > reverse_iterator
The reverse_iterator type.
complex get(size_t const i) const
C++ version of gsl_vector_complex_get().
gsl::vector const real() const
Another C++ version of gsl_vector_complex_const_real().
void set(size_t const i, complex x)
C++ version of gsl_vector_complex_set().
bool operator<=(vector_complex const &v) const
A container needs to define an ordering for sorting.
double const * data() const
Give access to the data block.
complex_ptr pointer
A container must have a pointer type.
static vector_complex const const_view_array(double const *v, size_t n)
C++ version of gsl_vector_complex _const_view_array().
reverse_iterator rbegin()
Get iterator pointing to first vector_complex element.
void reset()
Stop sharing ownership of the shared pointer.
static vector_complex view_array(double *v, size_t n)
C++ version of gsl_vector_complex_view_array().
static vector_complex const const_view_array_with_stride(double const *base, size_t stride, size_t n)
C++ version of gsl_vector_complex_const_view_array_with_stride().
bool operator<(vector_complex const &v) const
A container needs to define an ordering for sorting.
size_t * count
The shared reference count.
gsl::vector real()
C++ version of gsl_vector_complex_real().
gsl_vector_complex * ccgsl_pointer
The shared pointer.
gsl::vector const const_imag() const
C++ version of gsl_vector_complex_const_imag().
vector_complex()
The default constructor is only really useful for assigning to.
vector_complex const const_subvector_with_stride(size_t i, size_t stride, size_t n) const
C++ version of gsl_vector_complex_const_subvector_with_stride().
int mul(vector_complex const &b)
C++ version of gsl_vector_complex_mul().
gsl::vector const const_real() const
C++ version of gsl_vector_complex_const_real().
gsl::vector const imag() const
Another C++ version of gsl_vector_complex_const_imag().
bool unique() const
Find if this is the only object sharing the gsl_vector_complex.
int isnonneg() const
C++ version of gsl_vector_complex_isnonneg().
int set_basis(size_t i)
C++ version of gsl_vector_complex_set_basis().
int fscanf(FILE *stream)
C++ version of gsl_vector_complex_fscanf().
const_iterator begin() const
Get iterator pointing to first vector_complex element.
int swap_elements(size_t const i, size_t const j)
C++ version of gsl_vector_complex_swap_elements().
int isneg() const
C++ version of gsl_vector_complex_isneg().
vector_complex(vector_complex const &v)
The copy constructor.
size_t size_type
A container must have a size_type.
int isnull() const
C++ version of gsl_vector_complex_isnull().
vector_complex(std::initializer_list< std::complex< double > > initializer_list)
Could construct from a std::initializer_list in C++11.
bool operator>(vector_complex const &v) const
A container needs to define an ordering for sorting.
int scale(complex const x)
C++ version of gsl_vector_complex_scale().
complex_ptr const const_pointer
A container must have a constant pointer type.
const_reverse_iterator rend() const
Get iterator pointing beyond last vector_complex element.
reverse_iterator rend()
Get iterator pointing beyond last vector_complex element.
static vector_complex view_array_with_stride(double *base, size_t stride, size_t n)
C++ version of gsl_vector_complex_view_array_with_stride().
vector_complex subvector_with_stride(size_t i, size_t stride, size_t n)
C++ version of gsl_vector_complex_subvector_with_stride().
This class handles vector objects as shared handles.
static vector view_array_with_stride(double *base, size_t stride, size_t n)
C++ version of gsl_vector_view_array_with_stride().
static vector const const_view_array_with_stride(double const *base, size_t stride, size_t n)
C++ version of gsl_vector_const_view_array_with_stride().
int min(movstat::end_t const endtype, vector const &x, vector &y, workspace &w)
C++ version of gsl_movstat_min().
double beta(rng const &r, double const a, double const b)
C++ version of gsl_ran_beta().
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
gsl_sf_result result
Typedef for gsl_sf_result.
The gsl package creates an interface to the GNU Scientific Library for C++.