Skip to content

Commit

Permalink
Fixing return types to allow either prvalue or lvalue in operator()
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffburdick committed Mar 22, 2024
1 parent f0ae8a6 commit 98f3231
Show file tree
Hide file tree
Showing 85 changed files with 127 additions and 125 deletions.
8 changes: 4 additions & 4 deletions include/matx/core/tensor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class tensor_impl_t {
*
*/
template <int M = RANK, typename... Is>
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ const T &operator()(Is... indices) const noexcept
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(Is... indices) const noexcept
{
static_assert(sizeof...(Is) == M, "Number of indices of operator() must match rank of tensor");
#ifndef NDEBUG
Expand All @@ -699,7 +699,7 @@ class tensor_impl_t {
*/
template <int M = RANK, typename... Is,
std::enable_if_t<std::conjunction_v<std::is_integral<Is>...>, bool> = true>
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ T &operator()(Is... indices) noexcept
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(Is... indices) noexcept
{
static_assert(sizeof...(Is) == M, "Number of indices of operator() must match rank of tensor");
#ifndef NDEBUG
Expand All @@ -714,7 +714,7 @@ class tensor_impl_t {
* @returns value in tensor
*
*/
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ const T operator()(const std::array<index_t, RANK> &idx) const noexcept
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(const std::array<index_t, RANK> &idx) const noexcept
{
return std::apply([&](auto &&...args) -> T {
return this->operator()(args...);
Expand All @@ -727,7 +727,7 @@ class tensor_impl_t {
* @returns value in tensor
*
*/
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ T &operator()(const std::array<index_t, RANK> &idx) noexcept
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(const std::array<index_t, RANK> &idx) noexcept
{
return std::apply([&](auto &&...args) -> T& {
return this->operator()(args...);
Expand Down
4 changes: 2 additions & 2 deletions include/matx/generators/chirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace matx
method_(method)
{}

inline __MATX_HOST__ __MATX_DEVICE__ auto operator()(index_t i) const
inline __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(index_t i) const
{
if (method_ == ChirpMethod::CHIRP_METHOD_LINEAR) {
return cuda::std::cos(2.0f * M_PI * (f0_ * sop_(i) + 0.5f * ((f1_ - f0_) / t1_) * sop_(i) * sop_(i)));
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace matx
method_(method)
{}

inline __MATX_HOST__ __MATX_DEVICE__ auto operator()(index_t i) const
inline __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(index_t i) const
{
if (method_ == ChirpMethod::CHIRP_METHOD_LINEAR) {
FreqType real = cuda::std::cos(2.0f * M_PI * (f0_ * sop_(i) + 0.5f * ((f1_ - f0_) / t1_) * sop_(i) * sop_(i)));
Expand Down
2 changes: 1 addition & 1 deletion include/matx/generators/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace matx
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
if (((pp_get<0>(indices...) == indices) && ...)) {
return T(val_);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/generators/generator1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace matx
matxGenerator1D_t(S &&s, Generator1D f) : f_(f), s_(std::forward<S>(s)) {}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
return f_(pp_get<Dim>(indices...));
}

Expand Down
2 changes: 1 addition & 1 deletion include/matx/generators/meshgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {

std::array<index_t, Rank()> inds{indices...};
// get index for the axis
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace detail {
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
return tmp_out_(indices...);
};

Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/ambgfun.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace detail {
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
return tmp_out_(indices...);
};

Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/argmax.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace detail {
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const {
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/argmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace detail {
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const {
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/at.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace matx
__MATX_INLINE__ AtOp(Op op, Is... is) : op_(op), idx_{is...} {};

template <typename... Is2>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()([[maybe_unused]] Is2... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()([[maybe_unused]] Is2... indices) const
{
return mapply(op_, idx_);
}
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/binary_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ namespace matx
}

template <typename... Is, std::enable_if_t<std::conjunction_v<std::is_integral<Is>...>, bool> = true>
__MATX_DEVICE__ __MATX_HOST__ __MATX_INLINE__ auto operator()(Is... indices) const
__MATX_DEVICE__ __MATX_HOST__ __MATX_INLINE__ decltype(auto) operator()(Is... indices) const
{
auto i1 = get_value(in1_, indices...);
auto i2 = get_value(in2_, indices...);
return op_(i1, i2);
}

template <typename ArrayType, std::enable_if_t<is_std_array_v<ArrayType>, bool> = true>
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ const auto operator()(const ArrayType &idx) const noexcept
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ decltype(auto) operator()(const ArrayType &idx) const noexcept
{
return mapply([&](auto &&...args) {
return this->operator()(args...);
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/cart2sph.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
auto x = get_value(x_, indices...);
auto y = get_value(y_, indices...);
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ namespace matx
__MATX_INLINE__ CastOp(T op) : op_(op){};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return static_cast<NewType>(op_(indices...));
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto& operator()(Is... indices)
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices)
{
return static_cast<NewType>(op_(indices...));
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/cgsolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/channelize_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace detail {
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) {
return tmp_out_(indices...);
}

Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/chol.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace detail {

// This should never be called
template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const {
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace matx
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{

// convert variadic type to tuple so we can read/update
Expand All @@ -93,7 +93,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto& operator()(Is... indices)
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices)
{

// convert variadic type to tuple so we can read/update
Expand Down
8 changes: 4 additions & 4 deletions include/matx/operators/collapse.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
// indices coming in
std::array<index_t, Rank()> in{indices...}; // index coming in
Expand All @@ -95,7 +95,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto& operator()(Is... indices)
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices)
{
// indices coming in
std::array<index_t, Rank()> in{indices...}; // index coming in
Expand Down Expand Up @@ -219,7 +219,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
// indices coming in
std::array<index_t, Rank()> in{indices...}; // index coming in
Expand All @@ -244,7 +244,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto& operator()(Is... indices)
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices)
{
// indices coming in
std::array<index_t, Rank()> in{indices...}; // index coming in
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/concat.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... is) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... is) const
{
std::array<index_t, sizeof...(Is)> indices = {{is...}};
return GetVal<0, sizeof...(Ts)>(indices);
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto& operator()(Is... is)
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... is)
{
std::array<index_t, sizeof...(Is)> indices = {{is...}};
return GetVal<0, sizeof...(Ts)>(indices);
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/constval.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace matx
ConstVal(ShapeType &&s, T val) : s_(std::forward<ShapeType>(s)), v_(val){};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is...) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is...) const {
return v_; };

constexpr inline __MATX_HOST__ __MATX_DEVICE__ auto Size(int dim) const
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ namespace detail {
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/corr.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/cov.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/cumsum.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace detail {
};

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
return tmp_out_(indices...);
};

Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/det.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace detail {

// This should never be called
template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const{
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace matx
__MATX_INLINE__ DiagOp(T1 op) : op_(op) {}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
static_assert(sizeof...(Is) == RANK - 1, "Diagonal operator must have one fewer index than rank of operator");
static_assert(RANK > 1, "Cannot make get diagonals from 0D tensor");
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/eig.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace detail {

// This should never be called
template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const {
Expand Down
2 changes: 1 addition & 1 deletion include/matx/operators/einsum.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace detail {

// This should never be called
template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const = delete;
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const = delete;

template <typename Out, typename Executor>
void Exec(Out &&out, Executor &&ex) const {
Expand Down
4 changes: 2 additions & 2 deletions include/matx/operators/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const
{
return tmp_out_(indices...);
}
Expand Down Expand Up @@ -336,7 +336,7 @@ namespace matx
}

template <typename... Is>
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ auto operator()(Is... indices) const {
__MATX_INLINE__ __MATX_DEVICE__ __MATX_HOST__ decltype(auto) operator()(Is... indices) const {
return tmp_out_(indices...);
}

Expand Down
Loading

0 comments on commit 98f3231

Please sign in to comment.