mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
Add abs functions
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user