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

Hermitian nd #293

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Changes from all 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
12 changes: 9 additions & 3 deletions include/matx/operators/hermitian.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ namespace matx
using scalar_type = typename T1::scalar_type;

__MATX_INLINE__ std::string str() { return "hermitian(" + op_.str() + ")"; }
__MATX_INLINE__ HermitianTransOp(T1 op) : op_(op) {}
__MATX_INLINE__ HermitianTransOp(T1 op) : op_(op) {
static_assert(Rank() >= 2, "Hermitian operation needs input with rank >= 2");
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
{
auto tup = cuda::std::make_tuple(indices...);
return conj(mapply_reverse(op_, tup));
auto stl = cuda::std::get<Rank()-2>(tup);
cuda::std::get<Rank()-2>(tup) = cuda::std::get<Rank()-1>(tup);
cuda::std::get<Rank()-1>(tup) = stl;
return conj(mapply(op_, tup));
}

static __MATX_INLINE__ constexpr __MATX_HOST__ __MATX_DEVICE__ int32_t Rank()
Expand All @@ -71,7 +76,8 @@ namespace matx
}
constexpr __MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ index_t Size(int dim) const
{
return op_.Size(Rank() - dim - 1);
// Optimize these branches later
return (dim < (Rank() - 2)) ? op_.Size(dim) : op_.Size((dim == Rank() - 1) ? Rank() - 2 : Rank() - 1);
}
};
}
Expand Down