74 #ifndef SLIP_VECTOR_HPP
75 #define SLIP_VECTOR_HPP
94 #include <boost/serialization/access.hpp>
95 #include <boost/serialization/split_member.hpp>
96 #include <boost/serialization/string.hpp>
97 #include <boost/serialization/complex.hpp>
98 #include <boost/serialization/version.hpp>
103 template <
typename T>
106 template <
typename T>
119 bool operator<(const Vector<T>& x,
127 bool operator<=(const Vector<T>& x,
152 template <
typename T>
188 static const std::size_t
DIM = 1;
231 template<
typename InputIterator>
673 friend std::ostream& operator<< <>(std::ostream & out,
706 std::fill_n(this->
begin(),this->
size(),value);
728 template<
typename InputIterator>
747 friend bool operator== <>(
const Vector<T>& x,
756 friend bool operator!= <>(
const Vector<T>& x,
765 friend bool operator< <>(
const Vector<T>& x,
774 friend bool operator> <>(
const Vector<T>& x,
783 friend bool operator<= <>(
const Vector<T>& x,
792 friend bool operator>= <>(
const Vector<T>& x,
929 std::string
name()
const;
979 assert(this->
size() != 0);
989 assert(this->
size() != 0);
999 assert(this->
size() != 0);
1000 return slip::L1_norm<norm_type>(this->
begin(),this->
end());
1009 assert(this->
size() != 0);
1019 assert(this->
size() != 0);
1020 return slip::infinite_norm<norm_type>(this->
begin(),this->
end());
1060 friend class boost::serialization::access;
1061 template<
class Archive>
1062 void save(Archive & ar,
const unsigned int version)
const
1066 template<
class Archive>
1067 void load(Archive & ar,
const unsigned int version)
1071 BOOST_SERIALIZATION_SPLIT_MEMBER();
1104 template<
typename T>
1114 template<
typename T>
1124 template<
typename T>
1136 template<
typename T>
1146 template<
typename T>
1156 template<
typename T>
1167 template<
typename T>
1177 template<
typename T>
1187 template<
typename T>
1198 template<
typename T>
1208 template<
typename T>
1221 template<
typename T>
1231 template<
typename T>
1241 template<
typename T>
1250 template<
typename T>
1259 template<
typename T>
1290 template<
typename T>
1321 template<
typename T>
1353 template<
typename T>
1362 template<
typename T>
1371 template<
typename T>
1380 template<
typename T>
1389 template<
typename T>
1398 template<
typename T>
1405 template<
typename T>
1408 array_(new slip::
Array<T>())
1411 template<
typename T>
1414 array_(new slip::
Array<T>(n))
1417 template<
typename T>
1421 array_(new slip::
Array<T>(n,val))
1424 template<
typename T>
1428 array_(new slip::
Array<T>(n,val))
1431 template<
typename T>
1434 array_(new slip::
Array<T>((*rhs.array_)))
1437 template<
typename T>
1443 *array_ = *(rhs.array_);
1448 template<
typename T>
1455 template<
typename T>
1459 array_->operator=(val);
1463 template<
typename T>
1468 array_->resize(new_size,val);
1472 template<
typename T>
1476 return array_->begin();
1479 template<
typename T>
1483 return array_->end();
1486 template<
typename T>
1494 template<
typename T>
1503 template<
typename T>
1507 return array_->rbegin();
1510 template<
typename T>
1514 return array_->rend();
1517 template<
typename T>
1525 template<
typename T>
1534 template<
typename T>
1539 return array_->begin(range);
1542 template<
typename T>
1547 return array_->end(range);
1550 template<
typename T>
1556 return tp->
begin(range);
1559 template<
typename T>
1565 return tp->
end(range);
1569 template<
typename T>
1574 return array_->begin(box);
1577 template<
typename T>
1582 return array_->end(box);
1585 template<
typename T>
1591 return tp->
begin(box);
1594 template<
typename T>
1600 return tp->
end(box);
1604 template<
typename T>
1608 return array_->rbegin(box);
1611 template<
typename T>
1616 return array_->rend(box);
1619 template<
typename T>
1628 template<
typename T>
1634 return tp->
rend(box);
1637 template<
typename T>
1641 return array_->rbegin(range);
1644 template<
typename T>
1649 return array_->rend(range);
1652 template<
typename T>
1658 return tp->
rbegin(range);
1661 template<
typename T>
1667 return tp->
rend(range);
1671 template <
typename T>
1680 template<
typename T>
1684 return (*array_)[i];
1687 template<
typename T>
1691 return (*array_)[i];
1694 template<
typename T>
1698 return (*array_)(i);
1701 template<
typename T>
1705 return (*array_)(i);
1708 template <
typename T>
1710 typename Vector<T>::reference
1713 return (*array_)(p);
1716 template <
typename T>
1718 typename Vector<T>::const_reference
1721 return (*array_)(p);
1724 template<
typename T>
1728 assert(this->array_ != 0);
1730 assert(range.
start() < (int)this->size());
1731 assert(range.
stop() < (int)this->size());
1732 return Vector<T>(array_->begin(range),array_->end(range));
1736 template<
typename T>
1741 template<
typename T>
1745 template<
typename T>
1752 template<
typename T>
1756 template<
typename T>
1760 array_->swap(*(V.array_));
1764 template<
typename T>
1768 std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::plus<T>(),val));
1772 template<
typename T>
1776 std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::minus<T>(),val));
1780 template<
typename T>
1784 std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),val));
1788 template<
typename T>
1792 std::transform(array_->begin(),array_->end(),array_->begin(),std::bind2nd(std::multiplies<T>(),T(1)/val));
1797 template<
typename T>
1802 std::transform(array_->begin(),array_->end(),tmp.
begin(),std::negate<T>());
1806 template<
typename T>
1810 assert(this->size() == rhs.
size());
1811 std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::plus<T>());
1815 template<
typename T>
1819 assert(this->size() == rhs.
size());
1820 std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::minus<T>());
1824 template<
typename T>
1828 assert(this->size() == rhs.
size());
1829 std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::multiplies<T>());
1833 template<
typename T>
1837 assert(this->size() == rhs.
size());
1838 std::transform(array_->begin(),array_->end(),(*(rhs.array_)).begin(),array_->begin(),std::divides<T>());
1842 template<
typename T>
1846 assert(array_->size() != 0);
1847 return *std::min_element(array_->begin(),array_->end(),std::less<T>());
1850 template<
typename T>
1854 assert(array_->size() != 0);
1855 return *std::max_element(array_->begin(),array_->end(),std::less<T>());
1858 template<
typename T>
1862 assert(array_->size() != 0);
1863 return std::accumulate(array_->begin(),array_->end(),T(0));
1866 template<
typename T>
1870 slip::apply(this->begin(),this->end(),this->begin(),fun);
1874 template<
typename T>
1878 slip::apply(this->begin(),this->end(),this->begin(),fun);
1886 template<
typename T>
1893 std::transform(V1.
begin(),V1.
end(),V2.
begin(),tmp.begin(),std::plus<T>());
1898 template<
typename T>
1908 template<
typename T>
1916 template<
typename T>
1923 std::transform(V1.
begin(),V1.
end(),V2.
begin(),tmp.begin(),std::minus<T>());
1927 template<
typename T>
1937 template<
typename T>
1945 template<
typename T>
1952 std::transform(V1.
begin(),V1.
end(),V2.
begin(),tmp.begin(),std::multiplies<T>());
1956 template<
typename T>
1966 template<
typename T>
1974 template<
typename T>
1981 std::transform(V1.
begin(),V1.
end(),V2.
begin(),tmp.begin(),std::divides<T>());
1985 template<
typename T>
1997 template<
typename T>
2004 template<
typename T>
2011 template<
typename T>
2021 template<
typename T>
2030 template<
typename T>
2064 template<
typename T>
2099 template<
typename T>
2132 template<
typename T>
2141 template<
typename T>
2150 template<
typename T>
2159 template<
typename T>
2168 template<
typename T>
2177 template<
typename T>
2188 template<
typename T>
2193 return *(x.array_) == *(y.array_);
2196 template<
typename T>
2206 template<
typename T>
2208 bool operator<(const Vector<T>& x,
2211 return *(x.array_) < *(y.array_);
2214 template<
typename T>
2222 template<
typename T>
2224 bool operator<=(const Vector<T>& x,
2230 template<
typename T>
2240 #endif //SLIP_VECTOR_HPP
HyperVolume< T > tanh(const HyperVolume< T > &M)
ptrdiff_t difference_type
bool operator!=(const Array< T > &x, const Array< T > &y)
~Vector()
Destructor of the Vector.
norm_type L22_norm() const
Returns the L22 norm ( ) of the elements of the Vector.
Vector()
Constructs a Vector.
norm_type infinite_norm() const
Returns the infinite norm ( ) of the elements of the Vector.
slip::Vector< unsigned long > Vector_ul
unsigned long alias
Vector< long double > atan(const Vector< long double > &V)
self & operator-=(const T &val)
self & operator/=(const T &val)
Vector< T > cos(const Vector< T > &V)
T sum() const
Returns the sum of the elements of the Vector.
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Array...
T & min() const
Returns the min element of the Vector according to the operator < if T is std::complex, it returns the element of minimum magnitude.
slip::stride_iterator< const_pointer > const_iterator_range
iterator end()
Returns a read/write iterator that points one past the last element in the Vector. Iteration is done in ordinary element order.
const_pointer const_iterator
slip::Vector< short > Vector_s
short alias
slip::lin_alg_traits< typename std::iterator_traits< InputIterator >::value_type >::value_type L22_norm_cplx(InputIterator first, InputIterator last)
Computes the L22 norm of a complex container.
HyperVolume< T > cosh(const HyperVolume< T > &M)
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
Color< T > operator+(const Color< T > &V1, const Color< T > &V2)
iterator begin()
Returns a read/write iterator that points to the first element in the Array. Iteration is done in ord...
std::reverse_iterator< const_iterator > const_reverse_iterator
slip::Vector< double > Vector_d
double alias
norm_type L1_norm() const
Returns the L1 norm ( ) of the elements of the Vector.
HyperVolume< T > atan(const HyperVolume< T > &M)
norm_type Euclidean_norm() const
Returns the Euclidean norm of the elements of the Vector.
Vector< T > log10(const Vector< T > &V)
slip::Vector< float > Vector_f
float alias
iterator default_iterator
HyperVolume< T > exp(const HyperVolume< T > &M)
Vector< T > exp(const Vector< T > &V)
static const std::size_t DIM
Provides common linear algebra algorithms.
Vector< T > & apply(T(*fun)(T))
Applys the one-parameter C-function fun to each element of the Vector.
HyperVolume< T > abs(const HyperVolume< T > &M)
bool operator>(const Array< T > &x, const Array< T > &y)
std::string name() const
Returns the name of the class.
HyperVolume< T > sin(const HyperVolume< T > &M)
Provides a class to manipulate 1d dynamic and generic arrays.
HyperVolume< T > cos(const HyperVolume< T > &M)
Vector(InputIterator first, InputIterator last)
Contructs a Vector from a range.
std::reverse_iterator< const_iterator_range > const_reverse_iterator_range
slip::Vector< unsigned short > Vector_us
unsigned long alias
std::reverse_iterator< iterator > reverse_iterator
Vector< T > sinh(const Vector< T > &V)
This is a point1d class, a specialized version of Point<CoordType,DIM> with DIM = 1...
iterator end()
Returns a read/write iterator that points one past the last element in the Array. Iteration is done i...
size_type size() const
Returns the number of elements in the Vector.
void fill(const T *value)
Fills the container range [begin(),begin()+size()) with a copy of the value array.
void fill(const T &value)
Fills the container range [begin(),begin()+size()) with copies of value.
const_iterator const_default_iterator
slip::Vector< unsigned char > Vector_uc
unsigned char alias
This is a Box1d class, a specialized version of slip::Box<CoordType,DIM> with DIM = 1...
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Provides some macros which are used for using complex as real.
Vector< long double > asin(const Vector< long double > &V)
bool is_valid() const
Returns true if the range is valid :
SubType start() const
Accessor of the start subscript of the Range.
Numerical Vector class. This container statisfies the RandomAccessContainer concepts of the Standard ...
slip::Vector< unsigned int > Vector_ui
unsigned int alias
HyperVolume< T > sqrt(const HyperVolume< T > &M)
const value_type & const_reference
self & operator+=(const T &val)
Add val to each element of the Vector.
HyperVolume< T > sinh(const HyperVolume< T > &M)
void resize(const size_type new_n, const T &val=T())
Resizes a Vector.
Vector< T > sin(const Vector< T > &V)
const value_type * const_pointer
Vector< T > cosh(const Vector< T > &V)
Vector< T > log(const Vector< T > &V)
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Vector. Iteration is done in reverse element order.
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
reference operator()(const size_type i)
Subscript access to the data contained in the Vector.
bool empty() const
Returns true if the Vector is empty. (Thus size() == 0)
slip::Vector< long > Vector_l
long alias
reverse_iterator rend()
Returns a read/write reverse iterator that points to one before the first element in the Vector...
HyperVolume< T > log(const HyperVolume< T > &M)
Vector< T > tan(const Vector< T > &V)
Vector< long double > acos(const Vector< long double > &V)
HyperVolume< T > acos(const HyperVolume< T > &M)
HyperVolume< T > log10(const HyperVolume< T > &M)
size_type max_size() const
Returns the maximal size (number of elements) in the Vector.
T & max() const
Returns the max element of the Vector according to the operator >, if T is std::complex, it returns the element of maximum magnitude.
void fill(InputIterator first, InputIterator last)
Fills the container range [begin(),begin()+size()) with a copy of the range [first,last)
slip::Vector< char > Vector_c
char alias
slip::lin_alg_traits< value_type >::value_type norm_type
slip::stride_iterator< pointer > iterator_range
Provides some algorithms to apply C like functions to ranges.
Vector< T > sqrt(const Vector< T > &V)
Provides a class to iterate a 1d range according to a step.
norm_type L2_norm() const
Returns the Euclidean norm of the elements of the Vector.
HyperVolume< T > tan(const HyperVolume< T > &M)
reference operator[](const size_type i)
Subscript access to the data contained in the Vector.
bool operator==(const Array< T > &x, const Array< T > &y)
std::reverse_iterator< iterator_range > reverse_iterator_range
HyperVolume< T > asin(const HyperVolume< T > &M)
This is a linear (one-dimensional) dynamic template container. This container statisfies the RandomAc...
reverse_iterator rbegin()
Returns a read/write reverse iterator that points to the last element in the Array. Iteration is done in reverse element order.
self & operator*=(const T &val)
Vector< typename slip::lin_alg_traits< T >::value_type > abs(const Vector< T > &V)
Color< T > operator*(const Color< T > &V1, const Color< T > &V2)
void swap(self &M)
Swaps data with another Vector.
Provides a class to manipulate 1d box.
void apply(InputIterator first, InputIterator last, OutputIterator result, typename std::iterator_traits< OutputIterator >::value_type(*function)(typename std::iterator_traits< InputIterator >::value_type))
Applies a C-function to each element of a range.
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
SubType stop() const
Accessor of the stop subscript of the Range.
iterator begin()
Returns a read/write iterator that points to the first element in the Vector. Iteration is done in or...
Color< T > operator/(const Color< T > &V1, const Color< T > &V2)
const Vector< T > const_self
bool operator>=(const Array< T > &x, const Array< T > &y)
slip::Vector< int > Vector_i
int alias
Color< T > operator-(const Color< T > &V1, const Color< T > &V2)
self & operator=(const self &rhs)
Assign a Vector.
Provides some algorithms to compute norms.
Vector< T > tanh(const Vector< T > &V)