Skip to content

Commit 0d442b1

Browse files
authored
optimize our iterator to avoid an unecessary constructor call (#741)
1 parent 90f7bd6 commit 0d442b1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

include/matx/core/iterator.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ struct RandomOperatorIterator {
9898

9999
[[nodiscard]] __MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ value_type operator[](difference_type offset) const
100100
{
101-
return *self_type{t_, offset_ + offset};
101+
if constexpr (OperatorType::Rank() == 0) {
102+
return static_cast<value_type>(t_.operator()());
103+
}
104+
else {
105+
auto arrs = detail::GetIdxFromAbs(t_, offset_+offset);
106+
return cuda::std::apply([&](auto &&...args) {
107+
return static_cast<value_type>(t_.operator()(args...));
108+
}, arrs);
109+
}
102110
}
103111

104112
__MATX_INLINE__ __MATX_HOST__ __MATX_DEVICE__ self_type operator++(int)

0 commit comments

Comments
 (0)