mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
add valarray
This commit is contained in:
parent
5ff6029d51
commit
1b8c051008
27 changed files with 3330 additions and 5 deletions
116
sprout/valarray/arithmetic.hpp
Normal file
116
sprout/valarray/arithmetic.hpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2016 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_VALARRAY_ARITHMETIC_HPP
|
||||
#define SPROUT_VALARRAY_ARITHMETIC_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/valarray/valarray.hpp>
|
||||
#include <sprout/algorithm/fixed/transform.hpp>
|
||||
#include <sprout/functional/plus.hpp>
|
||||
#include <sprout/functional/minus.hpp>
|
||||
#include <sprout/functional/multiplies.hpp>
|
||||
#include <sprout/functional/divides.hpp>
|
||||
#include <sprout/functional/modulus.hpp>
|
||||
#include <sprout/functional/bind2nd.hpp>
|
||||
#include <sprout/functional/bind1st.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// operator+
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::plus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::plus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator+(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::plus<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator-
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::minus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::minus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator-(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::minus<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator*
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::multiplies<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::multiplies<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator*(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::multiplies<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator/
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::divides<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::divides<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator/(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::divides<>(), lhs));
|
||||
}
|
||||
//
|
||||
// operator%
|
||||
//
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(sprout::valarray<T, N> const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs, sprout::modulus<>());
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(sprout::valarray<T, N> const& lhs, T const& rhs) {
|
||||
return sprout::fixed::transform(lhs.begin(), lhs.end(), lhs, sprout::bind2nd(sprout::modulus<>(), rhs));
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR sprout::valarray<T, N>
|
||||
operator%(T const& lhs, sprout::valarray<T, N> const& rhs) {
|
||||
return sprout::fixed::transform(rhs.begin(), rhs.end(), rhs, sprout::bind1st(sprout::modulus<>(), lhs));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_VALARRAY_ARITHMETIC_HPP
|
Loading…
Add table
Add a link
Reference in a new issue