Skip to content

Commit b9cebc7

Browse files
authored
Add print function with nonzero dim args (#844)
* Add print overload with non-zero dimension args Add a new matx::print() implementation that accepts one or more arguments to specify the number of elements to print in the given dimension. * Document behavior of a dimension being set to 0 in print() * Change unit test to generic TypeType type
1 parent 7434f4c commit b9cebc7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

include/matx/core/print.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,21 @@ namespace matx {
736736
cuda::std::apply([&](auto &&...args) { fprint(stdout, op, args...); }, tp);
737737
}
738738

739+
/**
740+
* @brief Print all of a tensor's values to stdout
741+
*
742+
* This form of `print()` is a specialization for 1D+ tensors. A size of zero in
743+
* dimension prints all elements in that dimension.
744+
*
745+
* @tparam Op Operator input type
746+
* @param op Operator input
747+
*/
748+
template <typename Op, typename... Args,
749+
std::enable_if_t<(Op::Rank() > 0 && sizeof...(Args) > 0), bool> = true>
750+
void print(const Op &op, [[maybe_unused]] Args... dims) {
751+
fprint(stdout, op, dims...);
752+
}
753+
739754
/**
740755
* @brief Print a tensor's all values to stdout
741756
*

test/00_operators/OperatorTests.cu

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,9 +4745,12 @@ TYPED_TEST(OperatorTestsFloatAllExecs, Print)
47454745
MATX_ENTER_HANDLER();
47464746
using TestType = cuda::std::tuple_element_t<0, TypeParam>;
47474747

4748-
auto t = make_tensor<TestType>({3});
4749-
auto r = ones<TestType>(t.Shape());
4748+
auto t1 = make_tensor<TestType>({3});
4749+
auto r1 = ones<TestType>(t1.Shape());
4750+
print(r1);
4751+
4752+
auto t3 = matx::make_tensor<TestType>({3, 2, 20});
4753+
print(matx::ones(t3.Shape()), 1, 0, 2);
47504754

4751-
print(r);
47524755
MATX_EXIT_HANDLER();
47534756
}

0 commit comments

Comments
 (0)