Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement csqrt #619

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion include/matx/operators/scalar_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,38 @@ template <typename T> struct SqrtF {
}
};

template <typename T> using SqrtOp = UnOp<T, SqrtF<T>>;
template <typename T>
static __MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ auto _internal_csqrt(T v1)
{
if constexpr (is_cuda_complex_v<T>)
cliffburdick marked this conversation as resolved.
Show resolved Hide resolved
{
return cuda::std::sqrt(v1);
}
else {
///\todo TYLER_TODO should probably protect for only float types
return sqrt(static_cast<cuda::std::complex<T>>(v1));
}
if constexpr (!is_cuda_complex_v<T>) {
cliffburdick marked this conversation as resolved.
Show resolved Hide resolved
///\todo TYLER_TODO should probably protect for only float types
return sqrt(static_cast<cuda::std::complex<T>>(v1));
}
else {
return cuda::std::sqrt(v1);
}

}

template <typename T> struct CSqrtF {
static __MATX_INLINE__ std::string str() { return "csqrt"; }
static __MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ auto op(T v1)
{
return _internal_csqrt(v1);
}
};


template <typename T> using SqrtOp = UnOp<T, SqrtF<T>>;
template <typename T> using CsqrtOp = UnOp<T, CSqrtF<T>>;

template <typename T>
static __MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ auto _internal_conj(T v1)
Expand Down
1 change: 1 addition & 0 deletions include/matx/operators/unary_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ namespace matx

#else
DEFINE_UNARY_OP(sqrt, detail::SqrtOp);
DEFINE_UNARY_OP(csqrt, detail::CsqrtOp);
DEFINE_UNARY_OP(exp, detail::ExpOp);
DEFINE_UNARY_OP(expj, detail::ExpjOp);
DEFINE_UNARY_OP(log10, detail::Log10Op);
Expand Down