Add abs functions

This commit is contained in:
zhoushunjie
2022-11-24 04:02:00 +00:00
parent a14c55069f
commit 12af6b4464
4 changed files with 34 additions and 0 deletions

View File

@@ -52,5 +52,14 @@ template <typename T> struct SqrtFunctor {
}
};
// abs(x) = x if x > 0 else -x
template <typename T> struct AbsFunctor {
template <typename Device, typename X, typename Out>
void operator()(Device d, X x, Out out) const {
out.device(d) =
x.unaryExpr([](T v) { return v > static_cast<T>(0) ? v : -v; });
}
};
} // namespace function
} // namespace fastdeploy