Refactor geom::pointwise* and add geom::pointwise_pow
This commit is contained in:
parent
e55a98c2a0
commit
e3750707bc
1 changed files with 21 additions and 16 deletions
|
|
@ -343,40 +343,45 @@ namespace psemek::geom
|
||||||
return {v[0] * c - v[1] * s, v[0] * s + v[1] * c};
|
return {v[0] * c - v[1] * s, v[0] * s + v[1] * c};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename F, std::size_t N, typename ... Ts>
|
||||||
|
auto pointwise(F && f, vector<Ts, N> const & ... vs)
|
||||||
|
{
|
||||||
|
using R = decltype(f(vs[0]...));
|
||||||
|
|
||||||
|
vector<R, N> result;
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
result[i] = f(vs[i]...);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
vector<T, N> pointwise_mult(vector<T, N> const & v0, vector<T, N> const & v1)
|
vector<T, N> pointwise_mult(vector<T, N> const & v0, vector<T, N> const & v1)
|
||||||
{
|
{
|
||||||
vector<T, N> result;
|
return pointwise([](T const & a, T const & b){ return a * b; }, v0, v1);
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
|
||||||
result[i] = v0[i] * v1[i];
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
vector<T, N> pointwise_divide(vector<T, N> const & v0, vector<T, N> const & v1)
|
vector<T, N> pointwise_divide(vector<T, N> const & v0, vector<T, N> const & v1)
|
||||||
{
|
{
|
||||||
vector<T, N> result;
|
return pointwise([](T const & a, T const & b){ return a / b; }, v0, v1);
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
|
||||||
result[i] = v0[i] / v1[i];
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
vector<T, N> pointwise_log(vector<T, N> const & v)
|
vector<T, N> pointwise_log(vector<T, N> const & v)
|
||||||
{
|
{
|
||||||
vector<T, N> result;
|
return pointwise([](T const & a){ return std::log(a); }, v);
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
|
||||||
result[i] = std::log(v[i]);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
vector<T, N> pointwise_exp(vector<T, N> const & v)
|
vector<T, N> pointwise_exp(vector<T, N> const & v)
|
||||||
{
|
{
|
||||||
vector<T, N> result;
|
return pointwise([](T const & a){ return std::exp(a); }, v);
|
||||||
for (std::size_t i = 0; i < N; ++i)
|
}
|
||||||
result[i] = std::exp(v[i]);
|
|
||||||
return result;
|
template <typename T, std::size_t N>
|
||||||
|
vector<T, N> pointwise_pow(vector<T, N> const & v0, vector<T, N> const & v1)
|
||||||
|
{
|
||||||
|
return pointwise([](T const & a, T const & b){ return std::pow(a, b); }, v0, v1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue