Skip to content

Improve clone docs #942

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

Merged
merged 1 commit into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions docs_input/api/manipulation/joinrepeat/clone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ Examples
:end-before: example-end clone-test-1
:dedent:

.. literalinclude:: ../../../../test/00_operators/clone_test.cu
:language: cpp
:start-after: example-begin clone-test-2
:end-before: example-end clone-test-2
:dedent:
4 changes: 2 additions & 2 deletions include/matx/operators/clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ MATX_IGNORE_WARNING_POP_GCC


/**
* @brief Operator to clone an operator or tensor acorss dimensions
* @brief Operator to clone an operator or tensor across dimensions
*
* @tparam Rank the rank of the cloned operator
* @tparam T source operator/tensor type
* @param t source operator/tensor
* @param shape the shape of the cloned operator/tensor.
* Each element is either the size of the cloned dimension or matxKeepDim to be from the source tensor
* Each element is either the size of the cloned dimension or `matxKeepDim` to be from the source tensor
* @return operator to compute the cloned value
*/
template <std::size_t Rank, typename Op>
Expand Down
6 changes: 5 additions & 1 deletion test/00_operators/clone_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TYPED_TEST(OperatorTestsNumericAllExecs, CloneOp)

tiv() = 3;

// Clone "tiv" from a 1D tensor to a 3D tensor
// Clone "tiv" from a 0D tensor to a 3D tensor
auto op = clone<3>(tiv, {N, M, K});
// example-end clone-test-1

Expand Down Expand Up @@ -54,14 +54,18 @@ TYPED_TEST(OperatorTestsNumericAllExecs, CloneOp)
}

{ // clone from 1D
// example-begin clone-test-2
auto tiv = make_tensor<TestType>({K});
auto tov = make_tensor<TestType>({N,M,K});

for(int k = 0; k < K; k++) {
tiv(k) = static_cast<typename inner_op_type_t<TestType>::type>(k);
}

// Clone "tiv" from a 1D tensor to a 3D tensor
// matxKeepDim is used to indicate where the 1D tensor should be placed in the 3D tensor
auto op = clone<3>(tiv, {N, M, matxKeepDim});
// example-end clone-test-2

ASSERT_EQ(op.Size(0), N);
ASSERT_EQ(op.Size(1), M);
Expand Down