From 1796b6475aa264608ea8d85eb7b2a78656b56a4c Mon Sep 17 00:00:00 2001 From: cliffburdick Date: Fri, 7 Feb 2025 16:01:36 -0800 Subject: [PATCH 1/2] Refactored OperatorTests.cu for faster compilation time --- test/00_operators/CMakeLists.txt | 54 + test/00_operators/OperatorTests.cu | 4756 ----------------- test/00_operators/abs2_test.cu | 68 + test/00_operators/advanced_op_test.cu | 142 + test/00_operators/advanced_remap_test.cu | 155 + test/00_operators/angle_test.cu | 32 + test/00_operators/at_test.cu | 52 + test/00_operators/base_op_test.cu | 33 + test/00_operators/broadcast_test.cu | 75 + test/00_operators/cast_test.cu | 73 + test/00_operators/clone_add_test.cu | 69 + test/00_operators/clone_test.cu | 230 + test/00_operators/collapse_test.cu | 176 + .../complex_cast_exceptions_test.cu | 44 + test/00_operators/complex_cast_test.cu | 83 + .../complex_type_compatibility_test.cu | 111 + test/00_operators/concat_test.cu | 144 + test/00_operators/cross_test.cu | 68 + test/00_operators/fftshift_test.cu | 112 + test/00_operators/flatten_test.cu | 37 + test/00_operators/fmod_test.cu | 30 + test/00_operators/frexp_test.cu | 48 + test/00_operators/frexpc_test.cu | 59 + test/00_operators/get_string_test.cu | 32 + test/00_operators/interleaved_test.cu | 44 + test/00_operators/isclose_test.cu | 54 + test/00_operators/isnaninf_test.cu | 59 + test/00_operators/legendre_test.cu | 142 + test/00_operators/operator_func_test.cu | 431 ++ test/00_operators/operator_test_types.hpp | 103 + test/00_operators/overlap_test.cu | 87 + test/00_operators/permute_test.cu | 51 + test/00_operators/planar_test.cu | 39 + test/00_operators/polyval_test.cu | 34 + test/00_operators/print_test.cu | 22 + test/00_operators/r2c_test.cu | 99 + test/00_operators/real_imag_test.cu | 34 + test/00_operators/remap_rank_zero_test.cu | 79 + test/00_operators/remap_test.cu | 357 ++ test/00_operators/repmat_test.cu | 63 + test/00_operators/reshape_test.cu | 154 + test/00_operators/reverse_test.cu | 97 + test/00_operators/shift_test.cu | 164 + .../simple_executor_accessor_test.cu | 77 + test/00_operators/slice_and_reduce_test.cu | 99 + test/00_operators/slice_and_reshape_test.cu | 35 + test/00_operators/slice_stride_test.cu | 36 + test/00_operators/slice_test.cu | 99 + test/00_operators/sph2cart_test.cu | 37 + .../square_copy_transpose_test.cu | 85 + test/00_operators/stack_test.cu | 50 + test/00_operators/toeplitz_test.cu | 47 + test/00_operators/transpose_test.cu | 131 + test/00_operators/trig_funcs_test.cu | 95 + test/00_operators/updownsample_test.cu | 84 + test/CMakeLists.txt | 5 +- 56 files changed, 4919 insertions(+), 4757 deletions(-) create mode 100644 test/00_operators/CMakeLists.txt delete mode 100644 test/00_operators/OperatorTests.cu create mode 100644 test/00_operators/abs2_test.cu create mode 100644 test/00_operators/advanced_op_test.cu create mode 100644 test/00_operators/advanced_remap_test.cu create mode 100644 test/00_operators/angle_test.cu create mode 100644 test/00_operators/at_test.cu create mode 100644 test/00_operators/base_op_test.cu create mode 100644 test/00_operators/broadcast_test.cu create mode 100644 test/00_operators/cast_test.cu create mode 100644 test/00_operators/clone_add_test.cu create mode 100644 test/00_operators/clone_test.cu create mode 100644 test/00_operators/collapse_test.cu create mode 100644 test/00_operators/complex_cast_exceptions_test.cu create mode 100644 test/00_operators/complex_cast_test.cu create mode 100644 test/00_operators/complex_type_compatibility_test.cu create mode 100644 test/00_operators/concat_test.cu create mode 100644 test/00_operators/cross_test.cu create mode 100644 test/00_operators/fftshift_test.cu create mode 100644 test/00_operators/flatten_test.cu create mode 100644 test/00_operators/fmod_test.cu create mode 100644 test/00_operators/frexp_test.cu create mode 100644 test/00_operators/frexpc_test.cu create mode 100644 test/00_operators/get_string_test.cu create mode 100644 test/00_operators/interleaved_test.cu create mode 100644 test/00_operators/isclose_test.cu create mode 100644 test/00_operators/isnaninf_test.cu create mode 100644 test/00_operators/legendre_test.cu create mode 100644 test/00_operators/operator_func_test.cu create mode 100644 test/00_operators/operator_test_types.hpp create mode 100644 test/00_operators/overlap_test.cu create mode 100644 test/00_operators/permute_test.cu create mode 100644 test/00_operators/planar_test.cu create mode 100644 test/00_operators/polyval_test.cu create mode 100644 test/00_operators/print_test.cu create mode 100644 test/00_operators/r2c_test.cu create mode 100644 test/00_operators/real_imag_test.cu create mode 100644 test/00_operators/remap_rank_zero_test.cu create mode 100644 test/00_operators/remap_test.cu create mode 100644 test/00_operators/repmat_test.cu create mode 100644 test/00_operators/reshape_test.cu create mode 100644 test/00_operators/reverse_test.cu create mode 100644 test/00_operators/shift_test.cu create mode 100644 test/00_operators/simple_executor_accessor_test.cu create mode 100644 test/00_operators/slice_and_reduce_test.cu create mode 100644 test/00_operators/slice_and_reshape_test.cu create mode 100644 test/00_operators/slice_stride_test.cu create mode 100644 test/00_operators/slice_test.cu create mode 100644 test/00_operators/sph2cart_test.cu create mode 100644 test/00_operators/square_copy_transpose_test.cu create mode 100644 test/00_operators/stack_test.cu create mode 100644 test/00_operators/toeplitz_test.cu create mode 100644 test/00_operators/transpose_test.cu create mode 100644 test/00_operators/trig_funcs_test.cu create mode 100644 test/00_operators/updownsample_test.cu diff --git a/test/00_operators/CMakeLists.txt b/test/00_operators/CMakeLists.txt new file mode 100644 index 00000000..23c350f9 --- /dev/null +++ b/test/00_operators/CMakeLists.txt @@ -0,0 +1,54 @@ +set(OPERATOR_TEST_FILES + abs2_test.cu + advanced_op_test.cu + advanced_remap_test.cu + angle_test.cu + at_test.cu + base_op_test.cu + broadcast_test.cu + cast_test.cu + clone_add_test.cu + clone_test.cu + collapse_test.cu + complex_cast_exceptions_test.cu + complex_cast_test.cu + complex_type_compatibility_test.cu + concat_test.cu + cross_test.cu + fftshift_test.cu + flatten_test.cu + fmod_test.cu + frexp_test.cu + frexpc_test.cu + get_string_test.cu + interleaved_test.cu + isclose_test.cu + isnaninf_test.cu + legendre_test.cu + operator_func_test.cu + overlap_test.cu + permute_test.cu + planar_test.cu + polyval_test.cu + print_test.cu + r2c_test.cu + real_imag_test.cu + remap_rank_zero_test.cu + remap_test.cu + repmat_test.cu + reshape_test.cu + reverse_test.cu + shift_test.cu + simple_executor_accessor_test.cu + slice_and_reduce_test.cu + slice_and_reshape_test.cu + slice_stride_test.cu + slice_test.cu + sph2cart_test.cu + square_copy_transpose_test.cu + stack_test.cu + toeplitz_test.cu + transpose_test.cu + trig_funcs_test.cu + updownsample_test.cu +) \ No newline at end of file diff --git a/test/00_operators/OperatorTests.cu b/test/00_operators/OperatorTests.cu deleted file mode 100644 index 77c77501..00000000 --- a/test/00_operators/OperatorTests.cu +++ /dev/null @@ -1,4756 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// BSD 3-Clause License -// -// Copyright (c) 2021, NVIDIA Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -///////////////////////////////////////////////////////////////////////////////// - -#include "assert.h" -#include "matx.h" -#include "matx/transforms/transpose.h" -#include "test_types.h" -#include "utilities.h" -#include "gtest/gtest.h" -#include -#include - -using namespace matx; - -template -class OperatorTestsComplex : public ::testing::Test { -}; -template -class OperatorTestsFloat : public ::testing::Test { -}; -template -class OperatorTestsNumeric : public ::testing::Test { -}; -template -class OperatorTestsNumericNonComplex : public ::testing::Test { -}; -template -class OperatorTestsFloatNonComplex : public ::testing::Test { -}; -template -class OperatorTestsFloatNonHalf : public ::testing::Test { -}; -template -class OperatorTestsFloatNonComplexNonHalf : public ::testing::Test { -}; -template -class OperatorTestsIntegral : public ::testing::Test { -}; -template -class OperatorTestsBoolean : public ::testing::Test { -}; -template -class OperatorTestsFloatHalf : public ::testing::Test { -}; -template -class OperatorTestsNumericNoHalf : public ::testing::Test { -}; -template -class OperatorTestsAll : public ::testing::Test { -}; - -template -class OperatorTestsNumericNonComplexAllExecs : public ::testing::Test { -}; -template -class OperatorTestsFloatNonComplexNonHalfAllExecs : public ::testing::Test { -}; -template -class OperatorTestsNumericNoHalfAllExecs : public ::testing::Test { -}; -template -class OperatorTestsComplexNonHalfTypesAllExecs : public ::testing::Test { -}; -template -class OperatorTestsComplexTypesAllExecs : public ::testing::Test { -}; -template -class OperatorTestsAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsFloatAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsFloatNonComplexAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsNumericAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsIntegralAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsBooleanAllExecs : public ::testing::Test { -}; - -template -class OperatorTestsCastToFloatAllExecs : public ::testing::Test { -}; - -TYPED_TEST_SUITE(OperatorTestsFloatNonHalf, - MatXFloatNonHalfTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsNumericNonComplexAllExecs, - MatXNumericNonComplexTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsFloatNonComplexNonHalfAllExecs, - MatXFloatNonComplexNonHalfTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsFloatNonComplexAllExecs, - MatXTypesFloatNonComplexAllExecs); -TYPED_TEST_SUITE(OperatorTestsNumericAllExecs, - MatXTypesNumericAllExecs); -TYPED_TEST_SUITE(OperatorTestsNumericNoHalfAllExecs, MatXNumericNoHalfTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsComplexNonHalfTypesAllExecs, MatXComplexNonHalfTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsComplexTypesAllExecs, MatXComplexTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsAllExecs, MatXAllTypesAllExecs); -TYPED_TEST_SUITE(OperatorTestsFloatAllExecs, MatXTypesFloatAllExecs); -TYPED_TEST_SUITE(OperatorTestsIntegralAllExecs, MatXTypesIntegralAllExecs); -TYPED_TEST_SUITE(OperatorTestsBooleanAllExecs, MatXTypesBooleanAllExecs); -TYPED_TEST_SUITE(OperatorTestsCastToFloatAllExecs, MatXTypesCastToFloatAllExecs); - -TYPED_TEST(OperatorTestsAllExecs, BaseOp) -{ - MATX_ENTER_HANDLER(); - - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto A = make_tensor({10,20}); - auto op = A + A; - - EXPECT_TRUE(op.Size(0) == A.Size(0)); - EXPECT_TRUE(op.Size(1) == A.Size(1)); - - auto shape = op.Shape(); - - EXPECT_TRUE(shape[0] == A.Size(0)); - EXPECT_TRUE(shape[1] == A.Size(1)); - - EXPECT_TRUE(A.TotalSize() == op.TotalSize()); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, GetString) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto A = make_tensor({10,20}); - auto B = make_tensor({20}); - auto C = make_tensor({10,20}); - - auto op1 = C = A; - auto op2 = C = A + B + (TestType)5; - auto op3 = C = A / B; - auto op4 = (op1,op2,op3); - - std::cout << "op1: " << op1.str() << std::endl; - std::cout << "op2: " << op2.str() << std::endl; - std::cout << "op3: " << op3.str() << std::endl; - std::cout << "op4: " << op4.str() << std::endl; - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, SimpleExecutorAccessorTests) -{ - MATX_ENTER_HANDLER(); - - using TestType = std::tuple_element_t<0, TypeParam>; - using ExecType = std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - const int N = 3; - - auto t0 = make_tensor({}); - auto t1 = make_tensor({N}); - auto t2 = make_tensor({N,N}); - auto t3 = make_tensor({N,N,N}); - auto t4 = make_tensor({N,N,N,N}); - auto t5 = make_tensor({N,N,N,N,N}); - auto t6 = make_tensor({N,N,N,N,N,N}); - - // Simple executor accessor tests for tensors of increasing dimensions. - // These tests verify that we can read from and write to all elements of - // a tensor, which in turn tests the multi-dimensional indexing logic. - // These tests do not assign unique values to each unique index, so they - // are not exhaustive tests. For the CUDA executor, the 5D and higher-rank - // tensors will use matxOpTDKernel whereas the smaller tensors each have - // custom implementations. - const TestType init = TestType(5); - const TestType expected = TestType(7); - (t0 = init).run(exec); - (t1 = init).run(exec); - (t2 = init).run(exec); - (t3 = init).run(exec); - (t4 = init).run(exec); - (t5 = init).run(exec); - (t6 = init).run(exec); - - // We use IF to generate both a read and a write for each tensor index. - IF(t0 == init, t0 = expected).run(exec); - IF(t1 == init, t1 = expected).run(exec); - IF(t2 == init, t2 = expected).run(exec); - IF(t3 == init, t3 = expected).run(exec); - IF(t4 == init, t4 = expected).run(exec); - IF(t5 == init, t5 = expected).run(exec); - IF(t6 == init, t6 = expected).run(exec); - - cudaStreamSynchronize(0); - - ASSERT_EQ(t0(), expected); - for (int i0 = 0; i0 < N; i0++) { - ASSERT_EQ(t1(i0), expected); - for (int i1 = 0; i1 < N; i1++) { - ASSERT_EQ(t2(i0,i1), expected); - for (int i2 = 0; i2 < N; i2++) { - ASSERT_EQ(t3(i0,i1,i2), expected); - for (int i3 = 0; i3 < N; i3++) { - ASSERT_EQ(t4(i0,i1,i2,i3), expected); - for (int i4 = 0; i4 < N; i4++) { - ASSERT_EQ(t5(i0,i1,i2,i3,i4), expected); - for (int i5 = 0; i5 < N; i5++) { - ASSERT_EQ(t6(i0,i1,i2,i3,i4,i5), expected); - } - } - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, PermuteOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto A = make_tensor({10,20,30}); - for(int i=0; i < A.Size(0); i++) { - for(int j=0; j < A.Size(1); j++) { - for(int k=0; k < A.Size(2); k++) { - A(i,j,k) = static_cast::type>( i * A.Size(1)*A.Size(2) + - j * A.Size(2) + k); - } - } - } - - // example-begin permute-test-1 - // Permute from dims {0, 1, 2} to {2, 0, 1} - auto op = permute(A, {2, 0, 1}); - // example-end permute-test-1 - auto At = A.Permute({2, 0, 1}); - - ASSERT_TRUE(op.Size(0) == A.Size(2)); - ASSERT_TRUE(op.Size(1) == A.Size(0)); - ASSERT_TRUE(op.Size(2) == A.Size(1)); - - ASSERT_TRUE(op.Size(0) == At.Size(0)); - ASSERT_TRUE(op.Size(1) == At.Size(1)); - ASSERT_TRUE(op.Size(2) == At.Size(2)); - - for(int i=0; i < op.Size(0); i++) { - for(int j=0; j < op.Size(1); j++) { - for(int k=0; k < op.Size(2); k++) { - ASSERT_TRUE( op(i,j,k) == A(j,k,i)); - ASSERT_TRUE( op(i,j,k) == At(i,j,k)); - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, ReshapeOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin reshape-test-1 - auto A = make_tensor({2*4*8*16}); - for(int i = 0; i < A.Size(0); i++) { - A(i) = static_cast::type>(i); - } - - // op is a 4D operator - auto op = reshape(A, {2, 4, 8, 16}); - - // op2 is a 1D operator - auto op2 = reshape(op, {2 * 4 * 8 * 16}); - // example-end reshape-test-1 - - ASSERT_TRUE(op.Rank() == 4); - ASSERT_TRUE(op2.Rank() == 1); - - ASSERT_TRUE(op.Size(0) == 2 ); - ASSERT_TRUE(op.Size(1) == 4 ); - ASSERT_TRUE(op.Size(2) == 8 ); - ASSERT_TRUE(op.Size(3) == 16 ); - - ASSERT_TRUE(op2.Size(0) == A.TotalSize() ); - - int idx = 0; - for(int i=0; i < op.Size(0); i++) { - for(int j=0; j < op.Size(1); j++) { - for(int k=0; k < op.Size(2); k++) { - for(int l=0; l < op.Size(3); l++) { - ASSERT_TRUE( A(idx) == op(i,j,k,l) ); - ASSERT_TRUE( A(idx) == op2(idx)); - idx++; - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatAllExecs, IsClose) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin isclose-test-1 - auto A = make_tensor({5, 5, 5}); - auto B = make_tensor({5, 5, 5}); - auto C = make_tensor({5, 5, 5}); - - (A = ones(A.Shape())).run(exec); - (B = ones(B.Shape())).run(exec); - (C = isclose(A, B)).run(exec); - // example-end isclose-test-1 - exec.sync(); - - for(int i=0; i < A.Size(0); i++) { - for(int j=0; j < A.Size(1); j++) { - for(int k=0; k < A.Size(2); k++) { - ASSERT_EQ(C(i,j,k), 1); - } - } - } - - B(1,1,1) = 2; - (C = isclose(A, B)).run(exec); - exec.sync(); - - for(int i=0; i < A.Size(0); i++) { - for(int j=0; j < A.Size(1); j++) { - for(int k=0; k < A.Size(2); k++) { - if (i == 1 && j == 1 && k == 1) { - ASSERT_EQ(C(i,j,k), 0); - } - else { - ASSERT_EQ(C(i,j,k), 1); - } - } - } - } - - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, Frexp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin frexp-test-1 - // Input data - auto tiv0 = make_tensor({10}); - - // Output fractional/integer parts - auto tofrac = make_tensor({10}); - auto toint = make_tensor({10}); - - (tiv0 = random(tiv0.Shape(), NORMAL)).run(exec); - // Create operators representing fractional and integer - const auto [ofrac, oint] = frexp(tiv0); - (tofrac = ofrac, toint = oint).run(exec); - // example-end frexp-test-1 - - exec.sync(); - - int texp; - for (int i = 0; i < tiv0.Size(0); i++) { - if constexpr (std::is_same_v) { - float tfrac = cuda::std::frexpf(tiv0(i), &texp); - ASSERT_EQ(tfrac, tofrac(i)); - ASSERT_EQ(texp, toint(i)); - } - else { - double tfrac = cuda::std::frexp(tiv0(i), &texp); - ASSERT_EQ(tfrac, tofrac(i)); - ASSERT_EQ(texp, toint(i)); - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexNonHalfTypesAllExecs, Frexpc) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin frexpc-test-1 - // Input data - auto tiv0 = make_tensor({10}); - - // Output fractional/integer parts - auto tofrac_real = make_tensor({10}); - auto tofrac_imag = make_tensor({10}); - auto toint_real = make_tensor({10}); - auto toint_imag = make_tensor({10}); - - // Create operators representing fractional and integer - (tiv0 = random(tiv0.Shape(), NORMAL)).run(exec); - const auto [ofrac_real, oint_real, ofrac_imag, oint_imag] = frexpc(tiv0); - - ( tofrac_real = ofrac_real, - toint_real = oint_real, - tofrac_imag = ofrac_imag, - toint_imag = oint_imag).run(exec); - // example-end frexpc-test-1 - - exec.sync(); - int texp_real, texp_imag; - for (int i = 0; i < tiv0.Size(0); i++) { - if constexpr (std::is_same_v>) { - float tfrac_real = cuda::std::frexpf(tiv0(i).real(), &texp_real); - float tfrac_imag = cuda::std::frexpf(tiv0(i).imag(), &texp_imag); - ASSERT_EQ(tfrac_real, tofrac_real(i)); - ASSERT_EQ(texp_real, toint_real(i)); - ASSERT_EQ(tfrac_imag, tofrac_imag(i)); - ASSERT_EQ(texp_imag, toint_imag(i)); - } - else { - double tfrac_real = cuda::std::frexp(tiv0(i).real(), &texp_real); - double tfrac_imag = cuda::std::frexp(tiv0(i).imag(), &texp_imag); - ASSERT_EQ(tfrac_real, tofrac_real(i)); - ASSERT_EQ(texp_real, toint_real(i)); - ASSERT_EQ(tfrac_imag, tofrac_imag(i)); - ASSERT_EQ(texp_imag, toint_imag(i)); - } - } - - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, FMod) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin fmod-test-1 - auto tiv0 = make_tensor({}); - auto tiv1 = make_tensor({}); - auto tov0 = make_tensor({}); - - tiv0() = (TestType)5.0; - tiv1() = (TestType)3.1; - (tov0 = fmod(tiv0, tiv1)).run(exec); - // example-end fmod-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_fmod((TestType)5.0, (TestType)3.1))); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, TrigFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - // example-begin sin-test-1 - (tov0 = sin(tiv0)).run(exec); - // example-end sin-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sin(c))); - - // example-begin cos-test-1 - (tov0 = cos(tiv0)).run(exec); - // example-end cos-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_cos(c))); - - // example-begin tan-test-1 - (tov0 = tan(tiv0)).run(exec); - // example-end tan-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_tan(c))); - - // example-begin asin-test-1 - (tov0 = asin(tiv0)).run(exec); - // example-end asin-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_asin(c))); - - // example-begin acos-test-1 - (tov0 = acos(tiv0)).run(exec); - // example-end acos-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_acos(c))); - - // example-begin atan-test-1 - (tov0 = atan(tiv0)).run(exec); - // example-end atan-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_atan(c))); - - // example-begin sinh-test-1 - (tov0 = sinh(tiv0)).run(exec); - // example-end sinh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sinh(c))); - - // example-begin cosh-test-1 - (tov0 = cosh(tiv0)).run(exec); - // example-end cosh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_cosh(c))); - - // example-begin tanh-test-1 - (tov0 = tanh(tiv0)).run(exec); - // example-end tanh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_tanh(c))); - - // example-begin asinh-test-1 - (tov0 = asinh(tiv0)).run(exec); - // example-end asinh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_asinh(c))); - - // example-begin acosh-test-1 - (tov0 = acosh(tiv0)).run(exec); - // example-end acosh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_acosh(c))); - - // example-begin atanh-test-1 - (tov0 = atanh(tiv0)).run(exec); - // example-end atanh-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_atanh(c))); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, AngleOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - - // example-begin angle-test-1 - (tov0 = angle(tiv0)).run(exec); - // example-end angle-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_angle(c))); - - MATX_EXIT_HANDLER(); -} -TYPED_TEST(OperatorTestsNumericAllExecs, CloneOp) -{ - constexpr int N = 10; - constexpr int M = 12; - constexpr int K = 14; - - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - MATX_ENTER_HANDLER(); - { // clone from 0D - // example-begin clone-test-1 - auto tiv = make_tensor({}); - auto tov = make_tensor({N,M,K}); - - tiv() = 3; - - // Clone "tiv" from a 1D tensor to a 3D tensor - auto op = clone<3>(tiv, {N, M, K}); - // example-end clone-test-1 - - ASSERT_EQ(op.Size(0), N); - ASSERT_EQ(op.Size(1), M); - ASSERT_EQ(op.Size(2), K); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(op(n,m,k) , tiv()); - } - } - } - - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , tiv()); - } - } - } - } - - { // clone from 1D - auto tiv = make_tensor({K}); - auto tov = make_tensor({N,M,K}); - - for(int k = 0; k < K; k++) { - tiv(k) = static_cast::type>(k); - } - - auto op = clone<3>(tiv, {N, M, matxKeepDim}); - - ASSERT_EQ(op.Size(0), N); - ASSERT_EQ(op.Size(1), M); - ASSERT_EQ(op.Size(2), K); - - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(op(n,m,k) , tiv(k)); - } - } - } - - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , tiv(k)); - } - } - } - } - - { // clone from 1D - auto tiv = make_tensor({M}); - auto tov = make_tensor({N,M,K}); - - for(int m = 0; m < K; m++) { - tiv(m) = static_cast::type>(m); - } - - auto op = clone<3>(tiv, {N, matxKeepDim, K}); - - ASSERT_EQ(op.Size(0), N); - ASSERT_EQ(op.Size(1), M); - ASSERT_EQ(op.Size(2), K); - - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(op(n,m,k) , tiv(m)); - } - } - } - - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , tiv(m)); - } - } - } - } - - { // clone from 2D and operator - auto tiv = make_tensor({M,K}); - auto tov = make_tensor({N,M,K}); - - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); - } - } - - auto op = clone<3>(tiv, {N, matxKeepDim, matxKeepDim}); - - ASSERT_EQ(op.Size(0), N); - ASSERT_EQ(op.Size(1), M); - ASSERT_EQ(op.Size(2), K); - - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(op(n,m,k) , tiv(m,k)); - } - } - } - - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , tiv(m,k)); - } - } - } - } - - { // clone from 2D - auto tiv = make_tensor({M,K}); - auto tov = make_tensor({N,M,K}); - - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); - } - } - - const auto op = clone<3>(static_cast::type>(2)*tiv, {N, matxKeepDim, matxKeepDim}); - - ASSERT_EQ(op.Size(0), N); - ASSERT_EQ(op.Size(1), M); - ASSERT_EQ(op.Size(2), K); - - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(op(n,m,k), TestType(2)*tiv(m,k)); - } - } - } - - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , TestType(2)*tiv(m,k)); - } - } - } - } - - if constexpr (is_cuda_executor_v) - { // clone of a nested transform; conv2d currently only has a device executor - auto tiv = make_tensor({M,K}); - auto tov = make_tensor({N,M,K}); - auto delta = make_tensor({1,1}); - - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); - } - } - - delta(0,0) = static_cast::type>(1.0); - - exec.sync(); - - (tov = clone<3>(conv2d(tiv, delta, MATX_C_MODE_SAME), {N, matxKeepDim, matxKeepDim})).run(exec); - - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_EQ(tov(n,m,k) , tiv(m,k)); - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, AtOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto t2 = make_tensor({2,10}); - - // example-begin at-test-1 - auto t1 = make_tensor({10}); - auto t0 = make_tensor({}); - - t1.SetVals({10, 20, 30, 40, 50, 60, 70, 80, 90, 100}); - (t2 = t1).run(exec); - - // Select the fourth element from `t1` as part of the execution. Value should match - // `t1(3)` after execution - (t0 = at(t1, 3)).run(exec); - // example-end at-test-1 - exec.sync(); - - ASSERT_EQ(t0(), t1(3)); - - (t0 = at(t2, 1, 4)).run(exec); - exec.sync(); - - ASSERT_EQ(t0(), t2(1, 4)); - - if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) { - using ComplexType = detail::complex_from_scalar_t; - auto c0 = make_tensor({}); - (c0 = at(fft(t1), 0)).run(exec); - exec.sync(); - - // The first component of the FFT output (DC) is the sum of all elements, so - // 10+20+...+100 = 550. The imaginary component should be 0. - ASSERT_NEAR(c0().real(), static_cast(550.0), static_cast(1.0e-6)); - ASSERT_NEAR(c0().imag(), static_cast(0.0), static_cast(1.0e-6)); - } - - MATX_EXIT_HANDLER(); -} - - - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, SliceStrideOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - // example-begin slice-test-2 - auto t1 = make_tensor({10}); - - t1.SetVals({10, 20, 30, 40, 50, 60, 70, 80, 90, 100}); - - // Slice every other element from a 1D tensor (stride of two) - auto t1t = slice(t1, {0}, {matxEnd}, {2}); - // example-end slice-test-2 - - for (index_t i = 0; i < t1.Size(0); i += 2) { - ASSERT_EQ(t1(i), t1t(i / 2)); - } - - auto t1t2 = slice(t1, {2}, {matxEnd}, {2}); - - for (index_t i = 0; i < t1t2.Size(0); i++) { - ASSERT_EQ(TestType(30 + 20 * i), t1t2(i)); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, SliceOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - using inner_type = typename inner_op_type_t::type; - - ExecType exec{}; - - // example-begin slice-test-1 - auto t2 = make_tensor({20, 10}); - auto t3 = make_tensor({30, 20, 10}); - auto t4 = make_tensor({40, 30, 20, 10}); - - (t2 = linspace<1>(t2.Shape(), (inner_type)0, (inner_type)10)).run(exec); - (t3 = linspace<2>(t3.Shape(), (inner_type)0, (inner_type)10)).run(exec); - (t4 = linspace<3>(t4.Shape(), (inner_type)0, (inner_type)10)).run(exec); - exec.sync(); - - // Slice with different start and end points in each dimension - auto t2t = slice(t2, {1, 2}, {3, 5}); - auto t3t = slice(t3, {1, 2, 3}, {3, 5, 7}); - auto t4t = slice(t4, {1, 2, 3, 4}, {3, 5, 7, 9}); - // example-end slice-test-1 - - ASSERT_EQ(t2t.Size(0), 2); - ASSERT_EQ(t2t.Size(1), 3); - - ASSERT_EQ(t3t.Size(0), 2); - ASSERT_EQ(t3t.Size(1), 3); - ASSERT_EQ(t3t.Size(2), 4); - - ASSERT_EQ(t4t.Size(0), 2); - ASSERT_EQ(t4t.Size(1), 3); - ASSERT_EQ(t4t.Size(2), 4); - ASSERT_EQ(t4t.Size(3), 5); - - for (index_t i = 0; i < t2t.Size(0); i++) { - for (index_t j = 0; j < t2t.Size(1); j++) { - ASSERT_EQ(t2t(i, j), t2(i + 1, j + 2)); - } - } - - for (index_t i = 0; i < t3t.Size(0); i++) { - for (index_t j = 0; j < t3t.Size(1); j++) { - for (index_t k = 0; k < t3t.Size(2); k++) { - ASSERT_EQ(t3t(i, j, k), t3(i + 1, j + 2, k + 3)); - } - } - } - - for (index_t i = 0; i < t4t.Size(0); i++) { - for (index_t j = 0; j < t4t.Size(1); j++) { - for (index_t k = 0; k < t4t.Size(2); k++) { - for (index_t l = 0; l < t4t.Size(3); l++) { - ASSERT_EQ(t4t(i, j, k, l), t4(i + 1, j + 2, k + 3, l + 4)); - } - } - } - } - - // Test SliceOp applied to a transform, using transpose() as an example transform - auto t2trans = make_tensor({3, 2}); - (t2trans = slice(transpose(t2), {2, 1}, {5, 3})).run(exec); - exec.sync(); - - ASSERT_EQ(t2trans.Size(0), 3); - ASSERT_EQ(t2trans.Size(1), 2); - for (index_t i = 0; i < t2trans.Size(0); i++) { - for (index_t j = 0; j < t2trans.Size(1); j++) { - ASSERT_EQ(t2trans(i, j), t2(j + 1, i + 2)); - } - } - - // Negative indexing. These should give the same results - // example-begin slice-test-4 - auto t2sn = slice(t2, {-4, -5}, {matxEnd, matxEnd}); - auto t2s = slice(t2, {t2.Size(0) - 4, t2.Size(1) - 5}, {matxEnd, matxEnd}); - - // example-end slice-test-4 - exec.sync(); - ASSERT_EQ(t2sn.Size(0), t2s.Size(0)); - ASSERT_EQ(t2sn.Size(1), t2s.Size(1)); - for (index_t i = 0; i < t2sn.Size(0); i++) { - for (index_t j = 0; j < t2sn.Size(1); j++) { - ASSERT_EQ(t2sn(i, j), t2s(i, j)); - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, SliceAndReshape) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - { - // Unit test combining slice with reshape which showed a bug in the past - auto t = make_tensor({100}); - (t = linspace<0>(t.Shape(), (TestType)0, (TestType)99)).run(exec); - auto rs = reshape(t, {2, 10, 5}); - auto s = slice(rs, {0, 0, 2}, {matxEnd, matxEnd, matxEnd}); - exec.sync(); - - for (index_t i = 0; i < s.Size(0); i++) { - for (index_t j = 0; j < s.Size(1); j++) { - for (index_t k = 0; k < s.Size(2); k++) { - ASSERT_EQ(t(i*50 + j*5 + k+2), s(i,j,k)); - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, SliceAndReduceOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - using inner_type = typename inner_op_type_t::type; - ExecType exec{}; - - tensor_t t2t{{20, 10}}; - tensor_t t3t{{30, 20, 10}}; - (t2t = linspace<1>(t2t.Shape(), (inner_type)0, (inner_type)10)).run(exec); - (t3t = linspace<2>(t3t.Shape(), (inner_type)0, (inner_type)10)).run(exec); - exec.sync(); - - { - index_t j = 0; - // example-begin slice-test-3 - // Slice "t2t" by selecting column "j" from a 2D operator and converting to a 1D operator - auto t2sly = slice<1>(t2t, {0, j}, {matxEnd, matxDropDim}); - // example-end slice-test-3 - for (index_t i = 0; i < t2sly.Size(0); i++) { - ASSERT_EQ(t2sly(i), t2t(i, j)); - } - } - - { - index_t i = 0; - auto t2slx = slice<1>(t2t, {i, 0}, {matxDropDim, matxEnd}); - for (index_t j = 0; j < t2slx.Size(0); j++) { - ASSERT_EQ(t2slx(j), t2t(i, j)); - } - } - - { - index_t j = 0; - index_t k = 0; - auto t3slz = slice<1>(t3t, {0, j, k}, {matxEnd, matxDropDim, matxDropDim}); - for (index_t i = 0; i < t3slz.Size(0); i++) { - ASSERT_EQ(t3slz(i), t3t(i, j, k)); - } - } - - { - index_t i = 0; - index_t k = 0; - auto t3sly = slice<1>(t3t, {i, 0, k}, {matxDropDim, matxEnd, matxDropDim}); - for (index_t j = 0; j < t3sly.Size(0); j++) { - ASSERT_EQ(t3sly(j), t3t(i, j, k)); - } - } - - { - index_t i = 0; - index_t j = 0; - auto t3slx = slice<1>(t3t, {i, j, 0}, {matxDropDim, matxDropDim, matxEnd}); - for (index_t k = 0; k < t3slx.Size(0); k++) { - ASSERT_EQ(t3slx(k), t3t(i, j, k)); - } - } - - { - index_t k = 0; - auto t3slzy = slice<2>(t3t, {0, 0, k}, {matxEnd, matxEnd, matxDropDim}); - for (index_t i = 0; i < t3slzy.Size(0); i++) { - for (index_t j = 0; j < t3slzy.Size(1); j++) { - ASSERT_EQ(t3slzy(i, j), t3t(i, j, k)); - } - } - } - - { - index_t j = 0; - auto t3slzx = slice<2>(t3t, {0, j, 0}, {matxEnd, matxDropDim, matxEnd}); - for (index_t i = 0; i < t3slzx.Size(0); i++) { - for (index_t k = 0; k < t3slzx.Size(1); k++) { - ASSERT_EQ(t3slzx(i, k), t3t(i, j, k)); - } - } - } - - { - index_t i = 0; - auto t3slyx = slice<2>(t3t, {i, 0, 0}, {matxDropDim, matxEnd, matxEnd}); - for (index_t j = 0; j < t3slyx.Size(0); j++) { - for (index_t k = 0; k < t3slyx.Size(1); k++) { - ASSERT_EQ(t3slyx(j, k), t3t(i, j, k)); - } - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, CollapseOp) -{ - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - using inner_type = typename inner_op_type_t::type; - - ExecType exec{}; - - int N = 10; - int M = 12; - int K = 14; - - - MATX_ENTER_HANDLER(); - auto tiv = make_tensor({N,M,K}); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - tiv(n,m,k) = inner_type(n*M*K + m*K + k); - } - } - } - - { // rcollapse 2 - auto tov = make_tensor({N,M*K}); - - // example-begin rcollapse-test-1 - // Collapse two right-most dimensions together - auto op = rcollapse<2>(tiv); - // example-end rcollapse-test-1 - - EXPECT_TRUE(op.Rank() == 2); - EXPECT_TRUE(op.Size(0) == N); - EXPECT_TRUE(op.Size(1) == M*K); - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n,m*K+k)); - } - } - } - } - - { // lcollapse 12 - auto tov = make_tensor({N*M,K}); - - // example-begin lcollapse-test-1 - // Collapse two left-most dimensions together - auto op = lcollapse<2>(tiv); - // example-end lcollapse-test-1 - - EXPECT_TRUE(op.Rank() == 2); - EXPECT_TRUE(op.Size(0) == N*M); - EXPECT_TRUE(op.Size(1) == K); - - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n*M+m,k)); - } - } - } - } - - { // rcollapse 3 - auto tov = make_tensor({N*M*K}); - - auto op = rcollapse<3>(tiv); - - EXPECT_TRUE(op.Rank() == 1); - EXPECT_TRUE(op.Size(0) == N*M*K); - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n*M*K+m*K+k)); - } - } - } - } - - { // lcollapse 3 - auto tov = make_tensor({N*M*K}); - - auto op = lcollapse<3>(tiv); - - EXPECT_TRUE(op.Rank() == 1); - EXPECT_TRUE(op.Size(0) == N*M*K); - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n*M*K+m*K+k)); - } - } - } - } - - if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) - { // rcollapse with nested transform operator - auto tov = make_tensor({N,M*K}); - auto delta = make_tensor({1,1}); - delta(0,0) = static_cast::type>(1.0); - - auto op = rcollapse<2>(conv2d(tiv, delta, MATX_C_MODE_SAME)); - - EXPECT_TRUE(op.Rank() == 2); - EXPECT_TRUE(op.Size(0) == N); - EXPECT_TRUE(op.Size(1) == M*K); - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n,m*K+k)); - } - } - } - } - - if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) - { // lcollapse with nested transform operator - auto tov = make_tensor({N*M,K}); - auto delta = make_tensor({1,1}); - delta(0,0) = static_cast::type>(1.0); - - auto op = lcollapse<2>(conv2d(tiv, delta, MATX_C_MODE_SAME)); - - EXPECT_TRUE(op.Rank() == 2); - EXPECT_TRUE(op.Size(0) == N*M); - EXPECT_TRUE(op.Size(1) == K); - - (tov = (TestType)0).run(exec); - (tov = op).run(exec); - exec.sync(); - - for(int n = 0; n < N; n++) { - for(int m = 0; m < M; m++) { - for(int k = 0; k < K; k++) { - ASSERT_TRUE(tiv(n,m,k) == tov(n*M+m,k)); - } - } - } - } - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsNumericAllExecs, RemapOp) -{ - int N = 10; - - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - using inner_type = typename inner_op_type_t::type; - - ExecType exec{}; - - auto tiv = make_tensor({N,N}); - - for(int i = 0; i < N; i++) { - for(int j = 0; j < N; j++) { - tiv(i,j) = inner_type(i*N+j); - } - } - - { // Identity Gather test - - // example-begin remap-test-1 - auto tov = make_tensor({N, N}); - auto idx = make_tensor({N}); - - for(int i = 0; i < N; i++) { - idx(i) = i; - } - - // Remap 2D operator "tiv" by selecting elements from dimension 0 stored in "idx" - (tov = remap<0>(tiv, idx)).run(exec); - // example-end remap-test-1 - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - - (tov = remap<1>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - - // example-begin remap-test-2 - // Remap 2D operator "tiv" by selecting elements from dimensions 0 and 1 stored in "idx" - (tov = remap<0,1>(tiv, idx, idx)).run(exec); - // example-end remap-test-2 - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - } - - { // Identity lvalue test - - auto tov = make_tensor({N, N}); - auto idx = make_tensor({N}); - - for(int i = 0; i < N; i++) { - idx(i) = i; - } - - (tov = (TestType)0).run(exec); - - (remap<0>(tov, idx) = tiv).run(exec); - - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - - (tov = (TestType)0).run(exec); - (remap<1>(tov, idx) = tiv).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - - (tov = (TestType)0).run(exec); - (remap<0,1>(tov, idx, idx) = tiv).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j)); - } - } - } - - { // Reverse test - - auto tov = make_tensor({N,N}); - auto idx = make_tensor({N}); - - for(int i = 0; i < N; i++) { - idx(i) = N-i-1; - } - - (tov = remap<0>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(N-i-1,j)); - } - } - - (tov = remap<1>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i, N-j-1)); - } - } - - (tov = remap<0,1>(tiv, idx, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(N-i-1, N-j-1)); - } - } - } - - { // Reverse lvalue test - - auto tov = make_tensor({N,N}); - auto idx = make_tensor({N}); - - for(int i = 0; i < N; i++) { - idx(i) = N-i-1; - } - - (remap<0>(tov, idx) = tiv).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(N-i-1,j)); - } - } - - (remap<1>(tov, idx) = tiv).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i, N-j-1)); - } - } - - (remap<0,1>(tov, idx, idx) = tiv).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(N-i-1, N-j-1)); - } - } - } - - { // Even test - int M = N/2; - auto idx = make_tensor({M}); - - for(int i = 0; i < M; i++) { - idx(i) = i*2; - } - - { - auto tov = make_tensor({M, N}); - - (tov = remap<0>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < M ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i*2,j)); - } - } - } - - { - auto tov = make_tensor({N, M}); - - (tov = remap<1>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < M ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j*2)); - } - } - } - - { - auto tov = make_tensor({M, M}); - - (tov = remap<0,1>(tiv, idx, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < M ; i++) { - for( int j = 0; j < M ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i*2,j*2)); - } - } - } - } - - { // Braodcast test - int M = N*2; - auto idx = make_tensor({M}); - - for(int i = 0; i < M; i++) { - idx(i) = 1; - } - - { - auto tov = make_tensor({M, N}); - - (tov = remap<0>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < M ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(1,j)); - } - } - } - - { - auto tov = make_tensor({N, M}); - - (tov = remap<1>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < M ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,1)); - } - } - } - } - - { // Advanced test - int M = N*2; - auto idx = make_tensor({M}); - - for(int i = 0; i < M; i++) { - idx(i) = i/4; - } - - { - auto tov = make_tensor({M, N}); - - (tov = remap<0>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < M ; i++) { - for( int j = 0; j < N ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i/4,j)); - } - } - } - - { - auto tov = make_tensor({N, M}); - - (tov = remap<1>(tiv, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < N ; i++) { - for( int j = 0; j < M ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i,j/4)); - } - } - } - - { - auto tov = make_tensor({M, M}); - - (tov = remap<0,1>(tiv, idx, idx)).run(exec); - exec.sync(); - - for( int i = 0; i < M ; i++) { - for( int j = 0; j < M ; j++) { - EXPECT_TRUE(tov(i,j) == tiv(i/4,j/4)); - } - } - } - } - - { - // Remap as both LHS and RHS - auto in = make_tensor({4,4,4}); - auto out = make_tensor({4,4,4}); - TestType c = GenerateData(); - for (int i = 0; i < in.Size(0); i++){ - for (int j = 0; j < in.Size(1); j++){ - for (int k = 0; k < in.Size(2); k++){ - in(i,j,k) = c; - } - } - } - - auto map1 = matx::make_tensor({2}); - auto map2 = matx::make_tensor({2}); - map1(0) = 1; - map1(1) = 2; - map2(0) = 0; - map2(1) = 1; - - (out = static_cast(0)).run(exec); - (matx::remap<2>(out, map2) = matx::remap<2>(in, map1)).run(exec); - exec.sync(); - - for (int i = 0; i < in.Size(0); i++){ - for (int j = 0; j < in.Size(1); j++){ - for (int k = 0; k < in.Size(2); k++){ - if (k > 1) { - ASSERT_EQ(out(i,j,k), (TestType)0); - } - else { - ASSERT_EQ(out(i,j,k), in(i,j,k)); - } - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, RemapRankZero) -{ - MATX_ENTER_HANDLER(); - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - const int N = 16; - - // 1D source tensor cases - { - auto from = make_tensor({N}); - (from = range<0>({N}, 0, 1)).run(exec); - exec.sync(); - auto ind = make_tensor({}); - auto r = remap<0>(from, ind); - auto to = make_tensor({1}); - - ind() = N/2; - (to = r).run(exec); - exec.sync(); - - ASSERT_EQ(to(0), N/2); - - ind() = N/4; - (to = r).run(exec); - exec.sync(); - - ASSERT_EQ(to(0), N/4); - } - - // 2D source tensor cases - { - auto from = make_tensor({N,N}); - (from = ones()).run(exec); - exec.sync(); - - auto i0 = make_tensor({}); - auto i1 = make_tensor({}); - auto r0 = remap<0>(from, i0); - auto r1 = remap<1>(from, i0); - - auto to0 = make_tensor({1,N}); - auto to1 = make_tensor({N,1}); - - i0() = N/2; - from(N/2,0) = 2; - from(0,N/2) = 3; - (to0 = r0).run(exec); - (to1 = r1).run(exec); - exec.sync(); - - ASSERT_EQ(to0(0,0), 2); - ASSERT_EQ(to0(0,1), 1); - ASSERT_EQ(to1(0,0), 3); - ASSERT_EQ(to1(1,0), 1); - - i0() = N/3; - i1() = 2*(N/3); - from(N/3, 2*(N/3)) = 11; - - // Select a single entry from the 2D input tensor - auto entry = make_tensor({1,1}); - (entry = remap<0,1>(from, i0, i1)).run(exec); - exec.sync(); - - ASSERT_EQ(entry(0,0), 11); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, RealImagOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - // example-begin real-test-1 - (tov0 = real(tiv0)).run(exec); - // example-end real-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c.real())); - - // example-begin imag-test-1 - (tov0 = imag(tiv0)).run(exec); - // example-end imag-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c.imag())); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - TestType d = c; - TestType z = 0; - tiv0() = c; - - auto tov00 = make_tensor({}); - - // example-begin IFELSE-test-1 - IFELSE(tiv0 == d, tov0 = z, tov0 = d).run(exec); - // example-end IFELSE-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), z)); - - IFELSE(tiv0 == d, tov0 = tiv0, tov0 = d).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), tiv0())); - - IFELSE(tiv0 != d, tov0 = d, tov0 = z).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), z)); - - (tov0 = c, tov00 = c).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c)); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov00(), c)); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Abs2) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - using inner_type = typename inner_op_type_t::type; - - ExecType exec{}; - - if constexpr (std::is_same_v> && - std::is_same_v) { - // example-begin abs2-test-1 - auto x = make_tensor>({}); - auto y = make_tensor({}); - x() = { 1.5f, 2.5f }; - (y = abs2(x)).run(exec); - exec.sync(); - ASSERT_NEAR(y(), 1.5f*1.5f+2.5f*2.5f, 1.0e-6); - // example-end abs2-test-1 - } - - auto x = make_tensor({}); - auto y = make_tensor({}); - if constexpr (is_complex_v) { - x() = TestType{2.0, 2.0}; - (y = abs2(x)).run(exec); - exec.sync(); - ASSERT_NEAR(y(), 8.0, 1.0e-6); - } else { - x() = 2.0; - (y = abs2(x)).run(exec); - exec.sync(); - ASSERT_NEAR(y(), 4.0, 1.0e-6); - - // Test with higher rank tensor - auto x3 = make_tensor({3,3,3}); - auto y3 = make_tensor({3,3,3}); - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - x3(i,j,k) = static_cast(i*9 + j*3 + k); - } - } - } - - (y3 = abs2(x3)).run(exec); - exec.sync(); - - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - TestType v = static_cast(i*9 + j*3 + k); - ASSERT_NEAR(y3(i,j,k), v*v, 1.0e-6); - } - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, OperatorFuncsR2C) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor>({}); - TestType c = GenerateData(); - tiv0() = c; - - // example-begin expj-test-1 - (tov0 = expj(tiv0)).run(exec); - // example-end expj-test-1 - exec.sync(); - - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - tov0(), - typename detail::complex_from_scalar_t(detail::_internal_cos(tiv0()), detail::_internal_sin(tiv0())))); - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - - // example-begin log10-test-1 - (tov0 = log10(tiv0)).run(exec); - // example-end log10-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log10(c))); - - // example-begin log-test-1 - (tov0 = log(tiv0)).run(exec); - // example-end log-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log(c))); - - // example-begin log2-test-1 - (tov0 = log2(tiv0)).run(exec); - // example-end log2-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log2(c))); - - // example-begin floor-test-1 - (tov0 = floor(tiv0)).run(exec); - // example-end floor-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_floor(c))); - - // example-begin ceil-test-1 - (tov0 = ceil(tiv0)).run(exec); - // example-end ceil-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_ceil(c))); - - // example-begin round-test-1 - (tov0 = round(tiv0)).run(exec); - // example-end round-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_round(c))); - - // example-begin sqrt-test-1 - (tov0 = sqrt(tiv0)).run(exec); - // example-end sqrt-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sqrt(c))); - - // example-begin rsqrt-test-1 - (tov0 = rsqrt(tiv0)).run(exec); - // example-end rsqrt-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_rsqrt(c))); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, NDOperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto a = make_tensor({1,2,3,4,5}); - auto b = make_tensor({1,2,3,4,5}); - (a = ones(a.Shape())).run(exec); - exec.sync(); - (b = ones(b.Shape())).run(exec); - exec.sync(); - (a = a + b).run(exec); - - auto t0 = make_tensor({}); - (t0 = sum(a)).run(exec); - exec.sync(); - ASSERT_EQ(t0(), static_cast(2 * a.TotalSize())); - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatAllExecs, Toeplitz) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - auto pb = std::make_unique(); - pb->InitAndRunTVGenerator("00_operators", "toeplitz", "run", {5, 5, 6}); - - ExecType exec{}; - auto out1 = make_tensor({5, 5}); - auto out2 = make_tensor({5, 5}); - auto out3 = make_tensor({5, 6}); - auto c = make_tensor({5}); - auto r = make_tensor({5}); - auto r2 = make_tensor({6}); - - pb->NumpyToTensorView(c, "c"); - pb->NumpyToTensorView(r, "r"); - pb->NumpyToTensorView(r2, "r2"); - - // example-begin toeplitz-test-1 - (out1 = toeplitz(c)).run(exec); - // example-end toeplitz-test-1 - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out1, "out1", 0.01); - - // example-begin toeplitz-test-2 - (out2 = toeplitz(c, r)).run(exec); - // example-end toeplitz-test-2 - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out2, "out2", 0.01); - - (out3 = toeplitz(c, r2)).run(exec); - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out3, "out3", 0.01); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Cross) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - ExecType exec{}; - auto pb = std::make_unique(); - // Half precision needs a bit more tolerance when compared to fp32 - float thresh = 0.01f; - if constexpr (is_matx_half_v) { - thresh = 0.08f; - } - - {//batched 4 x 3 - pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {4, 3}); - - auto a = make_tensor({4, 3}); - auto b = make_tensor({4, 3}); - auto out = make_tensor({4, 3}); - - pb->NumpyToTensorView(a, "a"); - pb->NumpyToTensorView(b, "b"); - - // example-begin cross-test-1 - (out = cross(a, b)).run(exec); - // example-end cross-test-1 - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); - } - - {//non-batched 3 - pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {3}); - auto a = make_tensor({3}); - auto b = make_tensor({3}); - auto out = make_tensor({3}); - - pb->NumpyToTensorView(a, "a"); - pb->NumpyToTensorView(b, "b"); - - (out = cross(a, b)).run(exec); - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); - } - - {//non-batched 2 - pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {2}); - auto a = make_tensor({2}); - auto b = make_tensor({2}); - auto out = make_tensor({1}); - - pb->NumpyToTensorView(a, "a"); - pb->NumpyToTensorView(b, "b"); - - (out = cross(a, b)).run(exec); - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - TestType d = c + 1; - - // example-begin max-el-test-1 - (tov0 = max(tiv0, d)).run(exec); - // example-end max-el-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), std::max(c, d))); - - // example-begin min-el-test-1 - (tov0 = min(tiv0, d)).run(exec); - // example-end min-el-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), std::min(c, d))); - - // These operators convert type T into bool - auto tob = make_tensor({}); - - // example-begin lt-test-1 - (tob = tiv0 < d).run(exec); - // example-end lt-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c < d)); - - // example-begin gt-test-1 - (tob = tiv0 > d).run(exec); - // example-end gt-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c > d)); - - // example-begin lte-test-1 - (tob = tiv0 <= d).run(exec); - // example-end lte-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c <= d)); - - // example-begin gte-test-1 - (tob = tiv0 >= d).run(exec); - // example-end gte-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c >= d)); - - // example-begin eq-test-1 - (tob = tiv0 == d).run(exec); - // example-end eq-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c == d)); - - // example-begin neq-test-1 - (tob = tiv0 != d).run(exec); - // example-end neq-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c != d)); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, OperatorFuncDivComplex) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - typename TestType::value_type s = 5.0; - - TestType c = GenerateData(); - tiv0() = c; - - (tov0 = s / tiv0).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), s / tiv0())); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, IsNanInf) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto nan = make_tensor({}); - using conversionType = typename matx::detail::value_promote_t; - if constexpr(matx::is_complex_v) { - nan() = TestType(std::numeric_limits::quiet_NaN()); - } else { - nan() = std::numeric_limits::quiet_NaN(); - } - auto tob = make_tensor({}); - // example-begin nan-test-1 - (tob = matx::isnan(nan)).run(exec); - // example-end nan-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), std::is_floating_point_v ? true : false)); - - auto notnanorinf = make_tensor({}); - if constexpr(matx::is_complex_v) { - notnanorinf() = TestType(0); - } else { - notnanorinf() = 0; - } - (tob = matx::isnan(notnanorinf)).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), false)); - - auto inf = make_tensor({}); - if constexpr(matx::is_complex_v) { - inf() = TestType(std::numeric_limits::infinity()); - } else { - inf() = std::numeric_limits::infinity(); - } - // example-begin inf-test-1 - (tob = matx::isinf(inf)).run(exec); - // example-end inf-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), std::is_floating_point_v ? true : false)); - - (tob = matx::isinf(notnanorinf)).run(exec); - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), false)); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - - // example-begin add-test-1 - (tov0 = tiv0 + tiv0).run(exec); - // example-end add-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c + c)); - - // example-begin sub-test-1 - (tov0 = tiv0 - tiv0).run(exec); - // example-end sub-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c - c)); - - // example-begin mul-test-1 - (tov0 = tiv0 * tiv0).run(exec); - // example-end mul-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c * c)); - - // example-begin div-test-1 - (tov0 = tiv0 / tiv0).run(exec); - // example-end div-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c / c)); - - // example-begin neg-test-1 - (tov0 = -tiv0).run(exec); - // example-end neg-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), -c)); - - // example-begin IF-test-1 - IF(tiv0 == tiv0, tov0 = c).run(exec); - // example-end IF-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c)); - - TestType p = 2.0f; - // example-begin pow-test-1 - (tov0 = as_type(pow(tiv0, p))).run(exec); - // example-end pow-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_pow(c, p))); - - TestType three = 3.0f; - - (tov0 = tiv0 * tiv0 * (tiv0 + tiv0) / tiv0 + three).run(exec); - exec.sync(); - - TestType res; - res = c * c * (c + c) / c + three; - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), res, 0.07)); - - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsIntegralAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - TestType mod = 2; - - // example-begin mod-test-1 - (tov0 = tiv0 % mod).run(exec); - // example-end mod-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c % mod)); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsBooleanAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - TestType d = false; - tiv0() = c; - - // example-begin land-test-1 - (tov0 = tiv0 && d).run(exec); - // example-end land-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c && d)); - - // example-begin lor-test-1 - (tov0 = tiv0 || d).run(exec); - // example-end lor-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c || d)); - - // example-begin lnot-test-1 - (tov0 = !tiv0).run(exec); - // example-end lnot-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), !c)); - - // example-begin xor-test-1 - (tov0 = tiv0 ^ d).run(exec); - // example-end xor-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c ^ d)); - - // example-begin or-test-1 - (tov0 = tiv0 | d).run(exec); - // example-end or-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c | d)); - - // example-begin and-test-1 - (tov0 = tiv0 & d).run(exec); - // example-end and-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c & d)); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, OperatorFuncs) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto tiv0 = make_tensor({}); - auto tov0 = make_tensor({}); - - TestType c = GenerateData(); - tiv0() = c; - - // example-begin exp-test-1 - (tov0 = exp(tiv0)).run(exec); - // example-end exp-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_exp(c))); - - // example-begin conj-test-1 - (tov0 = conj(tiv0)).run(exec); - // example-end conj-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_conj(c))); - - // abs takes a complex and output a floating point value - auto tdd0 = make_tensor({}); - - // example-begin abs-test-1 - (tdd0 = abs(tiv0)).run(exec); - // example-end abs-test-1 - exec.sync(); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(tdd0(), detail::_internal_abs(c))); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, Flatten) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin flatten-test-1 - auto t2 = make_tensor({10, 2}); - auto val = GenerateData(); - - for (index_t i = 0; i < t2.Size(0); i++) { - for (index_t j = 0; j < t2.Size(1); j++) { - t2(i,j) = val; - } - } - - auto t1 = make_tensor({t2.Size(0)*t2.Size(1)}); - (t1 = flatten(t2)).run(exec); - // example-end flatten-test-1 - exec.sync(); - - for (index_t i = 0; i < t2.Size(0)*t2.Size(1); i++) { - ASSERT_EQ(t1(i), val); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericNoHalfAllExecs, AdvancedOperators) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count = 100; - - tensor_t a({count}); - tensor_t b({count}); - tensor_t c({count}); - - for (index_t i = 0; i < count; i++) { - a(i) = static_cast>(i); - b(i) = static_cast>(i + 100); - } - - { - (c = a + b).run(exec); - - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = static_cast>(i); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(c(i), tcnt + (tcnt + (TestType)100))); - } - } - - { - (c = a * b).run(exec); - - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = static_cast>(i); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(c(i), tcnt * (tcnt + (TestType)100))); - } - } - - { - (c = a * b + a).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = static_cast>(i); - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - c(i), tcnt * (tcnt + (TestType)100) + tcnt)); - } - } - - { - - (c = a * b + a * (TestType)4.0f).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = static_cast>(i); - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - c(i), tcnt * (tcnt + (TestType)100.0f) + tcnt * (TestType)4)); - } - } - MATX_EXIT_HANDLER(); -} - - - -TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, AdvancedOperators) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count = 10; - - tensor_t a({count}); - tensor_t b({count}); - tensor_t c({count}); - - for (index_t i = 0; i < count; i++) { - a(i) = (TestType)i; - b(i) = (TestType)(i + 2); - } - - { - (c = a + b).run(exec); - - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = (TestType)i; - EXPECT_TRUE(MatXUtils::MatXTypeCompare(c(i), (TestType)((float)tcnt + ((float)tcnt + 2.0f)))); - } - } - - { - (c = a * b).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = (TestType)i; - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(c(i), (float)tcnt * ((float)tcnt + 2.0f))); - } - } - - { - (c = a * b + a).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = (TestType)i; - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - c(i), (float)tcnt * ((float)tcnt + 2.0f) + (float)tcnt)); - } - } - - { - - (c = a * b + a * (TestType)2.0f).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - TestType tcnt = (TestType)i; - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - c(i), (float)tcnt * ((float)tcnt + 2.0f) + (float)tcnt * 2.0f)); - } - } - MATX_EXIT_HANDLER(); -} - - -// Testing 4 basic arithmetic operations with complex numbers and non-complex -TYPED_TEST(OperatorTestsComplexTypesAllExecs, ComplexTypeCompatibility) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count = 10; - - tensor_t fview({count}); - tensor_t dview({count}); - - // Multiply by scalar - for (index_t i = 0; i < count; i++) { - fview(i) = static_cast(i); - dview(i) = {static_cast>(i), - static_cast>(i)}; - } - - (dview = dview * fview).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - ASSERT_EQ(static_cast>(dview(i).real()), - static_cast>(i * i)); - ASSERT_EQ(static_cast>(dview(i).imag()), - static_cast>(i * i)); - } - - // Divide by scalar - for (index_t i = 0; i < count; i++) { - fview(i) = i == 0 ? static_cast(1) : static_cast(i); - dview(i) = {static_cast>(i), - static_cast>(i)}; - } - - (dview = dview / fview).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - ASSERT_EQ(static_cast>(dview(i).real()), - i == 0 ? static_cast>(0) - : static_cast>(1)); - ASSERT_EQ(static_cast>(dview(i).imag()), - i == 0 ? static_cast>(0) - : static_cast>(1)); - } - - // Add scalar - for (index_t i = 0; i < count; i++) { - fview(i) = static_cast(i); - dview(i) = {static_cast>(i), - static_cast>(i)}; - } - - - (dview = dview + fview).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - ASSERT_EQ(static_cast>(dview(i).real()), - static_cast>(i + i)); - ASSERT_EQ(static_cast>(dview(i).imag()), - static_cast>(i)); - } - - // Subtract scalar from complex - for (index_t i = 0; i < count; i++) { - fview(i) = static_cast(i + 1); - dview(i) = {static_cast>(i), - static_cast>(i)}; - } - - (dview = dview - fview).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - ASSERT_EQ(static_cast>(dview(i).real()), - static_cast>(-1)); - ASSERT_EQ(static_cast>(dview(i).imag()), - static_cast>(i)); - } - - // Subtract complex from scalar - for (index_t i = 0; i < count; i++) { - fview(i) = static_cast(i + 1); - dview(i) = {static_cast>(i), - static_cast>(i)}; - } - - (dview = fview - dview).run(exec); - exec.sync(); - - for (index_t i = 0; i < count; i++) { - ASSERT_EQ(static_cast>(dview(i).real()), - static_cast>(1)); - ASSERT_EQ(static_cast>(dview(i).imag()), - static_cast>(-i)); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, SquareCopyTranspose) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t count = 512; - tensor_t t2({count, count}); - tensor_t t2t({count, count}); - - for (index_t i = 0; i < count; i++) { - for (index_t j = 0; j < count; j++) { - t2(i, j) = static_cast>(i * count + j); - } - } - - matx::copy(t2t, t2, exec); - - exec.sync(); - - for (index_t i = 0; i < count; i++) { - for (index_t j = 0; j < count; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2t(i, j), - TestType(i * count + (double)j))); - } - } - - (t2t = transpose(t2)).run(exec); - - exec.sync(); - - for (index_t i = 0; i < count; i++) { - for (index_t j = 0; j < count; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j), - TestType(i * count + (double)j))); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2t(j, i), TestType(i * count + j))); - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, NonSquareTranspose) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count = 100; - index_t count1 = 200, count2 = 100; - tensor_t t2({count1, count2}); - tensor_t t2t({count2, count1}); - - for (index_t i = 0; i < count1; i++) { - for (index_t j = 0; j < count2; j++) { - t2(i, j) = static_cast>(i * count + j); - } - } - - (t2t = transpose(t2)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count1; i++) { - for (index_t j = 0; j < count2; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j), - TestType(i * count + (double)j))); - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2t(j, i), - TestType(i * count + (double)j))); - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Transpose3D) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t num_rows = 5998; - index_t num_cols = 64; - - tensor_t t3 ({1, num_rows, num_cols}); - tensor_t t3t({1, num_cols, num_rows}); - - for (index_t i = 0; i < num_rows; i++) { - for (index_t j = 0; j < num_cols; j++) { - t3(0, i, j) = static_cast>(i * num_cols + j); - } - } - - (t3t = transpose_matrix(t3)).run(exec); - exec.sync(); - - if constexpr (std::is_same_v) { - ASSERT_EQ(cudaGetLastError(), cudaSuccess); - } - - for (index_t i = 0; i < num_rows; i++) { - for (index_t j = 0; j < num_cols; j++) { - EXPECT_EQ(t3(0, i, j), t3t(0, j, i)); - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, TransposeVsTransposeMatrix) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - // example-begin transpose-test-1 - // ExecType is an executor type (e.g. matx::cudaExecutor for executing on the GPU). - ExecType exec{}; - - const index_t m = 3; - const index_t n = 5; - const index_t p = 7; - - // TestType is the tensor data type - tensor_t t3 ({m,n,p}); - tensor_t t3t ({p,n,m}); - tensor_t t3tm({m,p,n}); - - for (index_t i = 0; i < m; i++) { - for (index_t j = 0; j < n; j++) { - for (index_t k = 0; k < p; k++) { - t3(i, j, k) = static_cast>(i*n*p + j*p + k); - } - } - } - - (t3t = transpose(t3)).run(exec); - (t3tm = transpose_matrix(t3)).run(exec); - - exec.sync(); - if constexpr (std::is_same_v) { - ASSERT_EQ(cudaGetLastError(), cudaSuccess); - } - - for (index_t i = 0; i < m; i++) { - for (index_t j = 0; j < n; j++) { - for (index_t k = 0; k < p; k++) { - // transpose() permutes all dimensions whereas transpose_matrix() only permutes the - // last two dimensions. - EXPECT_EQ(t3(i,j,k), t3t(k,j,i)); - EXPECT_EQ(t3(i,j,k), t3tm(i,k,j)); - } - } - } - // example-end transpose-test-1 - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, CloneAndAdd) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t numSamples = 8; - index_t numPulses = 4; - index_t numPairs = 2; - index_t numBeams = 2; - - tensor_t beamwiseRangeDoppler( - {numBeams, numPulses, numPairs, numSamples}); - tensor_t steeredMx({numBeams, numSamples}); - tensor_t velAccelHypoth({numPulses, numPairs, numSamples}); - - for (index_t i = 0; i < numBeams; i++) { - for (index_t j = 0; j < numSamples; j++) { - steeredMx(i, j) = static_cast((i + 1) * 10 + (j + 1)); - } - } - - for (index_t i = 0; i < numPulses; i++) { - for (index_t j = 0; j < numPairs; j++) { - for (index_t k = 0; k < numSamples; k++) { - velAccelHypoth(i, j, k) = static_cast( - (i + 1) * 10 + (j + 1) * 1 + (k + 1) * 1); - } - } - } - - auto smx = - clone<4>(steeredMx, {matxKeepDim, numPulses, numPairs, matxKeepDim}); - auto vah = clone<4>(velAccelHypoth, - {numBeams, matxKeepDim, matxKeepDim, matxKeepDim}); - - (beamwiseRangeDoppler = smx + vah).run(exec); - - exec.sync(); - for (index_t i = 0; i < numBeams; i++) { - for (index_t j = 0; j < numPulses; j++) { - for (index_t k = 0; k < numPairs; k++) { - for (index_t l = 0; l < numSamples; l++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - beamwiseRangeDoppler(i, j, k, l), - steeredMx(i, l) + velAccelHypoth(j, k, l))); - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - beamwiseRangeDoppler(i, j, k, l), - ((i + 1) * 10 + (l + 1)) // steeredMx - + ((j + 1) * 10 + (k + 1) * 1 + - (l + 1) * 1) // velAccelHypoth - )); - } - } - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Reshape) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count = 10; - tensor_t t4({count, count, count, count}); - tensor_t t1({count * count * count * count}); - - for (index_t i = 0; i < t4.Size(0); i++) { - for (index_t j = 0; j < t4.Size(1); j++) { - for (index_t k = 0; k < t4.Size(2); k++) { - for (index_t l = 0; l < t4.Size(3); l++) { - t4(i, j, k, l) = - static_cast>(i + j + k + l); - t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1)) = - static_cast>(i + j + k + l); - } - } - } - } - - // Drop to a single dimension of same original total size - auto rsv1 = t4.View({count * count * count * count}); - for (index_t i = 0; i < t4.Size(0); i++) { - for (index_t j = 0; j < t4.Size(1); j++) { - for (index_t k = 0; k < t4.Size(2); k++) { - for (index_t l = 0; l < t4.Size(3); l++) { - MATX_ASSERT_EQ(rsv1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1)), - (TestType)(i + j + k + (double)l)); - } - } - } - } - - // Drop to 2D with a subset of the original size - auto rsv2 = t4.View({2, 2}); - for (index_t i = 0; i < rsv2.Size(0); i++) { - for (index_t j = 0; j < rsv2.Size(1); j++) { - MATX_ASSERT_EQ(rsv2(i, j), t4(0, 0, 0, i * rsv2.Size(1) + j)); - } - } - - // Create a 4D tensor from the 1D - auto rsv4 = t1.View({count, count, count, count}); - for (index_t i = 0; i < rsv4.Size(0); i++) { - for (index_t j = 0; j < rsv4.Size(1); j++) { - for (index_t k = 0; k < rsv4.Size(2); k++) { - for (index_t l = 0; l < rsv4.Size(3); l++) { - MATX_ASSERT_EQ(rsv4(i, j, k, l), - t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1))); - } - } - } - } - - - // Test if oversized views throw -#ifndef NDEBUG - try { - t4.View({1000, 1000, 100}); - FAIL() << "Oversized views not throwing"; - } catch (detail::matxException &e) {} -#endif - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, Overlap) -{ - MATX_ENTER_HANDLER(); - - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - - tensor_t a{{10}}; - a.SetVals({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - auto ao = overlap(a, {4}, {2}); - - tensor_t b{{4, 4}}; - b.SetVals({{0, 1, 2, 3}, {2, 3, 4, 5}, {4, 5, 6, 7}, {6, 7, 8, 9}}); - for (index_t i = 0; i < b.Size(0); i++) { - for (index_t j = 0; j < b.Size(1); j++) { - ASSERT_EQ(ao(i, j), b(i, j)); - } - } - - auto ao2 = overlap(a, {4}, {1}); - - tensor_t b2{{7, 4}}; - b2.SetVals({{0, 1, 2, 3}, - {1, 2, 3, 4}, - {2, 3, 4, 5}, - {3, 4, 5, 6}, - {4, 5, 6, 7}, - {5, 6, 7, 8}, - {6, 7, 8, 9}}); - for (index_t i = 0; i < b2.Size(0); i++) { - for (index_t j = 0; j < b2.Size(1); j++) { - ASSERT_EQ(ao2(i, j), b2(i, j)); - } - } - - auto ao3 = overlap(a, {4}, {3}); - tensor_t b3{{3, 4}}; - b3.SetVals({{0, 1, 2, 3}, {3, 4, 5, 6}, {6, 7, 8, 9}}); - for (index_t i = 0; i < b3.Size(0); i++) { - for (index_t j = 0; j < b3.Size(1); j++) { - ASSERT_EQ(ao3(i, j), b3(i, j)); - } - } - - auto ao4 = overlap(a, {3}, {2}); - tensor_t b4{{4, 3}}; - b4.SetVals({{0, 1, 2}, {2, 3, 4}, {4, 5, 6}, {6, 7, 8}}); - for (index_t i = 0; i < b4.Size(0); i++) { - for (index_t j = 0; j < b4.Size(1); j++) { - ASSERT_EQ(ao4(i, j), b4(i, j)); - } - } - - // Test with an operator input - // example-begin overlap-test-1 - auto aop = linspace<0>(a.Shape(), (TestType)0, (TestType)9); - tensor_t b4out{{4, 3}}; - - // Input is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - // Output is: {{0, 1, 2}, {2, 3, 4}, {4, 5, 6}, {6, 7, 8}} - (b4out = overlap(aop, {3}, {2})).run(exec); - // example-end overlap-test-1 - - ASSERT_EQ(b4out.Size(0), 4); - ASSERT_EQ(b4out.Size(1), 3); - - exec.sync(); - for (index_t i = 0; i < b4.Size(0); i++) { - for (index_t j = 0; j < b4.Size(1); j++) { - ASSERT_EQ(b4out(i, j), b4(i, j)); - } - } - - MATX_EXIT_HANDLER(); -} - - - -TYPED_TEST(OperatorTestsNumericAllExecs, Broadcast) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - { - auto t0 = make_tensor({}); - tensor_t t4i({10, 20, 30, 40}); - tensor_t t4o({10, 20, 30, 40}); - (t4o = t0).run(exec); - - t0() = (TestType)2.0f; - for (index_t i = 0; i < t4i.Size(0); i++) { - for (index_t j = 0; j < t4i.Size(1); j++) { - for (index_t k = 0; k < t4i.Size(2); k++) { - for (index_t l = 0; l < t4i.Size(3); l++) { - t4i(i, j, k, l) = - static_cast>(i + j + k + l); - } - } - } - } - - (t4o = t4i * t0).run(exec); - exec.sync(); - - for (index_t i = 0; i < t4o.Size(0); i++) { - for (index_t j = 0; j < t4o.Size(1); j++) { - for (index_t k = 0; k < t4o.Size(2); k++) { - for (index_t l = 0; l < t4o.Size(3); l++) { - if constexpr (IsHalfType()) { - MATX_ASSERT_EQ(t4o(i, j, k, l), - (TestType)t4i(i, j, k, l) * (TestType)t0()); - } - else { - MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) * t0()); - } - } - } - } - } - (t4o = t0 * t4i).run(exec); - exec.sync(); - - for (index_t i = 0; i < t4o.Size(0); i++) { - for (index_t j = 0; j < t4o.Size(1); j++) { - for (index_t k = 0; k < t4o.Size(2); k++) { - for (index_t l = 0; l < t4o.Size(3); l++) { - if constexpr (IsHalfType()) { - MATX_ASSERT_EQ(t4o(i, j, k, l), - (TestType)t0() * (TestType)t4i(i, j, k, l)); - } - else { - MATX_ASSERT_EQ(t4o(i, j, k, l), t0() * t4i(i, j, k, l)); - } - } - } - } - } - // } - // { - // tensor_t t1({4}); - // tensor_t t4i({1, 2, 3, 4}); - // tensor_t t4o({1, 2, 3, 4}); - - // for (index_t i = 0; i < t1.Size(0); i++) { - // t1(i) = static_cast>(i); - // } - - // for (index_t i = 0; i < t4i.Size(0); i++) { - // for (index_t j = 0; j < t4i.Size(1); j++) { - // for (index_t k = 0; k < t4i.Size(2); k++) { - // for (index_t l = 0; l < t4i.Size(3); l++) { - // t4i(i, j, k, l) = - // static_cast>(i + j + k + l); - // } - // } - // } - // } - - // (t4o = t4i * t1).run(exec); - // exec.sync(); - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t4i(i, j, k, l) * (double)t1(l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) * t1(l)); - // } - // } - // } - // } - // } - - // (t4o = t1 * t4i).run(exec); - // exec.sync(); - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t1(l) * (double)t4i(i, j, k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t1(l) * t4i(i, j, k, l)); - // } - // } - // } - // } - // } - // } - - // { - // tensor_t t2({3, 4}); - // tensor_t t4i({1, 2, 3, 4}); - // tensor_t t4o({1, 2, 3, 4}); - - // for (index_t i = 0; i < t2.Size(0); i++) { - // for (index_t j = 0; j < t2.Size(1); j++) { - // t2(i, j) = static_cast>(i + j); - // } - // } - - // for (index_t i = 0; i < t4i.Size(0); i++) { - // for (index_t j = 0; j < t4i.Size(1); j++) { - // for (index_t k = 0; k < t4i.Size(2); k++) { - // for (index_t l = 0; l < t4i.Size(3); l++) { - // t4i(i, j, k, l) = - // static_cast>(i + j + k + l); - // } - // } - // } - // } - - // (t4o = t4i * t2).run(exec); - // exec.sync(); - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t4i(i, j, k, l) * (double)t2(k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) * t2(k, l)); - // } - // } - // } - // } - // } - - // (t4o = t2 * t4i).run(exec); - // exec.sync(); - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t2(k, l) * (double)t4i(i, j, k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t2(k, l) * t4i(i, j, k, l)); - // } - // } - // } - // } - // } - // } - - // { - // tensor_t t3({2, 3, 4}); - // tensor_t t4i({1, 2, 3, 4}); - // tensor_t t4o({1, 2, 3, 4}); - - // for (index_t i = 0; i < t3.Size(0); i++) { - // for (index_t j = 0; j < t3.Size(1); j++) { - // for (index_t k = 0; k < t3.Size(2); k++) { - // t3(i, j, k) = static_cast>(i + j + k); - // } - // } - // } - - // for (index_t i = 0; i < t4i.Size(0); i++) { - // for (index_t j = 0; j < t4i.Size(1); j++) { - // for (index_t k = 0; k < t4i.Size(2); k++) { - // for (index_t l = 0; l < t4i.Size(3); l++) { - // t4i(i, j, k, l) = - // static_cast>(i + j + k + l); - // } - // } - // } - // } - - // (t4o = t4i * t3).run(exec); - // exec.sync() - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t4i(i, j, k, l) * (double)t3(j, k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) * t3(j, k, l)); - // } - // } - // } - // } - // } - - // (t4o = t3 * t4i).run(exec); - // exec.sync() - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t3(j, k, l) * (double)t4i(i, j, k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t3(j, k, l) * t4i(i, j, k, l)); - // } - // } - // } - // } - // } - // } - - // { - // tensor_t t0; - // tensor_t t1({4}); - // tensor_t t2({3, 4}); - // tensor_t t3({2, 3, 4}); - // tensor_t t4i({1, 2, 3, 4}); - // tensor_t t4o({1, 2, 3, 4}); - - // t0() = (TestType)200.0f; - - // for (index_t i = 0; i < t2.Size(0); i++) { - // t1(i) = static_cast>(i); - // } - - // for (index_t i = 0; i < t2.Size(0); i++) { - // for (index_t j = 0; j < t2.Size(1); j++) { - // t2(i, j) = static_cast>(i + j); - // } - // } - - // for (index_t i = 0; i < t3.Size(0); i++) { - // for (index_t j = 0; j < t3.Size(1); j++) { - // for (index_t k = 0; k < t3.Size(2); k++) { - // t3(i, j, k) = static_cast>(i + j + k); - // } - // } - // } - - // for (index_t i = 0; i < t4i.Size(0); i++) { - // for (index_t j = 0; j < t4i.Size(1); j++) { - // for (index_t k = 0; k < t4i.Size(2); k++) { - // for (index_t l = 0; l < t4i.Size(3); l++) { - // t4i(i, j, k, l) = - // static_cast>(i + j + k + l); - // } - // } - // } - // } - - // (t4o = t4i + t3 + t2 + t1 + t0).run(exec); - // exec.sync() - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t4i(i, j, k, l) + (double)t3(j, k, l) + - // (double)t2(k, l) + (double)t1(l) + - // (double)(double)t0()); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) + t3(j, k, l) + - // t2(k, l) + t1(l) + t0()); - // } - // } - // } - // } - // } - - // (t4o = t0 + t1 + t2 + t3 + t4i).run(exec); - // exec.sync(); - - // for (index_t i = 0; i < t4o.Size(0); i++) { - // for (index_t j = 0; j < t4o.Size(1); j++) { - // for (index_t k = 0; k < t4o.Size(2); k++) { - // for (index_t l = 0; l < t4o.Size(3); l++) { - // if constexpr (IsHalfType()) { - // MATX_ASSERT_EQ(t4o(i, j, k, l), - // (double)t0() + (double)t1(l) + (double)t2(k, l) + - // (double)t3(j, k, l) + (double)t4i(i, j, k, l)); - // } - // else { - // MATX_ASSERT_EQ(t4o(i, j, k, l), t0() + t1(l) + t2(k, l) + - // t3(j, k, l) + - // t4i(i, j, k, l)); - // } - // } - // } - // } - // } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Concatenate) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t i, j; - - // example-begin concat-test-1 - auto t11 = make_tensor({10}); - auto t12 = make_tensor({5}); - auto t1o = make_tensor({15}); - - t11.SetVals({0,1,2,3,4,5,6,7,8,9}); - t12.SetVals({0,1,2,3,4}); - - // Concatenate "t11" and "t12" into a new 1D tensor - (t1o = concat(0, t11, t12)).run(exec); - // example-end concat-test-1 - exec.sync(); - - for (i = 0; i < t11.Size(0) + t12.Size(0); i++) { - if (i < t11.Size(0)) { - ASSERT_EQ(t11(i), t1o(i)); - } - else { - ASSERT_EQ(t12(i - t11.Size(0)), t1o(i)); - } - } - - // Test contcat with nested transforms - if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) { - auto delta = make_tensor({1}); - delta.SetVals({1.0}); - - (t1o = 0).run(exec); - (t1o = concat(0, conv1d(t11, delta, MATX_C_MODE_SAME), conv1d(t12, delta, MATX_C_MODE_SAME))).run(exec); - - exec.sync(); - - for (i = 0; i < t11.Size(0) + t12.Size(0); i++) { - if (i < t11.Size(0)) { - ASSERT_EQ(t11(i), t1o(i)); - } - else { - ASSERT_EQ(t12(i - t11.Size(0)), t1o(i)); - } - } - } - - // 2D tensors - auto t21 = make_tensor({4, 4}); - auto t22 = make_tensor({3, 4}); - auto t23 = make_tensor({4, 3}); - - auto t2o1 = make_tensor({7,4}); - auto t2o2 = make_tensor({4,7}); - t21.SetVals({{1,2,3,4}, - {2,3,4,5}, - {3,4,5,6}, - {4,5,6,7}} ); - t22.SetVals({{5,6,7,8}, - {6,7,8,9}, - {9,10,11,12}}); - t23.SetVals({{5,6,7}, - {6,7,8}, - {9,10,11}, - {10,11,12}}); - - (t2o1 = concat(0, t21, t22)).run(exec); - exec.sync(); - - for (i = 0; i < t21.Size(0) + t22.Size(0); i++) { - for (j = 0; j < t21.Size(1); j++) { - if (i < t21.Size(0)) { - ASSERT_EQ(t21(i,j), t2o1(i,j)); - } - else { - ASSERT_EQ(t22(i - t21.Size(0), j), t2o1(i,j)); - } - } - } - - (t2o2 = concat(1, t21, t23)).run(exec); - exec.sync(); - - for (j = 0; j < t21.Size(1) + t23.Size(1); j++) { - for (i = 0; i < t21.Size(0); i++) { - if (j < t21.Size(1)) { - ASSERT_EQ(t21(i,j), t2o2(i,j)); - } - else { - ASSERT_EQ(t23(i, j - t21.Size(1)), t2o2(i,j)); - } - } - } - - auto t1o1 = make_tensor({30}); - - // Concatenating 3 tensors - (t1o1 = concat(0, t11, t11, t11)).run(exec); - exec.sync(); - - for (i = 0; i < t1o1.Size(0); i++) { - ASSERT_EQ(t1o1(i), t11(i % t11.Size(0))); - } - - - // Multiple concatenations - { - auto a = matx::make_tensor({10}); - auto b = matx::make_tensor({10}); - auto c = matx::make_tensor({10}); - auto d = matx::make_tensor({10}); - - auto result = matx::make_tensor({40}); - a.SetVals({1,2,3,4,5,6,7,8,9,10}); - b.SetVals({11,12,13,14,15,16,17,18,19,20}); - c.SetVals({21,22,23,24,25,26,27,28,29,30}); - d.SetVals({31,32,33,34,35,36,37,38,39,40}); - - auto tempConcat1 = matx::concat(0, a, b); - auto tempConcat2 = matx::concat(0, c, d); - (result = matx::concat(0, tempConcat1, tempConcat2 )).run(exec); - - exec.sync(); - for (int cnt = 0; cnt < result.Size(0); cnt++) { - ASSERT_EQ(result(cnt), cnt + 1); - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Stack) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - auto t1a = make_tensor({5}); - auto t1b = make_tensor({5}); - auto t1c = make_tensor({5}); - - auto cop = concat(0, t1a, t1b, t1c); - - (cop = (TestType)2).run(exec); - exec.sync(); - - { - // example-begin stack-test-1 - // Stack 1D operators "t1a", "t1b", and "t1c" together along the first dimension - auto op = stack(0, t1a, t1b, t1c); - // example-end stack-test-1 - - for(int i = 0; i < t1a.Size(0); i++) { - ASSERT_EQ(op(0,i), t1a(i)); - ASSERT_EQ(op(1,i), t1b(i)); - ASSERT_EQ(op(2,i), t1c(i)); - } - } - - { - auto op = stack(1, t1a, t1b, t1c); - - for(int i = 0; i < t1a.Size(0); i++) { - ASSERT_EQ(op(i,0), t1a(i)); - ASSERT_EQ(op(i,1), t1b(i)); - ASSERT_EQ(op(i,2), t1c(i)); - } - } - - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, HermitianTranspose) -{ - MATX_ENTER_HANDLER(); - - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t count0 = 100; - index_t count1 = 200; - tensor_t t2({count0, count1}); - tensor_t t2s({count1, count0}); - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - TestType tmp = {(float)i, (float)-j}; - t2(i, j) = tmp; - } - } - - // example-begin hermitianT-test-1 - (t2s = hermitianT(t2)).run(exec); - // example-end hermitianT-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(static_cast(t2s(j, i).real()), - static_cast(t2(i, j).real()))); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(-static_cast(t2s(j, i).imag()), - static_cast(t2(i, j).imag()))); - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, PlanarTransform) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - index_t m = 10; - index_t k = 20; - tensor_t t2({m, k}); - tensor_t t2p({m * 2, k}); - for (index_t i = 0; i < m; i++) { - for (index_t j = 0; j < k; j++) { - TestType tmp = {(float)i, (float)-j}; - t2(i, j) = tmp; - } - } - - (t2p = planar(t2)).run(exec); - exec.sync(); - - for (index_t i = 0; i < m; i++) { - for (index_t j = 0; j < k; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j).real(), t2p(i, j))); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2(i, j).imag(), t2p(i + t2.Size(0), j))) << i << " " << j << "\n"; - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsComplexTypesAllExecs, InterleavedTransform) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t m = 10; - index_t k = 20; - tensor_t t2({m, k}); - tensor_t t2p({m * 2, k}); - for (index_t i = 0; i < 2 * m; i++) { - for (index_t j = 0; j < k; j++) { - if (i >= m) { - t2p(i, j) = 2.0f; - } - else { - t2p(i, j) = -1.0f; - } - } - } - - (t2 = interleaved(t2p)).run(exec); - exec.sync(); - - for (index_t i = 0; i < m; i++) { - for (index_t j = 0; j < k; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j).real(), t2p(i, j))); - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2(i, j).imag(), t2p(i + t2.Size(0), j))); - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsAllExecs, RepMat) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // example-begin repmat-test-1 - const index_t count0 = 4; - const index_t count1 = 4; - const index_t same_reps = 10; - tensor_t t2({count0, count1}); - tensor_t t2s({count0 * same_reps, count1 * same_reps}); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - t2(i, j) = static_cast>(i); - } - } - - auto repop = repmat(t2, same_reps); - // example-end repmat-test-1 - ASSERT_TRUE(repop.Size(0) == same_reps * t2.Size(0)); - ASSERT_TRUE(repop.Size(1) == same_reps * t2.Size(1)); - - (t2s = repop).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0 * same_reps; i++) { - for (index_t j = 0; j < count1 * same_reps; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2s(i, j), t2(i % count0, j % count1))); - } - } - - // Now a rectangular repmat - tensor_t t2r({count0 * same_reps, count1 * same_reps * 2}); - - auto rrepop = repmat(t2, {same_reps, same_reps * 2}); - ASSERT_TRUE(rrepop.Size(0) == same_reps * t2.Size(0)); - ASSERT_TRUE(rrepop.Size(1) == same_reps * 2 * t2.Size(1)); - - (t2r = rrepop).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0 * same_reps; i++) { - for (index_t j = 0; j < count1 * same_reps * 2; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2r(i, j), t2(i % count0, j % count1))); - } - } - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Sphere2Cart) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - int n = 5; - - auto xi = range<0>({n},(TestType)1,(TestType)1); - auto yi = range<0>({n},(TestType)1,(TestType)1); - auto zi = range<0>({n},(TestType)1,(TestType)1); - - // example-begin cart2sph-test-1 - auto [theta, phi, r] = cart2sph(xi, yi, zi); - // example-end cart2sph-test-1 - - // example-begin sph2cart-test-1 - auto [x, y, z] = sph2cart(theta, phi, r); - // example-end sph2cart-test-1 - - for(int i=0; i; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - auto pb = std::make_unique(); - pb->InitAndRunTVGenerator("00_operators", "polyval_operator", "run", {4, 100}); - - ExecType exec{}; - auto x = make_tensor({100}); - auto c = make_tensor({4}); - auto out = make_tensor({100}); - - pb->NumpyToTensorView(x, "x"); - pb->NumpyToTensorView(c, "c"); - - // example-begin polyval-test-1 - (out = polyval(x, c)).run(exec); - // example-end polyval-test-1 - exec.sync(); - MATX_TEST_ASSERT_COMPARE(pb, out, "out", 0.01); - - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsNumericAllExecs, Upsample) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - { - // example-begin upsample-test-1 - // Upsample a signal of length 100 by 5 - int n = 5; - - auto t1 = make_tensor({100}); - (t1 = static_cast(1)).run(exec); - auto us_op = upsample(t1, 0, n); - // example-end upsample-test-1 - exec.sync(); - - ASSERT_TRUE(us_op.Size(0) == t1.Size(0) * n); - for (index_t i = 0; i < us_op.Size(0); i++) { - if ((i % n) == 0) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(us_op(i), t1(i / n))); - } - else { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(us_op(i), static_cast(0))); - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Downsample) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - { - // example-begin downsample-test-1 - int n = 5; - - auto t1 = make_tensor({100}); - (t1 = static_cast(1)).run(exec); - auto ds_op = downsample(t1, 0, n); - // example-end downsample-test-1 - exec.sync(); - - ASSERT_TRUE(ds_op.Size(0) == t1.Size(0) / n); - for (index_t i = 0; i < ds_op.Size(0); i++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(ds_op(i), t1(i * n))); - } - } - - { - int n = 3; - - auto t1 = make_tensor({100}); - (t1 = static_cast(1)).run(exec); - auto ds_op = downsample(t1, 0, n); - - exec.sync(); - - ASSERT_TRUE(ds_op.Size(0) == t1.Size(0) / n + 1); - for (index_t i = 0; i < ds_op.Size(0); i++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(ds_op(i), t1(i * n))); - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, R2COp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - ExecType exec{}; - using ComplexType = detail::complex_from_scalar_t; - - // r2c requires FFT support, so we need to check the executor here - if constexpr (!detail::CheckFFTSupport()) { - GTEST_SKIP(); - } - - const int N1 = 5; - const int N2 = 6; - - auto t1 = make_tensor({N1}); - auto t2 = make_tensor({N2}); - auto T1 = make_tensor({N1}); - auto T2 = make_tensor({N2}); - - for (int i = 0; i < N1; i++) { t1(i) = static_cast(i+1); } - for (int i = 0; i < N2; i++) { t2(i) = static_cast(i+1); } - exec.sync(); - - const cuda::std::array T1_expected = {{ - { 15.0, 0.0 }, { -2.5, static_cast(3.4409548) }, { -2.5, static_cast(0.81229924) }, - { -2.5, static_cast(-0.81229924) }, { -2.5, static_cast(-3.4409548) } - }}; - - const cuda::std::array T2_expected = {{ - { 21.0, 0.0 }, { -3.0, static_cast(5.19615242) }, { -3.0, static_cast(1.73205081) }, - { -3.0, static_cast(-4.44089210e-16) }, { -3.0, static_cast(-1.73205081) }, - { -3.0, static_cast(-5.19615242) } - }}; - - const TestType thresh = static_cast(1.0e-6); - - // Test the regular r2c path with fft() deducing the transform size - (T1 = r2c(fft(t1), N1)).run(exec); - (T2 = r2c(fft(t2), N2)).run(exec); - - exec.sync(); - - for (int i = 0; i < N1; i++) { - ASSERT_NEAR(T1(i).real(), T1_expected[i].real(), thresh); - ASSERT_NEAR(T1(i).imag(), T1_expected[i].imag(), thresh); - } - - for (int i = 0; i < N2; i++) { - ASSERT_NEAR(T2(i).real(), T2_expected[i].real(), thresh); - ASSERT_NEAR(T2(i).imag(), T2_expected[i].imag(), thresh); - } - - // Test the r2c path when specifying the fft() transform size - (T1 = r2c(fft(t1, N1), N1)).run(exec); - (T2 = r2c(fft(t2, N2), N2)).run(exec); - - exec.sync(); - - for (int i = 0; i < N1; i++) { - ASSERT_NEAR(T1(i).real(), T1_expected[i].real(), thresh); - ASSERT_NEAR(T1(i).imag(), T1_expected[i].imag(), thresh); - } - - for (int i = 0; i < N2; i++) { - ASSERT_NEAR(T2(i).real(), T2_expected[i].real(), thresh); - ASSERT_NEAR(T2(i).imag(), T2_expected[i].imag(), thresh); - } - - // Add an ifft to the composition to return the original tensor, - // but now in complex rather than real form. The imaginary components - // should be ~0. - (T1 = ifft(r2c(fft(t1), N1))).run(exec); - (T2 = ifft(r2c(fft(t2), N2))).run(exec); - - exec.sync(); - - for (int i = 0; i < N1; i++) { - ASSERT_NEAR(T1(i).real(), t1(i), thresh); - ASSERT_NEAR(T1(i).imag(), static_cast(0.0), thresh); - } - - for (int i = 0; i < N2; i++) { - ASSERT_NEAR(T2(i).real(), t2(i), thresh); - ASSERT_NEAR(T2(i).imag(), static_cast(0.0), thresh); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsFloatNonHalf, FFTShiftWithTransform) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - using inner_type = typename inner_op_type_t::type; - using complex_type = detail::complex_from_scalar_t; - - if constexpr (!detail::CheckFFTSupport()) { - GTEST_SKIP(); - } - - ExecType exec{}; - - [[maybe_unused]] const inner_type thresh = static_cast(1.0e-6); - - // Verify that fftshift1D/ifftshift1D work with nested transforms. - // These tests are limited to complex-to-complex transforms where we have matched - // dimensions and types for the inputs/outputs. Adding tests that include real-to-complex - // or complex-to-real fft compositions is TBD. - if constexpr (is_complex_v) - { - const int N1 = 3; - const int N2 = 4; - - auto t3 = make_tensor({N1}); - auto t4 = make_tensor({N2}); - auto T3 = make_tensor({N1}); - auto T4 = make_tensor({N2}); - - const cuda::std::array t3_vals = {{ { 1.0, 0.0 }, { 2.0, 0.0 }, { 3.0, 0.0 } }}; - const cuda::std::array t4_vals = {{ { 1.0, 0.0 }, { 2.0, 0.0 }, { 3.0, 0.0 }, { 4.0, 0.0 } }}; - - for (int i = 0; i < N1; i++) { t3(i) = t3_vals[i]; }; - for (int i = 0; i < N2; i++) { t4(i) = t4_vals[i]; }; - - exec.sync(); - - (T3 = fftshift1D(fft(t3))).run(exec); - (T4 = fftshift1D(fft(t4))).run(exec); - - exec.sync(); - - const cuda::std::array T3_expected = {{ - { -1.5, static_cast(-0.8660254) }, { 6.0, 0.0 }, { -1.5, static_cast(0.8660254) } - }}; - const cuda::std::array T4_expected = {{ - { -2.0, 0.0 }, { -2.0, -2.0 }, { 10.0, 0.0 }, { -2.0, 2.0 } - }}; - - for (int i = 0; i < N1; i++) { - ASSERT_NEAR(T3(i).real(), T3_expected[i].real(), thresh); - ASSERT_NEAR(T3(i).imag(), T3_expected[i].imag(), thresh); - } - - for (int i = 0; i < N2; i++) { - ASSERT_NEAR(T4(i).real(), T4_expected[i].real(), thresh); - ASSERT_NEAR(T4(i).imag(), T4_expected[i].imag(), thresh); - } - - (T3 = ifftshift1D(fft(t3))).run(exec); - (T4 = ifftshift1D(fft(t4))).run(exec); - - exec.sync(); - - const cuda::std::array T3_ifftshift_expected = {{ - { -1.5, static_cast(0.8660254) }, { -1.5, static_cast(-0.8660254) }, { 6.0, 0.0 } - }}; - - for (int i = 0; i < N1; i++) { - ASSERT_NEAR(T3(i).real(), T3_ifftshift_expected[i].real(), thresh); - ASSERT_NEAR(T3(i).imag(), T3_ifftshift_expected[i].imag(), thresh); - } - - // For even length vectors, fftshift() and ifftshift() are identical - for (int i = 0; i < N2; i++) { - ASSERT_NEAR(T4(i).real(), T4_expected[i].real(), thresh); - ASSERT_NEAR(T4(i).imag(), T4_expected[i].imag(), thresh); - } - } - - // Verify that fftshift2D/ifftshift2D work with nested transforms. We do not - // check correctness here, but there are fftshift2D correctness tests elsewhere. - if constexpr (is_complex_v) { - [[maybe_unused]] const int N = 4; - - auto x = make_tensor({N,N}); - auto X = make_tensor({N,N}); - - (x = static_cast(0)).run(exec); - - (X = fftshift2D(fft2(x))).run(exec); - (X = fftshift2D(ifft2(x))).run(exec); - (X = ifftshift2D(fft2(x))).run(exec); - (X = ifftshift2D(ifft2(x))).run(exec); - - exec.sync(); - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, ShiftOp) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t count0 = 100; - index_t count1 = 201; - tensor_t t2({count0, count1}); - tensor_t t2s({count0, count1}); - tensor_t t2s2({count0, count1}); - auto t0 = make_tensor({}); - t0() = -5; - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - t2(i, j) = static_cast>(i * count1 + j); - } - } - - { - // example-begin shift-test-1 - // Shift the first dimension of "t2" by -5 so the 5th element of "t2" is the first element of "t2s" - (t2s = shift<0>(t2, -5)).run(exec); - // example-end shift-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE( - MatXUtils::MatXTypeCompare(t2s(i, j), t2((i + 5) % count0, j))); - } - } - } - - { - (t2s = shift<0>(t2, t0)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE( - MatXUtils::MatXTypeCompare(t2s(i, j), t2((i + 5) % count0, j))); - } - } - } - - { - (t2s = shift<1>(t2, -5)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE( - MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, (j + 5) % count1))); - } - } - } - - { - (t2s = shift<1,0>(t2, -5, -6)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare( - t2s(i, j), t2((i + 6) % count0, (j + 5) % count1))); - } - } - } - - { - // example-begin fftshift2D-test-1 - (t2s = fftshift2D(t2)).run(exec); - // example-end fftshift2D-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare( - t2s(i, j), t2((i + (count0 + 1) / 2) % count0, - (j + (count1 + 1) / 2) % count1))); - } - } - } - - { - // example-begin ifftshift2D-test-1 - (t2s = ifftshift2D(t2)).run(exec); - // example-end ifftshift2D-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare( - t2s(i, j), - t2((i + (count0) / 2) % count0, (j + (count1) / 2) % count1))); - } - } - } - - // Right shifts - { - (t2s = shift<0>(t2, 5)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - index_t idim = i < 5 ? (t2.Size(0) - 5 + i) : (i - 5); - ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(idim, j))); - } - } - } - - { - (t2s = shift<1>(t2, 5)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - index_t jdim = j < 5 ? (t2.Size(1) - 5 + j) : (j - 5); - ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, jdim))); - } - } - } - - // Large shifts - { - (t2s = shift<0>(t2, -t2.Size(0) * 4)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, j))); - } - } - } - - { - // Shift 4 times the size back, minus one. This should be equivalent to - // simply shifting by -1 - (t2s = shift<0>(t2, -t2.Size(0) * 4 - 1)).run(exec); - (t2s2 = shift<0>(t2, -1)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2s2(i, j))); - } - } - } - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsNumericAllExecs, Reverse) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t count0 = 100; - index_t count1 = 200; - tensor_t t2({count0, count1}); - tensor_t t2r({count0, count1}); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - t2(i, j) = static_cast>(i * count1 + j); - } - } - - { - // example-begin reverse-test-1 - // Reverse the values of t2 along dimension 0 - (t2r = reverse<0>(t2)).run(exec); - // example-end reverse-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2r(i, j), t2(count0 - i - 1, j))); - } - } - } - - { - (t2r = reverse<1>(t2)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2r(i, j), t2(i, count1 - j - 1))); - } - } - } - - { - (t2r = reverse<0,1>(t2)).run(exec); - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE(MatXUtils::MatXTypeCompare( - t2r(i, j), t2(count0 - i - 1, count1 - j - 1))); - } - } - } - - // Flip versions - { - // example-begin flipud-test-1 - (t2r = flipud(t2)).run(exec); - // example-end flipud-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2r(i, j), t2(count0 - i - 1, j))); - } - } - } - - { - // example-begin fliplr-test-1 - (t2r = fliplr(t2)).run(exec); - // example-end fliplr-test-1 - exec.sync(); - - for (index_t i = 0; i < count0; i++) { - for (index_t j = 0; j < count1; j++) { - EXPECT_TRUE( - MatXUtils::MatXTypeCompare(t2r(i, j), t2(i, count1 - j - 1))); - } - } - } - - MATX_EXIT_HANDLER(); -} - -TEST(OperatorTests, Cast) -{ - MATX_ENTER_HANDLER(); - index_t count0 = 4; - auto t = make_tensor({count0}); - auto t2 = make_tensor({count0}); - auto to = make_tensor({count0}); - - cudaExecutor exec{}; - - t.SetVals({126, 126, 126, 126}); - t2.SetVals({126, 126, 126, 126}); - - // example-begin as_type-test-1 - (to = as_type(t + t2)).run(exec); - // example-end as_type-test-1 - exec.sync(); - - for (int i = 0; i < t.Size(0); i++) { - ASSERT_EQ(to(i), -4); // -4 from 126 + 126 wrap-around - } - - // example-begin as_int8-test-1 - (to = as_int8(t + t2)).run(exec); - // example-end as_int8-test-1 - exec.sync(); - - for (int i = 0; i < t.Size(0); i++) { - ASSERT_EQ(to(i), -4); // -4 from 126 + 126 wrap-around - } - - // example-begin as_complex_float-test-1 - auto c32 = make_tensor>({}); - auto s64 = make_tensor({}); - s64.SetVals({5.0}); - (c32 = as_complex_float(s64)).run(); - // c32() will be (5.0f, 0.0f) - // example-end as_complex_float-test-1 - - // example-begin as_complex_double-test-1 - auto c64 = make_tensor>({}); - auto s32 = make_tensor({}); - s32.SetVals({3.0f}); - (c64 = as_complex_double(s32)).run(); - // c64() will be (3.0, 0.0) - // example-end as_complex_double-test-1 - - cudaStreamSynchronize(0); - - ASSERT_EQ(c32().real(), 5.0f); - ASSERT_EQ(c32().imag(), 0.0f); - ASSERT_EQ(c64().real(), 3.0); - ASSERT_EQ(c64().imag(), 0.0); - - (c32 = as_complex_float(s32)).run(); - (c64 = as_complex_double(s64)).run(); - cudaStreamSynchronize(0); - - ASSERT_EQ(c32().real(), 3.0f); - ASSERT_EQ(c32().imag(), 0.0f); - ASSERT_EQ(c64().real(), 5.0); - ASSERT_EQ(c64().imag(), 0.0); - - MATX_EXIT_HANDLER(); -} - -TEST(OperatorTests, ComplexCastExceptions) -{ - MATX_ENTER_HANDLER(); - index_t count0 = 4; - auto t = make_tensor({count0}); - auto t2 = make_tensor({count0}); - auto to = make_tensor({count0}); - - cudaExecutor exec{}; - - const int N = 3; - cuda::std::array real_dims, imag_dims; - real_dims.fill(5); - imag_dims.fill(5); - - auto out = make_tensor>(real_dims); - auto test_code = [&real_dims, &imag_dims]() { - auto re = make_tensor(real_dims); - auto im = make_tensor(imag_dims); - [[maybe_unused]] auto op = as_complex_float(re, im); - }; - - for (int i = 0; i < N; i++) { - real_dims[i] = 6; - ASSERT_THROW({ test_code(); }, matx::detail::matxException); - real_dims[i] = 5; - - imag_dims[i] = 6; - ASSERT_THROW({ test_code(); }, matx::detail::matxException); - imag_dims[i] = 5; - } - - ASSERT_NO_THROW({ test_code(); }); - - MATX_EXIT_HANDLER(); -} - -TYPED_TEST(OperatorTestsCastToFloatAllExecs, ComplexCast) -{ - MATX_ENTER_HANDLER(); - - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - // 0D tensor tests - { - // example-begin as_complex_double-test-2 - auto c64 = make_tensor>({}); - auto in_real = make_tensor({}); - auto in_imag = make_tensor({}); - in_real.SetVals({3}); - in_imag.SetVals({5}); - (c64 = as_complex_double(in_real, in_imag)).run(exec); - // c64() will be (3.0, 5.0) - // example-end as_complex_double-test-2 - exec.sync(); - - ASSERT_EQ(c64().real(), 3.0); - ASSERT_EQ(c64().imag(), 5.0); - } - { - // example-begin as_complex_float-test-2 - auto c32 = make_tensor>({}); - auto in_real = make_tensor({}); - auto in_imag = make_tensor({}); - in_real.SetVals({3}); - in_imag.SetVals({5}); - (c32 = as_complex_float(in_real, in_imag)).run(exec); - // c32() will be (3.0f, 5.0f) - // example-end as_complex_float-test-2 - exec.sync(); - - ASSERT_EQ(c32().real(), 3.0f); - ASSERT_EQ(c32().imag(), 5.0f); - } - - // 2D tensor tests - { - const int N = 4; - auto c32 = make_tensor>({N,N}); - auto c64 = make_tensor>({N,N}); - auto in_real = make_tensor({N,N}); - auto in_imag = make_tensor({N,N}); - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - in_real(i,j) = static_cast(4); - in_imag(i,j) = static_cast(6); - } - } - - exec.sync(); - - (c32 = as_complex_float(in_real, in_imag)).run(exec); - (c64 = as_complex_double(in_real, in_imag)).run(exec); - - exec.sync(); - - for (int i = 0; i < N; i++) { - for (int j = 0; j < N; j++) { - ASSERT_EQ(c32(i,j).real(), 4.0f); - ASSERT_EQ(c32(i,j).imag(), 6.0f); - ASSERT_EQ(c64(i,j).real(), 4.0); - ASSERT_EQ(c64(i,j).imag(), 6.0); - } - } - } - - MATX_EXIT_HANDLER(); -} - -template -TypeParam legendre_check(int n, int m, TypeParam x) { - if (m > n ) return 0; - - TypeParam a = detail::_internal_sqrt(TypeParam(1)-x*x); - // first we will move move along diagonal - - // initialize registers - TypeParam d1 = 1, d0; - - for(int i=0; i < m; i++) { - // advance diagonal (shift) - d0 = d1; - // compute next term using recurrence relationship - d1 = -TypeParam(2*i+1)*a*d0; - } - - // next we will move to the right till we get to the correct entry - - // initialize registers - TypeParam p0, p1 = 0, p2 = d1; - - for(int l=m; l; - using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - - ExecType exec{}; - - index_t size = 11; - int order = 5; - - { // vector for n and m - // example-begin legendre-test-1 - auto n = range<0, 1, int>({order}, 0, 1); - auto m = range<0, 1, int>({order}, 0, 1); - auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); - - auto out = make_tensor({order, order, size}); - - (out = legendre(n, m, x)).run(exec); - // example-end legendre-test-1 - - exec.sync(); - - for(int j = 0; j < order; j++) { - for(int p = 0; p < order; p++) { - for(int i = 0 ; i < size; i++) { - if constexpr (is_matx_half_v) { - ASSERT_NEAR(out(p,j,i), legendre_check(p, j, x(i)),50.0); - } - else { - ASSERT_NEAR(out(p,j,i), legendre_check(p, j, x(i)),.0001); - } - } - } - } - } - - { // constant for n - auto m = range<0, 1, int>({order}, 0, 1); - auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); - - auto out = make_tensor({order, size}); - - (out = lcollapse<2>(legendre(order, m, x))).run(exec); - - exec.sync(); - - for(int i = 0 ; i < size; i++) { - for(int p = 0; p < order; p++) { - if constexpr (is_matx_half_v) { - ASSERT_NEAR(out(p,i), legendre_check(order, p, x(i)),50.0); - } - else { - ASSERT_NEAR(out(p,i), legendre_check(order, p, x(i)),.0001); - } - } - } - } - - { // taking a constant for m and n; - auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); - - auto out = make_tensor({size}); - - (out = lcollapse<3>(legendre(order, order, x))).run(exec); - - exec.sync(); - - for(int i = 0 ; i < size; i++) { - if constexpr (is_matx_half_v) { - ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),50.0); - } - else { - ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),.0001); - } - } - } - - { // taking a rank0 tensor for m and constant for n - auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); - auto m = make_tensor({}); - auto out = make_tensor({size}); - m() = order; - - (out = lcollapse<3>(legendre(order, m, x))).run(exec); - - exec.sync(); - - for(int i = 0 ; i < size; i++) { - if constexpr (is_matx_half_v) { - ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),50.0); - } - else { - ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),.0001); - } - } - } - MATX_EXIT_HANDLER(); -} - -TEST(OperatorTestsAdvanced, AdvancedRemapOp) -{ - typedef cuda::std::complex complex; - cudaExecutor exec{}; - MATX_ENTER_HANDLER(); - - int I = 4; - int J = 4; - int K = 14; - int L = 133; - - int F = 4096; - int P = 288; - - int M = 2; - - auto idx = matx::make_tensor({M}); - - idx(0) = 1; - idx(1) = 3; - - auto A = matx::make_tensor({I, J, K, L}); - //collapsed tensor - auto B = matx::make_tensor({I * M * K, L}); - - auto index = [&] (int i, int j, int k, int l) { - return i * J * K * L + - j * K * L + - k * L + - l; - }; - for (int i = 0; i < I ; i++) { - for (int j = 0; j < J ; j++) { - for (int k = 0; k < K ; k++) { - for (int l = 0; l < L ; l++) { - float val = (float)index(i,j,k,l); - A(i,j,k,l) = complex(val, val/100); - } - } - } - } - - (B = 0).run(exec); - - auto rop = remap<1>(A, idx); - auto lop = lcollapse<3>(rop); - - ASSERT_EQ(lop.Rank() , 2); - ASSERT_EQ(lop.Size(1) , A.Size(3)); - ASSERT_EQ(lop.Size(0) , I * M * K); - - (B = lop).run(exec); - - exec.sync(); - - for (int i = 0; i < I; i++) { - for (int m = 0; m < M; m++) { - for (int k = 0; k < K; k++) { - for (int l = 0; l < L; l++) { - int j = idx(m); - int fidx = i * M * K + m * K + k; - float val = (float)index(i,j,k,l); - complex expected_val = complex(val,val/100); - complex a_val = A(i,j,k,l); - complex b_val = B(fidx, l); - complex lop_val = lop(fidx, l); - complex rop_val = rop(i, m, k, l); - - ASSERT_EQ(a_val, expected_val); - ASSERT_EQ(rop_val, expected_val); - ASSERT_EQ(lop_val, expected_val); - ASSERT_EQ(b_val, expected_val); - - ASSERT_EQ(B(fidx, l) , lop(fidx, l)); - } - } - } - } - - - // convolution test - auto O1 = matx::make_tensor({I, J, K, F + P + L - 1}); - auto O2 = matx::make_tensor({I, J, K, F + P + L - 1}); - auto O3 = matx::make_tensor({I, J, K, F + P + L - 1}); - auto O4 = matx::make_tensor({I, J, K, F + P + L - 1}); - - auto C = matx::make_tensor({I, K, F + P}); - //collapsed tensor - auto D = matx::make_tensor({I * M * K, F + P}); - - auto indexc = [&] (int i, int j, int k) { - return i * C.Size(1) * C.Size(2) + - j * C.Size(2) + - k; - }; - - for (int i = 0; i < I ; i++) { - for (int j = 0; j < J ; j++) { - for (int k = 0; k < K ; k++) { - float val = (float) indexc(i,j,k); - C(i,j,k) = complex(val, val/100); - } - } - } - - exec.sync(); - - auto o1op = lcollapse<3>(remap<1>(O1, idx)); - auto o2op = lcollapse<3>(remap<1>(O2, idx)); - auto o3op = lcollapse<3>(remap<1>(O3, idx)); - auto o4op = lcollapse<3>(remap<1>(O4, idx)); - - auto cop = C.Clone<4>({matxKeepDim, M, matxKeepDim, matxKeepDim}); - auto rcop = lcollapse<3>(remap<1>(cop, idx)); - - (O1 = 1).run(exec); - (O2 = 2).run(exec); - (O3 = 3).run(exec); - (O4 = 4).run(exec); - - (B = lop).run(exec); - (D = rcop).run(exec); - - // two operators as input - (o1op = conv1d(lop, rcop, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); - - // one tensor and one operators as input - (o2op = conv1d(B, rcop, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); - - // one tensor and one operators as input - (o3op = conv1d(lop, D, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); - - //two tensors as input - (o4op = conv1d(B, D, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); - - exec.sync(); - - for (int i = 0; i < o1op.Size(0); i++) { - for (int l = 0; l < o1op.Size(1); l++) { - ASSERT_EQ(o1op(i,l), o2op(i,l)); - ASSERT_EQ(o2op(i,l), o3op(i,l)); - ASSERT_EQ(o3op(i,l), o4op(i,l)); - } - } - - MATX_EXIT_HANDLER(); -} - - -TYPED_TEST(OperatorTestsFloatAllExecs, Print) -{ - MATX_ENTER_HANDLER(); - using TestType = cuda::std::tuple_element_t<0, TypeParam>; - - auto t1 = make_tensor({3}); - auto r1 = ones(t1.Shape()); - print(r1); - - auto t3 = matx::make_tensor({3, 2, 20}); - print(matx::ones(t3.Shape()), 1, 0, 2); - - MATX_EXIT_HANDLER(); -} diff --git a/test/00_operators/abs2_test.cu b/test/00_operators/abs2_test.cu new file mode 100644 index 00000000..ce7aad70 --- /dev/null +++ b/test/00_operators/abs2_test.cu @@ -0,0 +1,68 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, Abs2) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + using inner_type = typename inner_op_type_t::type; + + ExecType exec{}; + + if constexpr (std::is_same_v> && + std::is_same_v) { + // example-begin abs2-test-1 + auto x = make_tensor>({}); + auto y = make_tensor({}); + x() = { 1.5f, 2.5f }; + (y = abs2(x)).run(exec); + exec.sync(); + ASSERT_NEAR(y(), 1.5f*1.5f+2.5f*2.5f, 1.0e-6); + // example-end abs2-test-1 + } + + auto x = make_tensor({}); + auto y = make_tensor({}); + if constexpr (is_complex_v) { + x() = TestType{2.0, 2.0}; + (y = abs2(x)).run(exec); + exec.sync(); + ASSERT_NEAR(y(), 8.0, 1.0e-6); + } else { + x() = 2.0; + (y = abs2(x)).run(exec); + exec.sync(); + ASSERT_NEAR(y(), 4.0, 1.0e-6); + + // Test with higher rank tensor + auto x3 = make_tensor({3,3,3}); + auto y3 = make_tensor({3,3,3}); + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (int k = 0; k < 3; k++) { + x3(i,j,k) = static_cast(i*9 + j*3 + k); + } + } + } + + (y3 = abs2(x3)).run(exec); + exec.sync(); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + for (int k = 0; k < 3; k++) { + TestType v = static_cast(i*9 + j*3 + k); + ASSERT_NEAR(y3(i,j,k), v*v, 1.0e-6); + } + } + } + } + + MATX_EXIT_HANDLER(); +} diff --git a/test/00_operators/advanced_op_test.cu b/test/00_operators/advanced_op_test.cu new file mode 100644 index 00000000..7993a09a --- /dev/null +++ b/test/00_operators/advanced_op_test.cu @@ -0,0 +1,142 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsNumericNoHalfAllExecs, AdvancedOperators) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 100; + + tensor_t a({count}); + tensor_t b({count}); + tensor_t c({count}); + + for (index_t i = 0; i < count; i++) { + a(i) = static_cast>(i); + b(i) = static_cast>(i + 100); + } + + { + (c = a + b).run(exec); + + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = static_cast>(i); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(c(i), tcnt + (tcnt + (TestType)100))); + } + } + + { + (c = a * b).run(exec); + + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = static_cast>(i); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(c(i), tcnt * (tcnt + (TestType)100))); + } + } + + { + (c = a * b + a).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = static_cast>(i); + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + c(i), tcnt * (tcnt + (TestType)100) + tcnt)); + } + } + + { + + (c = a * b + a * (TestType)4.0f).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = static_cast>(i); + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + c(i), tcnt * (tcnt + (TestType)100.0f) + tcnt * (TestType)4)); + } + } + MATX_EXIT_HANDLER(); +} + + + +TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, AdvancedOperators) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 10; + + tensor_t a({count}); + tensor_t b({count}); + tensor_t c({count}); + + for (index_t i = 0; i < count; i++) { + a(i) = (TestType)i; + b(i) = (TestType)(i + 2); + } + + { + (c = a + b).run(exec); + + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = (TestType)i; + EXPECT_TRUE(MatXUtils::MatXTypeCompare(c(i), (TestType)((float)tcnt + ((float)tcnt + 2.0f)))); + } + } + + { + (c = a * b).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = (TestType)i; + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(c(i), (float)tcnt * ((float)tcnt + 2.0f))); + } + } + + { + (c = a * b + a).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = (TestType)i; + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + c(i), (float)tcnt * ((float)tcnt + 2.0f) + (float)tcnt)); + } + } + + { + + (c = a * b + a * (TestType)2.0f).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + TestType tcnt = (TestType)i; + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + c(i), (float)tcnt * ((float)tcnt + 2.0f) + (float)tcnt * 2.0f)); + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/advanced_remap_test.cu b/test/00_operators/advanced_remap_test.cu new file mode 100644 index 00000000..37cd1052 --- /dev/null +++ b/test/00_operators/advanced_remap_test.cu @@ -0,0 +1,155 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TEST(OperatorTestsAdvanced, AdvancedRemapOp) +{ + typedef cuda::std::complex complex; + cudaExecutor exec{}; + MATX_ENTER_HANDLER(); + + int I = 4; + int J = 4; + int K = 14; + int L = 133; + + int F = 4096; + int P = 288; + + int M = 2; + + auto idx = matx::make_tensor({M}); + + idx(0) = 1; + idx(1) = 3; + + auto A = matx::make_tensor({I, J, K, L}); + //collapsed tensor + auto B = matx::make_tensor({I * M * K, L}); + + auto index = [&] (int i, int j, int k, int l) { + return i * J * K * L + + j * K * L + + k * L + + l; + }; + for (int i = 0; i < I ; i++) { + for (int j = 0; j < J ; j++) { + for (int k = 0; k < K ; k++) { + for (int l = 0; l < L ; l++) { + float val = (float)index(i,j,k,l); + A(i,j,k,l) = complex(val, val/100); + } + } + } + } + + (B = 0).run(exec); + + auto rop = remap<1>(A, idx); + auto lop = lcollapse<3>(rop); + + ASSERT_EQ(lop.Rank() , 2); + ASSERT_EQ(lop.Size(1) , A.Size(3)); + ASSERT_EQ(lop.Size(0) , I * M * K); + + (B = lop).run(exec); + + exec.sync(); + + for (int i = 0; i < I; i++) { + for (int m = 0; m < M; m++) { + for (int k = 0; k < K; k++) { + for (int l = 0; l < L; l++) { + int j = idx(m); + int fidx = i * M * K + m * K + k; + float val = (float)index(i,j,k,l); + complex expected_val = complex(val,val/100); + complex a_val = A(i,j,k,l); + complex b_val = B(fidx, l); + complex lop_val = lop(fidx, l); + complex rop_val = rop(i, m, k, l); + + ASSERT_EQ(a_val, expected_val); + ASSERT_EQ(rop_val, expected_val); + ASSERT_EQ(lop_val, expected_val); + ASSERT_EQ(b_val, expected_val); + + ASSERT_EQ(B(fidx, l) , lop(fidx, l)); + } + } + } + } + + + // convolution test + auto O1 = matx::make_tensor({I, J, K, F + P + L - 1}); + auto O2 = matx::make_tensor({I, J, K, F + P + L - 1}); + auto O3 = matx::make_tensor({I, J, K, F + P + L - 1}); + auto O4 = matx::make_tensor({I, J, K, F + P + L - 1}); + + auto C = matx::make_tensor({I, K, F + P}); + //collapsed tensor + auto D = matx::make_tensor({I * M * K, F + P}); + + auto indexc = [&] (int i, int j, int k) { + return i * C.Size(1) * C.Size(2) + + j * C.Size(2) + + k; + }; + + for (int i = 0; i < I ; i++) { + for (int j = 0; j < J ; j++) { + for (int k = 0; k < K ; k++) { + float val = (float) indexc(i,j,k); + C(i,j,k) = complex(val, val/100); + } + } + } + + exec.sync(); + + auto o1op = lcollapse<3>(remap<1>(O1, idx)); + auto o2op = lcollapse<3>(remap<1>(O2, idx)); + auto o3op = lcollapse<3>(remap<1>(O3, idx)); + auto o4op = lcollapse<3>(remap<1>(O4, idx)); + + auto cop = C.Clone<4>({matxKeepDim, M, matxKeepDim, matxKeepDim}); + auto rcop = lcollapse<3>(remap<1>(cop, idx)); + + (O1 = 1).run(exec); + (O2 = 2).run(exec); + (O3 = 3).run(exec); + (O4 = 4).run(exec); + + (B = lop).run(exec); + (D = rcop).run(exec); + + // two operators as input + (o1op = conv1d(lop, rcop, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); + + // one tensor and one operators as input + (o2op = conv1d(B, rcop, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); + + // one tensor and one operators as input + (o3op = conv1d(lop, D, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); + + //two tensors as input + (o4op = conv1d(B, D, matx::matxConvCorrMode_t::MATX_C_MODE_FULL)).run(exec); + + exec.sync(); + + for (int i = 0; i < o1op.Size(0); i++) { + for (int l = 0; l < o1op.Size(1); l++) { + ASSERT_EQ(o1op(i,l), o2op(i,l)); + ASSERT_EQ(o2op(i,l), o3op(i,l)); + ASSERT_EQ(o3op(i,l), o4op(i,l)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/angle_test.cu b/test/00_operators/angle_test.cu new file mode 100644 index 00000000..715f56ae --- /dev/null +++ b/test/00_operators/angle_test.cu @@ -0,0 +1,32 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST_SUITE(OperatorTestsComplexTypesAllExecs, MatXComplexTypesAllExecs); + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, AngleOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + + // example-begin angle-test-1 + (tov0 = angle(tiv0)).run(exec); + // example-end angle-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_angle(c))); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/at_test.cu b/test/00_operators/at_test.cu new file mode 100644 index 00000000..f04a608f --- /dev/null +++ b/test/00_operators/at_test.cu @@ -0,0 +1,52 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, AtOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto t2 = make_tensor({2,10}); + + // example-begin at-test-1 + auto t1 = make_tensor({10}); + auto t0 = make_tensor({}); + + t1.SetVals({10, 20, 30, 40, 50, 60, 70, 80, 90, 100}); + (t2 = t1).run(exec); + + // Select the fourth element from `t1` as part of the execution. Value should match + // `t1(3)` after execution + (t0 = at(t1, 3)).run(exec); + // example-end at-test-1 + exec.sync(); + + ASSERT_EQ(t0(), t1(3)); + + (t0 = at(t2, 1, 4)).run(exec); + exec.sync(); + + ASSERT_EQ(t0(), t2(1, 4)); + + if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) { + using ComplexType = detail::complex_from_scalar_t; + auto c0 = make_tensor({}); + (c0 = at(fft(t1), 0)).run(exec); + exec.sync(); + + // The first component of the FFT output (DC) is the sum of all elements, so + // 10+20+...+100 = 550. The imaginary component should be 0. + ASSERT_NEAR(c0().real(), static_cast(550.0), static_cast(1.0e-6)); + ASSERT_NEAR(c0().imag(), static_cast(0.0), static_cast(1.0e-6)); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/base_op_test.cu b/test/00_operators/base_op_test.cu new file mode 100644 index 00000000..fc6cb3bf --- /dev/null +++ b/test/00_operators/base_op_test.cu @@ -0,0 +1,33 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsAllExecs, BaseOp) +{ + MATX_ENTER_HANDLER(); + + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto A = make_tensor({10,20}); + auto op = A + A; + + EXPECT_TRUE(op.Size(0) == A.Size(0)); + EXPECT_TRUE(op.Size(1) == A.Size(1)); + + auto shape = op.Shape(); + + EXPECT_TRUE(shape[0] == A.Size(0)); + EXPECT_TRUE(shape[1] == A.Size(1)); + + EXPECT_TRUE(A.TotalSize() == op.TotalSize()); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/broadcast_test.cu b/test/00_operators/broadcast_test.cu new file mode 100644 index 00000000..3132e33a --- /dev/null +++ b/test/00_operators/broadcast_test.cu @@ -0,0 +1,75 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsNumericAllExecs, Broadcast) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + { + auto t0 = make_tensor({}); + tensor_t t4i({10, 20, 30, 40}); + tensor_t t4o({10, 20, 30, 40}); + (t4o = t0).run(exec); + + t0() = (TestType)2.0f; + for (index_t i = 0; i < t4i.Size(0); i++) { + for (index_t j = 0; j < t4i.Size(1); j++) { + for (index_t k = 0; k < t4i.Size(2); k++) { + for (index_t l = 0; l < t4i.Size(3); l++) { + t4i(i, j, k, l) = + static_cast>(i + j + k + l); + } + } + } + } + + (t4o = t4i * t0).run(exec); + exec.sync(); + + for (index_t i = 0; i < t4o.Size(0); i++) { + for (index_t j = 0; j < t4o.Size(1); j++) { + for (index_t k = 0; k < t4o.Size(2); k++) { + for (index_t l = 0; l < t4o.Size(3); l++) { + if constexpr (IsHalfType()) { + MATX_ASSERT_EQ(t4o(i, j, k, l), + (TestType)t4i(i, j, k, l) * (TestType)t0()); + } + else { + MATX_ASSERT_EQ(t4o(i, j, k, l), t4i(i, j, k, l) * t0()); + } + } + } + } + } + (t4o = t0 * t4i).run(exec); + exec.sync(); + + for (index_t i = 0; i < t4o.Size(0); i++) { + for (index_t j = 0; j < t4o.Size(1); j++) { + for (index_t k = 0; k < t4o.Size(2); k++) { + for (index_t l = 0; l < t4o.Size(3); l++) { + if constexpr (IsHalfType()) { + MATX_ASSERT_EQ(t4o(i, j, k, l), + (TestType)t0() * (TestType)t4i(i, j, k, l)); + } + else { + MATX_ASSERT_EQ(t4o(i, j, k, l), t0() * t4i(i, j, k, l)); + } + } + } + } + } + + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/cast_test.cu b/test/00_operators/cast_test.cu new file mode 100644 index 00000000..b37c953c --- /dev/null +++ b/test/00_operators/cast_test.cu @@ -0,0 +1,73 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TEST(OperatorTests, Cast) +{ + MATX_ENTER_HANDLER(); + index_t count0 = 4; + auto t = make_tensor({count0}); + auto t2 = make_tensor({count0}); + auto to = make_tensor({count0}); + + cudaExecutor exec{}; + + t.SetVals({126, 126, 126, 126}); + t2.SetVals({126, 126, 126, 126}); + + // example-begin as_type-test-1 + (to = as_type(t + t2)).run(exec); + // example-end as_type-test-1 + exec.sync(); + + for (int i = 0; i < t.Size(0); i++) { + ASSERT_EQ(to(i), -4); // -4 from 126 + 126 wrap-around + } + + // example-begin as_int8-test-1 + (to = as_int8(t + t2)).run(exec); + // example-end as_int8-test-1 + exec.sync(); + + for (int i = 0; i < t.Size(0); i++) { + ASSERT_EQ(to(i), -4); // -4 from 126 + 126 wrap-around + } + + // example-begin as_complex_float-test-1 + auto c32 = make_tensor>({}); + auto s64 = make_tensor({}); + s64.SetVals({5.0}); + (c32 = as_complex_float(s64)).run(); + // c32() will be (5.0f, 0.0f) + // example-end as_complex_float-test-1 + + // example-begin as_complex_double-test-1 + auto c64 = make_tensor>({}); + auto s32 = make_tensor({}); + s32.SetVals({3.0f}); + (c64 = as_complex_double(s32)).run(); + // c64() will be (3.0, 0.0) + // example-end as_complex_double-test-1 + + cudaStreamSynchronize(0); + + ASSERT_EQ(c32().real(), 5.0f); + ASSERT_EQ(c32().imag(), 0.0f); + ASSERT_EQ(c64().real(), 3.0); + ASSERT_EQ(c64().imag(), 0.0); + + (c32 = as_complex_float(s32)).run(); + (c64 = as_complex_double(s64)).run(); + cudaStreamSynchronize(0); + + ASSERT_EQ(c32().real(), 3.0f); + ASSERT_EQ(c32().imag(), 0.0f); + ASSERT_EQ(c64().real(), 5.0); + ASSERT_EQ(c64().imag(), 0.0); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/clone_add_test.cu b/test/00_operators/clone_add_test.cu new file mode 100644 index 00000000..40de5c96 --- /dev/null +++ b/test/00_operators/clone_add_test.cu @@ -0,0 +1,69 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, CloneAndAdd) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t numSamples = 8; + index_t numPulses = 4; + index_t numPairs = 2; + index_t numBeams = 2; + + tensor_t beamwiseRangeDoppler( + {numBeams, numPulses, numPairs, numSamples}); + tensor_t steeredMx({numBeams, numSamples}); + tensor_t velAccelHypoth({numPulses, numPairs, numSamples}); + + for (index_t i = 0; i < numBeams; i++) { + for (index_t j = 0; j < numSamples; j++) { + steeredMx(i, j) = static_cast((i + 1) * 10 + (j + 1)); + } + } + + for (index_t i = 0; i < numPulses; i++) { + for (index_t j = 0; j < numPairs; j++) { + for (index_t k = 0; k < numSamples; k++) { + velAccelHypoth(i, j, k) = static_cast( + (i + 1) * 10 + (j + 1) * 1 + (k + 1) * 1); + } + } + } + + auto smx = + clone<4>(steeredMx, {matxKeepDim, numPulses, numPairs, matxKeepDim}); + auto vah = clone<4>(velAccelHypoth, + {numBeams, matxKeepDim, matxKeepDim, matxKeepDim}); + + (beamwiseRangeDoppler = smx + vah).run(exec); + + exec.sync(); + for (index_t i = 0; i < numBeams; i++) { + for (index_t j = 0; j < numPulses; j++) { + for (index_t k = 0; k < numPairs; k++) { + for (index_t l = 0; l < numSamples; l++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + beamwiseRangeDoppler(i, j, k, l), + steeredMx(i, l) + velAccelHypoth(j, k, l))); + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + beamwiseRangeDoppler(i, j, k, l), + ((i + 1) * 10 + (l + 1)) // steeredMx + + ((j + 1) * 10 + (k + 1) * 1 + + (l + 1) * 1) // velAccelHypoth + )); + } + } + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/clone_test.cu b/test/00_operators/clone_test.cu new file mode 100644 index 00000000..cb249af3 --- /dev/null +++ b/test/00_operators/clone_test.cu @@ -0,0 +1,230 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, CloneOp) +{ + constexpr int N = 10; + constexpr int M = 12; + constexpr int K = 14; + + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + MATX_ENTER_HANDLER(); + { // clone from 0D + // example-begin clone-test-1 + auto tiv = make_tensor({}); + auto tov = make_tensor({N,M,K}); + + tiv() = 3; + + // Clone "tiv" from a 1D tensor to a 3D tensor + auto op = clone<3>(tiv, {N, M, K}); + // example-end clone-test-1 + + ASSERT_EQ(op.Size(0), N); + ASSERT_EQ(op.Size(1), M); + ASSERT_EQ(op.Size(2), K); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(op(n,m,k) , tiv()); + } + } + } + + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , tiv()); + } + } + } + } + + { // clone from 1D + auto tiv = make_tensor({K}); + auto tov = make_tensor({N,M,K}); + + for(int k = 0; k < K; k++) { + tiv(k) = static_cast::type>(k); + } + + auto op = clone<3>(tiv, {N, M, matxKeepDim}); + + ASSERT_EQ(op.Size(0), N); + ASSERT_EQ(op.Size(1), M); + ASSERT_EQ(op.Size(2), K); + + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(op(n,m,k) , tiv(k)); + } + } + } + + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , tiv(k)); + } + } + } + } + + { // clone from 1D + auto tiv = make_tensor({M}); + auto tov = make_tensor({N,M,K}); + + for(int m = 0; m < K; m++) { + tiv(m) = static_cast::type>(m); + } + + auto op = clone<3>(tiv, {N, matxKeepDim, K}); + + ASSERT_EQ(op.Size(0), N); + ASSERT_EQ(op.Size(1), M); + ASSERT_EQ(op.Size(2), K); + + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(op(n,m,k) , tiv(m)); + } + } + } + + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , tiv(m)); + } + } + } + } + + { // clone from 2D and operator + auto tiv = make_tensor({M,K}); + auto tov = make_tensor({N,M,K}); + + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); + } + } + + auto op = clone<3>(tiv, {N, matxKeepDim, matxKeepDim}); + + ASSERT_EQ(op.Size(0), N); + ASSERT_EQ(op.Size(1), M); + ASSERT_EQ(op.Size(2), K); + + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(op(n,m,k) , tiv(m,k)); + } + } + } + + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , tiv(m,k)); + } + } + } + } + + { // clone from 2D + auto tiv = make_tensor({M,K}); + auto tov = make_tensor({N,M,K}); + + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); + } + } + + const auto op = clone<3>(static_cast::type>(2)*tiv, {N, matxKeepDim, matxKeepDim}); + + ASSERT_EQ(op.Size(0), N); + ASSERT_EQ(op.Size(1), M); + ASSERT_EQ(op.Size(2), K); + + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(op(n,m,k), TestType(2)*tiv(m,k)); + } + } + } + + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , TestType(2)*tiv(m,k)); + } + } + } + } + + if constexpr (is_cuda_executor_v) + { // clone of a nested transform; conv2d currently only has a device executor + auto tiv = make_tensor({M,K}); + auto tov = make_tensor({N,M,K}); + auto delta = make_tensor({1,1}); + + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + tiv(m,k) = static_cast::type>(m*K)+static_cast::type>(k); + } + } + + delta(0,0) = static_cast::type>(1.0); + + exec.sync(); + + (tov = clone<3>(conv2d(tiv, delta, MATX_C_MODE_SAME), {N, matxKeepDim, matxKeepDim})).run(exec); + + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_EQ(tov(n,m,k) , tiv(m,k)); + } + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/collapse_test.cu b/test/00_operators/collapse_test.cu new file mode 100644 index 00000000..92ac409f --- /dev/null +++ b/test/00_operators/collapse_test.cu @@ -0,0 +1,176 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, CollapseOp) +{ + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + using inner_type = typename inner_op_type_t::type; + + ExecType exec{}; + + int N = 10; + int M = 12; + int K = 14; + + + MATX_ENTER_HANDLER(); + auto tiv = make_tensor({N,M,K}); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + tiv(n,m,k) = inner_type(n*M*K + m*K + k); + } + } + } + + { // rcollapse 2 + auto tov = make_tensor({N,M*K}); + + // example-begin rcollapse-test-1 + // Collapse two right-most dimensions together + auto op = rcollapse<2>(tiv); + // example-end rcollapse-test-1 + + EXPECT_TRUE(op.Rank() == 2); + EXPECT_TRUE(op.Size(0) == N); + EXPECT_TRUE(op.Size(1) == M*K); + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n,m*K+k)); + } + } + } + } + + { // lcollapse 12 + auto tov = make_tensor({N*M,K}); + + // example-begin lcollapse-test-1 + // Collapse two left-most dimensions together + auto op = lcollapse<2>(tiv); + // example-end lcollapse-test-1 + + EXPECT_TRUE(op.Rank() == 2); + EXPECT_TRUE(op.Size(0) == N*M); + EXPECT_TRUE(op.Size(1) == K); + + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n*M+m,k)); + } + } + } + } + + { // rcollapse 3 + auto tov = make_tensor({N*M*K}); + + auto op = rcollapse<3>(tiv); + + EXPECT_TRUE(op.Rank() == 1); + EXPECT_TRUE(op.Size(0) == N*M*K); + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n*M*K+m*K+k)); + } + } + } + } + + { // lcollapse 3 + auto tov = make_tensor({N*M*K}); + + auto op = lcollapse<3>(tiv); + + EXPECT_TRUE(op.Rank() == 1); + EXPECT_TRUE(op.Size(0) == N*M*K); + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n*M*K+m*K+k)); + } + } + } + } + + if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) + { // rcollapse with nested transform operator + auto tov = make_tensor({N,M*K}); + auto delta = make_tensor({1,1}); + delta(0,0) = static_cast::type>(1.0); + + auto op = rcollapse<2>(conv2d(tiv, delta, MATX_C_MODE_SAME)); + + EXPECT_TRUE(op.Rank() == 2); + EXPECT_TRUE(op.Size(0) == N); + EXPECT_TRUE(op.Size(1) == M*K); + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n,m*K+k)); + } + } + } + } + + if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) + { // lcollapse with nested transform operator + auto tov = make_tensor({N*M,K}); + auto delta = make_tensor({1,1}); + delta(0,0) = static_cast::type>(1.0); + + auto op = lcollapse<2>(conv2d(tiv, delta, MATX_C_MODE_SAME)); + + EXPECT_TRUE(op.Rank() == 2); + EXPECT_TRUE(op.Size(0) == N*M); + EXPECT_TRUE(op.Size(1) == K); + + (tov = (TestType)0).run(exec); + (tov = op).run(exec); + exec.sync(); + + for(int n = 0; n < N; n++) { + for(int m = 0; m < M; m++) { + for(int k = 0; k < K; k++) { + ASSERT_TRUE(tiv(n,m,k) == tov(n*M+m,k)); + } + } + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/complex_cast_exceptions_test.cu b/test/00_operators/complex_cast_exceptions_test.cu new file mode 100644 index 00000000..6a6ae2f0 --- /dev/null +++ b/test/00_operators/complex_cast_exceptions_test.cu @@ -0,0 +1,44 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TEST(OperatorTests, ComplexCastExceptions) +{ + MATX_ENTER_HANDLER(); + index_t count0 = 4; + auto t = make_tensor({count0}); + auto t2 = make_tensor({count0}); + auto to = make_tensor({count0}); + + cudaExecutor exec{}; + + const int N = 3; + cuda::std::array real_dims, imag_dims; + real_dims.fill(5); + imag_dims.fill(5); + + auto out = make_tensor>(real_dims); + auto test_code = [&real_dims, &imag_dims]() { + auto re = make_tensor(real_dims); + auto im = make_tensor(imag_dims); + [[maybe_unused]] auto op = as_complex_float(re, im); + }; + + for (int i = 0; i < N; i++) { + real_dims[i] = 6; + ASSERT_THROW({ test_code(); }, matx::detail::matxException); + real_dims[i] = 5; + + imag_dims[i] = 6; + ASSERT_THROW({ test_code(); }, matx::detail::matxException); + imag_dims[i] = 5; + } + + ASSERT_NO_THROW({ test_code(); }); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/complex_cast_test.cu b/test/00_operators/complex_cast_test.cu new file mode 100644 index 00000000..520c92f2 --- /dev/null +++ b/test/00_operators/complex_cast_test.cu @@ -0,0 +1,83 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsCastToFloatAllExecs, ComplexCast) +{ + MATX_ENTER_HANDLER(); + + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // 0D tensor tests + { + // example-begin as_complex_double-test-2 + auto c64 = make_tensor>({}); + auto in_real = make_tensor({}); + auto in_imag = make_tensor({}); + in_real.SetVals({3}); + in_imag.SetVals({5}); + (c64 = as_complex_double(in_real, in_imag)).run(exec); + // c64() will be (3.0, 5.0) + // example-end as_complex_double-test-2 + exec.sync(); + + ASSERT_EQ(c64().real(), 3.0); + ASSERT_EQ(c64().imag(), 5.0); + } + { + // example-begin as_complex_float-test-2 + auto c32 = make_tensor>({}); + auto in_real = make_tensor({}); + auto in_imag = make_tensor({}); + in_real.SetVals({3}); + in_imag.SetVals({5}); + (c32 = as_complex_float(in_real, in_imag)).run(exec); + // c32() will be (3.0f, 5.0f) + // example-end as_complex_float-test-2 + exec.sync(); + + ASSERT_EQ(c32().real(), 3.0f); + ASSERT_EQ(c32().imag(), 5.0f); + } + + // 2D tensor tests + { + const int N = 4; + auto c32 = make_tensor>({N,N}); + auto c64 = make_tensor>({N,N}); + auto in_real = make_tensor({N,N}); + auto in_imag = make_tensor({N,N}); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + in_real(i,j) = static_cast(4); + in_imag(i,j) = static_cast(6); + } + } + + exec.sync(); + + (c32 = as_complex_float(in_real, in_imag)).run(exec); + (c64 = as_complex_double(in_real, in_imag)).run(exec); + + exec.sync(); + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + ASSERT_EQ(c32(i,j).real(), 4.0f); + ASSERT_EQ(c32(i,j).imag(), 6.0f); + ASSERT_EQ(c64(i,j).real(), 4.0); + ASSERT_EQ(c64(i,j).imag(), 6.0); + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/complex_type_compatibility_test.cu b/test/00_operators/complex_type_compatibility_test.cu new file mode 100644 index 00000000..d59e8b5a --- /dev/null +++ b/test/00_operators/complex_type_compatibility_test.cu @@ -0,0 +1,111 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +// Testing 4 basic arithmetic operations with complex numbers and non-complex +TYPED_TEST(OperatorTestsComplexTypesAllExecs, ComplexTypeCompatibility) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 10; + + tensor_t fview({count}); + tensor_t dview({count}); + + // Multiply by scalar + for (index_t i = 0; i < count; i++) { + fview(i) = static_cast(i); + dview(i) = {static_cast>(i), + static_cast>(i)}; + } + + (dview = dview * fview).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + ASSERT_EQ(static_cast>(dview(i).real()), + static_cast>(i * i)); + ASSERT_EQ(static_cast>(dview(i).imag()), + static_cast>(i * i)); + } + + // Divide by scalar + for (index_t i = 0; i < count; i++) { + fview(i) = i == 0 ? static_cast(1) : static_cast(i); + dview(i) = {static_cast>(i), + static_cast>(i)}; + } + + (dview = dview / fview).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + ASSERT_EQ(static_cast>(dview(i).real()), + i == 0 ? static_cast>(0) + : static_cast>(1)); + ASSERT_EQ(static_cast>(dview(i).imag()), + i == 0 ? static_cast>(0) + : static_cast>(1)); + } + + // Add scalar + for (index_t i = 0; i < count; i++) { + fview(i) = static_cast(i); + dview(i) = {static_cast>(i), + static_cast>(i)}; + } + + + (dview = dview + fview).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + ASSERT_EQ(static_cast>(dview(i).real()), + static_cast>(i + i)); + ASSERT_EQ(static_cast>(dview(i).imag()), + static_cast>(i)); + } + + // Subtract scalar from complex + for (index_t i = 0; i < count; i++) { + fview(i) = static_cast(i + 1); + dview(i) = {static_cast>(i), + static_cast>(i)}; + } + + (dview = dview - fview).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + ASSERT_EQ(static_cast>(dview(i).real()), + static_cast>(-1)); + ASSERT_EQ(static_cast>(dview(i).imag()), + static_cast>(i)); + } + + // Subtract complex from scalar + for (index_t i = 0; i < count; i++) { + fview(i) = static_cast(i + 1); + dview(i) = {static_cast>(i), + static_cast>(i)}; + } + + (dview = fview - dview).run(exec); + exec.sync(); + + for (index_t i = 0; i < count; i++) { + ASSERT_EQ(static_cast>(dview(i).real()), + static_cast>(1)); + ASSERT_EQ(static_cast>(dview(i).imag()), + static_cast>(-i)); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/concat_test.cu b/test/00_operators/concat_test.cu new file mode 100644 index 00000000..910d6f54 --- /dev/null +++ b/test/00_operators/concat_test.cu @@ -0,0 +1,144 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Concatenate) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t i, j; + + // example-begin concat-test-1 + auto t11 = make_tensor({10}); + auto t12 = make_tensor({5}); + auto t1o = make_tensor({15}); + + t11.SetVals({0,1,2,3,4,5,6,7,8,9}); + t12.SetVals({0,1,2,3,4}); + + // Concatenate "t11" and "t12" into a new 1D tensor + (t1o = concat(0, t11, t12)).run(exec); + // example-end concat-test-1 + exec.sync(); + + for (i = 0; i < t11.Size(0) + t12.Size(0); i++) { + if (i < t11.Size(0)) { + ASSERT_EQ(t11(i), t1o(i)); + } + else { + ASSERT_EQ(t12(i - t11.Size(0)), t1o(i)); + } + } + + // Test contcat with nested transforms + if constexpr (is_cuda_executor_v && (std::is_same_v || std::is_same_v)) { + auto delta = make_tensor({1}); + delta.SetVals({1.0}); + + (t1o = 0).run(exec); + (t1o = concat(0, conv1d(t11, delta, MATX_C_MODE_SAME), conv1d(t12, delta, MATX_C_MODE_SAME))).run(exec); + + exec.sync(); + + for (i = 0; i < t11.Size(0) + t12.Size(0); i++) { + if (i < t11.Size(0)) { + ASSERT_EQ(t11(i), t1o(i)); + } + else { + ASSERT_EQ(t12(i - t11.Size(0)), t1o(i)); + } + } + } + + // 2D tensors + auto t21 = make_tensor({4, 4}); + auto t22 = make_tensor({3, 4}); + auto t23 = make_tensor({4, 3}); + + auto t2o1 = make_tensor({7,4}); + auto t2o2 = make_tensor({4,7}); + t21.SetVals({{1,2,3,4}, + {2,3,4,5}, + {3,4,5,6}, + {4,5,6,7}} ); + t22.SetVals({{5,6,7,8}, + {6,7,8,9}, + {9,10,11,12}}); + t23.SetVals({{5,6,7}, + {6,7,8}, + {9,10,11}, + {10,11,12}}); + + (t2o1 = concat(0, t21, t22)).run(exec); + exec.sync(); + + for (i = 0; i < t21.Size(0) + t22.Size(0); i++) { + for (j = 0; j < t21.Size(1); j++) { + if (i < t21.Size(0)) { + ASSERT_EQ(t21(i,j), t2o1(i,j)); + } + else { + ASSERT_EQ(t22(i - t21.Size(0), j), t2o1(i,j)); + } + } + } + + (t2o2 = concat(1, t21, t23)).run(exec); + exec.sync(); + + for (j = 0; j < t21.Size(1) + t23.Size(1); j++) { + for (i = 0; i < t21.Size(0); i++) { + if (j < t21.Size(1)) { + ASSERT_EQ(t21(i,j), t2o2(i,j)); + } + else { + ASSERT_EQ(t23(i, j - t21.Size(1)), t2o2(i,j)); + } + } + } + + auto t1o1 = make_tensor({30}); + + // Concatenating 3 tensors + (t1o1 = concat(0, t11, t11, t11)).run(exec); + exec.sync(); + + for (i = 0; i < t1o1.Size(0); i++) { + ASSERT_EQ(t1o1(i), t11(i % t11.Size(0))); + } + + + // Multiple concatenations + { + auto a = matx::make_tensor({10}); + auto b = matx::make_tensor({10}); + auto c = matx::make_tensor({10}); + auto d = matx::make_tensor({10}); + + auto result = matx::make_tensor({40}); + a.SetVals({1,2,3,4,5,6,7,8,9,10}); + b.SetVals({11,12,13,14,15,16,17,18,19,20}); + c.SetVals({21,22,23,24,25,26,27,28,29,30}); + d.SetVals({31,32,33,34,35,36,37,38,39,40}); + + auto tempConcat1 = matx::concat(0, a, b); + auto tempConcat2 = matx::concat(0, c, d); + (result = matx::concat(0, tempConcat1, tempConcat2 )).run(exec); + + exec.sync(); + for (int cnt = 0; cnt < result.Size(0); cnt++) { + ASSERT_EQ(result(cnt), cnt + 1); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/cross_test.cu b/test/00_operators/cross_test.cu new file mode 100644 index 00000000..28b97890 --- /dev/null +++ b/test/00_operators/cross_test.cu @@ -0,0 +1,68 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Cross) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + ExecType exec{}; + auto pb = std::make_unique(); + // Half precision needs a bit more tolerance when compared to fp32 + float thresh = 0.01f; + if constexpr (is_matx_half_v) { + thresh = 0.08f; + } + + {//batched 4 x 3 + pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {4, 3}); + + auto a = make_tensor({4, 3}); + auto b = make_tensor({4, 3}); + auto out = make_tensor({4, 3}); + + pb->NumpyToTensorView(a, "a"); + pb->NumpyToTensorView(b, "b"); + + // example-begin cross-test-1 + (out = cross(a, b)).run(exec); + // example-end cross-test-1 + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); + } + + {//non-batched 3 + pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {3}); + auto a = make_tensor({3}); + auto b = make_tensor({3}); + auto out = make_tensor({3}); + + pb->NumpyToTensorView(a, "a"); + pb->NumpyToTensorView(b, "b"); + + (out = cross(a, b)).run(exec); + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); + } + + {//non-batched 2 + pb->InitAndRunTVGenerator("00_operators", "cross_operator", "run", {2}); + auto a = make_tensor({2}); + auto b = make_tensor({2}); + auto out = make_tensor({1}); + + pb->NumpyToTensorView(a, "a"); + pb->NumpyToTensorView(b, "b"); + + (out = cross(a, b)).run(exec); + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out, "out", thresh); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/fftshift_test.cu b/test/00_operators/fftshift_test.cu new file mode 100644 index 00000000..c537a4ea --- /dev/null +++ b/test/00_operators/fftshift_test.cu @@ -0,0 +1,112 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + + +TYPED_TEST(OperatorTestsFloatNonHalf, FFTShiftWithTransform) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + using inner_type = typename inner_op_type_t::type; + using complex_type = detail::complex_from_scalar_t; + + if constexpr (!detail::CheckFFTSupport()) { + GTEST_SKIP(); + } + + ExecType exec{}; + + [[maybe_unused]] const inner_type thresh = static_cast(1.0e-6); + + // Verify that fftshift1D/ifftshift1D work with nested transforms. + // These tests are limited to complex-to-complex transforms where we have matched + // dimensions and types for the inputs/outputs. Adding tests that include real-to-complex + // or complex-to-real fft compositions is TBD. + if constexpr (is_complex_v) + { + const int N1 = 3; + const int N2 = 4; + + auto t3 = make_tensor({N1}); + auto t4 = make_tensor({N2}); + auto T3 = make_tensor({N1}); + auto T4 = make_tensor({N2}); + + const cuda::std::array t3_vals = {{ { 1.0, 0.0 }, { 2.0, 0.0 }, { 3.0, 0.0 } }}; + const cuda::std::array t4_vals = {{ { 1.0, 0.0 }, { 2.0, 0.0 }, { 3.0, 0.0 }, { 4.0, 0.0 } }}; + + for (int i = 0; i < N1; i++) { t3(i) = t3_vals[i]; }; + for (int i = 0; i < N2; i++) { t4(i) = t4_vals[i]; }; + + exec.sync(); + + (T3 = fftshift1D(fft(t3))).run(exec); + (T4 = fftshift1D(fft(t4))).run(exec); + + exec.sync(); + + const cuda::std::array T3_expected = {{ + { -1.5, static_cast(-0.8660254) }, { 6.0, 0.0 }, { -1.5, static_cast(0.8660254) } + }}; + const cuda::std::array T4_expected = {{ + { -2.0, 0.0 }, { -2.0, -2.0 }, { 10.0, 0.0 }, { -2.0, 2.0 } + }}; + + for (int i = 0; i < N1; i++) { + ASSERT_NEAR(T3(i).real(), T3_expected[i].real(), thresh); + ASSERT_NEAR(T3(i).imag(), T3_expected[i].imag(), thresh); + } + + for (int i = 0; i < N2; i++) { + ASSERT_NEAR(T4(i).real(), T4_expected[i].real(), thresh); + ASSERT_NEAR(T4(i).imag(), T4_expected[i].imag(), thresh); + } + + (T3 = ifftshift1D(fft(t3))).run(exec); + (T4 = ifftshift1D(fft(t4))).run(exec); + + exec.sync(); + + const cuda::std::array T3_ifftshift_expected = {{ + { -1.5, static_cast(0.8660254) }, { -1.5, static_cast(-0.8660254) }, { 6.0, 0.0 } + }}; + + for (int i = 0; i < N1; i++) { + ASSERT_NEAR(T3(i).real(), T3_ifftshift_expected[i].real(), thresh); + ASSERT_NEAR(T3(i).imag(), T3_ifftshift_expected[i].imag(), thresh); + } + + // For even length vectors, fftshift() and ifftshift() are identical + for (int i = 0; i < N2; i++) { + ASSERT_NEAR(T4(i).real(), T4_expected[i].real(), thresh); + ASSERT_NEAR(T4(i).imag(), T4_expected[i].imag(), thresh); + } + } + + // Verify that fftshift2D/ifftshift2D work with nested transforms. We do not + // check correctness here, but there are fftshift2D correctness tests elsewhere. + if constexpr (is_complex_v) { + [[maybe_unused]] const int N = 4; + + auto x = make_tensor({N,N}); + auto X = make_tensor({N,N}); + + (x = static_cast(0)).run(exec); + + (X = fftshift2D(fft2(x))).run(exec); + (X = fftshift2D(ifft2(x))).run(exec); + (X = ifftshift2D(fft2(x))).run(exec); + (X = ifftshift2D(ifft2(x))).run(exec); + + exec.sync(); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/flatten_test.cu b/test/00_operators/flatten_test.cu new file mode 100644 index 00000000..e3d53813 --- /dev/null +++ b/test/00_operators/flatten_test.cu @@ -0,0 +1,37 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, Flatten) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin flatten-test-1 + auto t2 = make_tensor({10, 2}); + auto val = GenerateData(); + + for (index_t i = 0; i < t2.Size(0); i++) { + for (index_t j = 0; j < t2.Size(1); j++) { + t2(i,j) = val; + } + } + + auto t1 = make_tensor({t2.Size(0)*t2.Size(1)}); + (t1 = flatten(t2)).run(exec); + // example-end flatten-test-1 + exec.sync(); + + for (index_t i = 0; i < t2.Size(0)*t2.Size(1); i++) { + ASSERT_EQ(t1(i), val); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/fmod_test.cu b/test/00_operators/fmod_test.cu new file mode 100644 index 00000000..4fa687f8 --- /dev/null +++ b/test/00_operators/fmod_test.cu @@ -0,0 +1,30 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, FMod) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin fmod-test-1 + auto tiv0 = make_tensor({}); + auto tiv1 = make_tensor({}); + auto tov0 = make_tensor({}); + + tiv0() = (TestType)5.0; + tiv1() = (TestType)3.1; + (tov0 = fmod(tiv0, tiv1)).run(exec); + // example-end fmod-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_fmod((TestType)5.0, (TestType)3.1))); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/frexp_test.cu b/test/00_operators/frexp_test.cu new file mode 100644 index 00000000..dfa3af0a --- /dev/null +++ b/test/00_operators/frexp_test.cu @@ -0,0 +1,48 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, Frexp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin frexp-test-1 + // Input data + auto tiv0 = make_tensor({10}); + + // Output fractional/integer parts + auto tofrac = make_tensor({10}); + auto toint = make_tensor({10}); + + (tiv0 = random(tiv0.Shape(), NORMAL)).run(exec); + // Create operators representing fractional and integer + const auto [ofrac, oint] = frexp(tiv0); + (tofrac = ofrac, toint = oint).run(exec); + // example-end frexp-test-1 + + exec.sync(); + + int texp; + for (int i = 0; i < tiv0.Size(0); i++) { + if constexpr (std::is_same_v) { + float tfrac = cuda::std::frexpf(tiv0(i), &texp); + ASSERT_EQ(tfrac, tofrac(i)); + ASSERT_EQ(texp, toint(i)); + } + else { + double tfrac = cuda::std::frexp(tiv0(i), &texp); + ASSERT_EQ(tfrac, tofrac(i)); + ASSERT_EQ(texp, toint(i)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/frexpc_test.cu b/test/00_operators/frexpc_test.cu new file mode 100644 index 00000000..da20921a --- /dev/null +++ b/test/00_operators/frexpc_test.cu @@ -0,0 +1,59 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsComplexNonHalfTypesAllExecs, Frexpc) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin frexpc-test-1 + // Input data + auto tiv0 = make_tensor({10}); + + // Output fractional/integer parts + auto tofrac_real = make_tensor({10}); + auto tofrac_imag = make_tensor({10}); + auto toint_real = make_tensor({10}); + auto toint_imag = make_tensor({10}); + + // Create operators representing fractional and integer + (tiv0 = random(tiv0.Shape(), NORMAL)).run(exec); + const auto [ofrac_real, oint_real, ofrac_imag, oint_imag] = frexpc(tiv0); + + ( tofrac_real = ofrac_real, + toint_real = oint_real, + tofrac_imag = ofrac_imag, + toint_imag = oint_imag).run(exec); + // example-end frexpc-test-1 + + exec.sync(); + int texp_real, texp_imag; + for (int i = 0; i < tiv0.Size(0); i++) { + if constexpr (std::is_same_v>) { + float tfrac_real = cuda::std::frexpf(tiv0(i).real(), &texp_real); + float tfrac_imag = cuda::std::frexpf(tiv0(i).imag(), &texp_imag); + ASSERT_EQ(tfrac_real, tofrac_real(i)); + ASSERT_EQ(texp_real, toint_real(i)); + ASSERT_EQ(tfrac_imag, tofrac_imag(i)); + ASSERT_EQ(texp_imag, toint_imag(i)); + } + else { + double tfrac_real = cuda::std::frexp(tiv0(i).real(), &texp_real); + double tfrac_imag = cuda::std::frexp(tiv0(i).imag(), &texp_imag); + ASSERT_EQ(tfrac_real, tofrac_real(i)); + ASSERT_EQ(texp_real, toint_real(i)); + ASSERT_EQ(tfrac_imag, tofrac_imag(i)); + ASSERT_EQ(texp_imag, toint_imag(i)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/get_string_test.cu b/test/00_operators/get_string_test.cu new file mode 100644 index 00000000..f51abe4c --- /dev/null +++ b/test/00_operators/get_string_test.cu @@ -0,0 +1,32 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, GetString) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto A = make_tensor({10,20}); + auto B = make_tensor({20}); + auto C = make_tensor({10,20}); + + auto op1 = C = A; + auto op2 = C = A + B + (TestType)5; + auto op3 = C = A / B; + auto op4 = (op1,op2,op3); + + std::cout << "op1: " << op1.str() << std::endl; + std::cout << "op2: " << op2.str() << std::endl; + std::cout << "op3: " << op3.str() << std::endl; + std::cout << "op4: " << op4.str() << std::endl; + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/interleaved_test.cu b/test/00_operators/interleaved_test.cu new file mode 100644 index 00000000..d64b4017 --- /dev/null +++ b/test/00_operators/interleaved_test.cu @@ -0,0 +1,44 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, InterleavedTransform) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t m = 10; + index_t k = 20; + tensor_t t2({m, k}); + tensor_t t2p({m * 2, k}); + for (index_t i = 0; i < 2 * m; i++) { + for (index_t j = 0; j < k; j++) { + if (i >= m) { + t2p(i, j) = 2.0f; + } + else { + t2p(i, j) = -1.0f; + } + } + } + + (t2 = interleaved(t2p)).run(exec); + exec.sync(); + + for (index_t i = 0; i < m; i++) { + for (index_t j = 0; j < k; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j).real(), t2p(i, j))); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2(i, j).imag(), t2p(i + t2.Size(0), j))); + } + } + MATX_EXIT_HANDLER(); +} diff --git a/test/00_operators/isclose_test.cu b/test/00_operators/isclose_test.cu new file mode 100644 index 00000000..22d747dc --- /dev/null +++ b/test/00_operators/isclose_test.cu @@ -0,0 +1,54 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatAllExecs, IsClose) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin isclose-test-1 + auto A = make_tensor({5, 5, 5}); + auto B = make_tensor({5, 5, 5}); + auto C = make_tensor({5, 5, 5}); + + (A = ones(A.Shape())).run(exec); + (B = ones(B.Shape())).run(exec); + (C = isclose(A, B)).run(exec); + // example-end isclose-test-1 + exec.sync(); + + for(int i=0; i < A.Size(0); i++) { + for(int j=0; j < A.Size(1); j++) { + for(int k=0; k < A.Size(2); k++) { + ASSERT_EQ(C(i,j,k), 1); + } + } + } + + B(1,1,1) = 2; + (C = isclose(A, B)).run(exec); + exec.sync(); + + for(int i=0; i < A.Size(0); i++) { + for(int j=0; j < A.Size(1); j++) { + for(int k=0; k < A.Size(2); k++) { + if (i == 1 && j == 1 && k == 1) { + ASSERT_EQ(C(i,j,k), 0); + } + else { + ASSERT_EQ(C(i,j,k), 1); + } + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/isnaninf_test.cu b/test/00_operators/isnaninf_test.cu new file mode 100644 index 00000000..87d7c178 --- /dev/null +++ b/test/00_operators/isnaninf_test.cu @@ -0,0 +1,59 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, IsNanInf) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto nan = make_tensor({}); + using conversionType = typename matx::detail::value_promote_t; + if constexpr(matx::is_complex_v) { + nan() = TestType(std::numeric_limits::quiet_NaN()); + } else { + nan() = std::numeric_limits::quiet_NaN(); + } + auto tob = make_tensor({}); + // example-begin nan-test-1 + (tob = matx::isnan(nan)).run(exec); + // example-end nan-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), std::is_floating_point_v ? true : false)); + + auto notnanorinf = make_tensor({}); + if constexpr(matx::is_complex_v) { + notnanorinf() = TestType(0); + } else { + notnanorinf() = 0; + } + (tob = matx::isnan(notnanorinf)).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), false)); + + auto inf = make_tensor({}); + if constexpr(matx::is_complex_v) { + inf() = TestType(std::numeric_limits::infinity()); + } else { + inf() = std::numeric_limits::infinity(); + } + // example-begin inf-test-1 + (tob = matx::isinf(inf)).run(exec); + // example-end inf-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), std::is_floating_point_v ? true : false)); + + (tob = matx::isinf(notnanorinf)).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), false)); + + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/legendre_test.cu b/test/00_operators/legendre_test.cu new file mode 100644 index 00000000..8ad1c6a9 --- /dev/null +++ b/test/00_operators/legendre_test.cu @@ -0,0 +1,142 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +template +TypeParam legendre_check(int n, int m, TypeParam x) { + if (m > n ) return 0; + + TypeParam a = detail::_internal_sqrt(TypeParam(1)-x*x); + // first we will move move along diagonal + + // initialize registers + TypeParam d1 = 1, d0; + + for(int i=0; i < m; i++) { + // advance diagonal (shift) + d0 = d1; + // compute next term using recurrence relationship + d1 = -TypeParam(2*i+1)*a*d0; + } + + // next we will move to the right till we get to the correct entry + + // initialize registers + TypeParam p0, p1 = 0, p2 = d1; + + for(int l=m; l; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t size = 11; + int order = 5; + + { // vector for n and m + // example-begin legendre-test-1 + auto n = range<0, 1, int>({order}, 0, 1); + auto m = range<0, 1, int>({order}, 0, 1); + auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); + + auto out = make_tensor({order, order, size}); + + (out = legendre(n, m, x)).run(exec); + // example-end legendre-test-1 + + exec.sync(); + + for(int j = 0; j < order; j++) { + for(int p = 0; p < order; p++) { + for(int i = 0 ; i < size; i++) { + if constexpr (is_matx_half_v) { + ASSERT_NEAR(out(p,j,i), legendre_check(p, j, x(i)),50.0); + } + else { + ASSERT_NEAR(out(p,j,i), legendre_check(p, j, x(i)),.0001); + } + } + } + } + } + + { // constant for n + auto m = range<0, 1, int>({order}, 0, 1); + auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); + + auto out = make_tensor({order, size}); + + (out = lcollapse<2>(legendre(order, m, x))).run(exec); + + exec.sync(); + + for(int i = 0 ; i < size; i++) { + for(int p = 0; p < order; p++) { + if constexpr (is_matx_half_v) { + ASSERT_NEAR(out(p,i), legendre_check(order, p, x(i)),50.0); + } + else { + ASSERT_NEAR(out(p,i), legendre_check(order, p, x(i)),.0001); + } + } + } + } + + { // taking a constant for m and n; + auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); + + auto out = make_tensor({size}); + + (out = lcollapse<3>(legendre(order, order, x))).run(exec); + + exec.sync(); + + for(int i = 0 ; i < size; i++) { + if constexpr (is_matx_half_v) { + ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),50.0); + } + else { + ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),.0001); + } + } + } + + { // taking a rank0 tensor for m and constant for n + auto x = as_type(linspace<0>({size}, TestType(0), TestType(1))); + auto m = make_tensor({}); + auto out = make_tensor({size}); + m() = order; + + (out = lcollapse<3>(legendre(order, m, x))).run(exec); + + exec.sync(); + + for(int i = 0 ; i < size; i++) { + if constexpr (is_matx_half_v) { + ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),50.0); + } + else { + ASSERT_NEAR(out(i), legendre_check(order, order, x(i)),.0001); + } + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/operator_func_test.cu b/test/00_operators/operator_func_test.cu new file mode 100644 index 00000000..df2ee1a8 --- /dev/null +++ b/test/00_operators/operator_func_test.cu @@ -0,0 +1,431 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + TestType d = c; + TestType z = 0; + tiv0() = c; + + auto tov00 = make_tensor({}); + + // example-begin IFELSE-test-1 + IFELSE(tiv0 == d, tov0 = z, tov0 = d).run(exec); + // example-end IFELSE-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), z)); + + IFELSE(tiv0 == d, tov0 = tiv0, tov0 = d).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), tiv0())); + + IFELSE(tiv0 != d, tov0 = d, tov0 = z).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), z)); + + (tov0 = c, tov00 = c).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c)); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov00(), c)); + + MATX_EXIT_HANDLER(); +} + + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, OperatorFuncsR2C) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor>({}); + TestType c = GenerateData(); + tiv0() = c; + + // example-begin expj-test-1 + (tov0 = expj(tiv0)).run(exec); + // example-end expj-test-1 + exec.sync(); + + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + tov0(), + typename detail::complex_from_scalar_t(detail::_internal_cos(tiv0()), detail::_internal_sin(tiv0())))); + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + + // example-begin log10-test-1 + (tov0 = log10(tiv0)).run(exec); + // example-end log10-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log10(c))); + + // example-begin log-test-1 + (tov0 = log(tiv0)).run(exec); + // example-end log-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log(c))); + + // example-begin log2-test-1 + (tov0 = log2(tiv0)).run(exec); + // example-end log2-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_log2(c))); + + // example-begin floor-test-1 + (tov0 = floor(tiv0)).run(exec); + // example-end floor-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_floor(c))); + + // example-begin ceil-test-1 + (tov0 = ceil(tiv0)).run(exec); + // example-end ceil-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_ceil(c))); + + // example-begin round-test-1 + (tov0 = round(tiv0)).run(exec); + // example-end round-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_round(c))); + + // example-begin sqrt-test-1 + (tov0 = sqrt(tiv0)).run(exec); + // example-end sqrt-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sqrt(c))); + + // example-begin rsqrt-test-1 + (tov0 = rsqrt(tiv0)).run(exec); + // example-end rsqrt-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_rsqrt(c))); + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, NDOperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto a = make_tensor({1,2,3,4,5}); + auto b = make_tensor({1,2,3,4,5}); + (a = ones(a.Shape())).run(exec); + exec.sync(); + (b = ones(b.Shape())).run(exec); + exec.sync(); + (a = a + b).run(exec); + + auto t0 = make_tensor({}); + (t0 = sum(a)).run(exec); + exec.sync(); + ASSERT_EQ(t0(), static_cast(2 * a.TotalSize())); + MATX_EXIT_HANDLER(); +} + + +TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + TestType d = c + 1; + + // example-begin max-el-test-1 + (tov0 = max(tiv0, d)).run(exec); + // example-end max-el-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), std::max(c, d))); + + // example-begin min-el-test-1 + (tov0 = min(tiv0, d)).run(exec); + // example-end min-el-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), std::min(c, d))); + + // These operators convert type T into bool + auto tob = make_tensor({}); + + // example-begin lt-test-1 + (tob = tiv0 < d).run(exec); + // example-end lt-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c < d)); + + // example-begin gt-test-1 + (tob = tiv0 > d).run(exec); + // example-end gt-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c > d)); + + // example-begin lte-test-1 + (tob = tiv0 <= d).run(exec); + // example-end lte-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c <= d)); + + // example-begin gte-test-1 + (tob = tiv0 >= d).run(exec); + // example-end gte-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c >= d)); + + // example-begin eq-test-1 + (tob = tiv0 == d).run(exec); + // example-end eq-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c == d)); + + // example-begin neq-test-1 + (tob = tiv0 != d).run(exec); + // example-end neq-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tob(), c != d)); + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, OperatorFuncDivComplex) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + typename TestType::value_type s = 5.0; + + TestType c = GenerateData(); + tiv0() = c; + + (tov0 = s / tiv0).run(exec); + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), s / tiv0())); + + MATX_EXIT_HANDLER(); +} + + +TYPED_TEST(OperatorTestsNumericAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + + // example-begin add-test-1 + (tov0 = tiv0 + tiv0).run(exec); + // example-end add-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c + c)); + + // example-begin sub-test-1 + (tov0 = tiv0 - tiv0).run(exec); + // example-end sub-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c - c)); + + // example-begin mul-test-1 + (tov0 = tiv0 * tiv0).run(exec); + // example-end mul-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c * c)); + + // example-begin div-test-1 + (tov0 = tiv0 / tiv0).run(exec); + // example-end div-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c / c)); + + // example-begin neg-test-1 + (tov0 = -tiv0).run(exec); + // example-end neg-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), -c)); + + // example-begin IF-test-1 + IF(tiv0 == tiv0, tov0 = c).run(exec); + // example-end IF-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c)); + + TestType p = 2.0f; + // example-begin pow-test-1 + (tov0 = as_type(pow(tiv0, p))).run(exec); + // example-end pow-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_pow(c, p))); + + TestType three = 3.0f; + + (tov0 = tiv0 * tiv0 * (tiv0 + tiv0) / tiv0 + three).run(exec); + exec.sync(); + + TestType res; + res = c * c * (c + c) / c + three; + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), res, 0.07)); + + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsIntegralAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + TestType mod = 2; + + // example-begin mod-test-1 + (tov0 = tiv0 % mod).run(exec); + // example-end mod-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c % mod)); + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsBooleanAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + TestType d = false; + tiv0() = c; + + // example-begin land-test-1 + (tov0 = tiv0 && d).run(exec); + // example-end land-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c && d)); + + // example-begin lor-test-1 + (tov0 = tiv0 || d).run(exec); + // example-end lor-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c || d)); + + // example-begin lnot-test-1 + (tov0 = !tiv0).run(exec); + // example-end lnot-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), !c)); + + // example-begin xor-test-1 + (tov0 = tiv0 ^ d).run(exec); + // example-end xor-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c ^ d)); + + // example-begin or-test-1 + (tov0 = tiv0 | d).run(exec); + // example-end or-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c | d)); + + // example-begin and-test-1 + (tov0 = tiv0 & d).run(exec); + // example-end and-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c & d)); + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, OperatorFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + + // example-begin exp-test-1 + (tov0 = exp(tiv0)).run(exec); + // example-end exp-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_exp(c))); + + // example-begin conj-test-1 + (tov0 = conj(tiv0)).run(exec); + // example-end conj-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_conj(c))); + + // abs takes a complex and output a floating point value + auto tdd0 = make_tensor({}); + + // example-begin abs-test-1 + (tdd0 = abs(tiv0)).run(exec); + // example-end abs-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tdd0(), detail::_internal_abs(c))); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/operator_test_types.hpp b/test/00_operators/operator_test_types.hpp new file mode 100644 index 00000000..90de3a40 --- /dev/null +++ b/test/00_operators/operator_test_types.hpp @@ -0,0 +1,103 @@ +#pragma once + +#include "matx.h" +#include "test_types.h" +#include "gtest/gtest.h" + +namespace matx { +namespace test { + +template +class OperatorTestsComplex : public ::testing::Test {}; + +template +class OperatorTestsFloat : public ::testing::Test {}; + +template +class OperatorTestsNumeric : public ::testing::Test {}; + +template +class OperatorTestsNumericNonComplex : public ::testing::Test {}; + +template +class OperatorTestsFloatNonComplex : public ::testing::Test {}; + +template +class OperatorTestsFloatNonHalf : public ::testing::Test {}; + +template +class OperatorTestsFloatNonComplexNonHalf : public ::testing::Test {}; + +template +class OperatorTestsIntegral : public ::testing::Test {}; + +template +class OperatorTestsBoolean : public ::testing::Test {}; + +template +class OperatorTestsFloatHalf : public ::testing::Test {}; + +template +class OperatorTestsNumericNoHalf : public ::testing::Test {}; + +template +class OperatorTestsAll : public ::testing::Test {}; + +template +class OperatorTestsNumericNonComplexAllExecs : public ::testing::Test {}; + +template +class OperatorTestsFloatNonComplexNonHalfAllExecs : public ::testing::Test {}; + +template +class OperatorTestsNumericNoHalfAllExecs : public ::testing::Test {}; + +template +class OperatorTestsComplexNonHalfTypesAllExecs : public ::testing::Test {}; + +template +class OperatorTestsComplexTypesAllExecs : public ::testing::Test {}; + +template +class OperatorTestsAllExecs : public ::testing::Test {}; + +template +class OperatorTestsFloatAllExecs : public ::testing::Test {}; + +template +class OperatorTestsFloatNonComplexAllExecs : public ::testing::Test {}; + +template +class OperatorTestsNumericAllExecs : public ::testing::Test {}; + +template +class OperatorTestsIntegralAllExecs : public ::testing::Test {}; + +template +class OperatorTestsBooleanAllExecs : public ::testing::Test {}; + +template +class OperatorTestsCastToFloatAllExecs : public ::testing::Test {}; + +TYPED_TEST_SUITE(OperatorTestsFloatNonHalf, + MatXFloatNonHalfTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsNumericNonComplexAllExecs, + MatXNumericNonComplexTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsFloatNonComplexNonHalfAllExecs, + MatXFloatNonComplexNonHalfTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsFloatNonComplexAllExecs, + MatXTypesFloatNonComplexAllExecs); +TYPED_TEST_SUITE(OperatorTestsNumericAllExecs, + MatXTypesNumericAllExecs); +TYPED_TEST_SUITE(OperatorTestsNumericNoHalfAllExecs, MatXNumericNoHalfTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsComplexNonHalfTypesAllExecs, MatXComplexNonHalfTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsComplexTypesAllExecs, MatXComplexTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsAllExecs, MatXAllTypesAllExecs); +TYPED_TEST_SUITE(OperatorTestsFloatAllExecs, MatXTypesFloatAllExecs); +TYPED_TEST_SUITE(OperatorTestsIntegralAllExecs, MatXTypesIntegralAllExecs); +TYPED_TEST_SUITE(OperatorTestsBooleanAllExecs, MatXTypesBooleanAllExecs); +TYPED_TEST_SUITE(OperatorTestsCastToFloatAllExecs, MatXTypesCastToFloatAllExecs); + + +} // namespace test +} // namespace matx \ No newline at end of file diff --git a/test/00_operators/overlap_test.cu b/test/00_operators/overlap_test.cu new file mode 100644 index 00000000..af2c0bd1 --- /dev/null +++ b/test/00_operators/overlap_test.cu @@ -0,0 +1,87 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsNumericNonComplexAllExecs, Overlap) +{ + MATX_ENTER_HANDLER(); + + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + + tensor_t a{{10}}; + a.SetVals({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + auto ao = overlap(a, {4}, {2}); + + tensor_t b{{4, 4}}; + b.SetVals({{0, 1, 2, 3}, {2, 3, 4, 5}, {4, 5, 6, 7}, {6, 7, 8, 9}}); + for (index_t i = 0; i < b.Size(0); i++) { + for (index_t j = 0; j < b.Size(1); j++) { + ASSERT_EQ(ao(i, j), b(i, j)); + } + } + + auto ao2 = overlap(a, {4}, {1}); + + tensor_t b2{{7, 4}}; + b2.SetVals({{0, 1, 2, 3}, + {1, 2, 3, 4}, + {2, 3, 4, 5}, + {3, 4, 5, 6}, + {4, 5, 6, 7}, + {5, 6, 7, 8}, + {6, 7, 8, 9}}); + for (index_t i = 0; i < b2.Size(0); i++) { + for (index_t j = 0; j < b2.Size(1); j++) { + ASSERT_EQ(ao2(i, j), b2(i, j)); + } + } + + auto ao3 = overlap(a, {4}, {3}); + tensor_t b3{{3, 4}}; + b3.SetVals({{0, 1, 2, 3}, {3, 4, 5, 6}, {6, 7, 8, 9}}); + for (index_t i = 0; i < b3.Size(0); i++) { + for (index_t j = 0; j < b3.Size(1); j++) { + ASSERT_EQ(ao3(i, j), b3(i, j)); + } + } + + auto ao4 = overlap(a, {3}, {2}); + tensor_t b4{{4, 3}}; + b4.SetVals({{0, 1, 2}, {2, 3, 4}, {4, 5, 6}, {6, 7, 8}}); + for (index_t i = 0; i < b4.Size(0); i++) { + for (index_t j = 0; j < b4.Size(1); j++) { + ASSERT_EQ(ao4(i, j), b4(i, j)); + } + } + + // Test with an operator input + // example-begin overlap-test-1 + auto aop = linspace<0>(a.Shape(), (TestType)0, (TestType)9); + tensor_t b4out{{4, 3}}; + + // Input is {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + // Output is: {{0, 1, 2}, {2, 3, 4}, {4, 5, 6}, {6, 7, 8}} + (b4out = overlap(aop, {3}, {2})).run(exec); + // example-end overlap-test-1 + + ASSERT_EQ(b4out.Size(0), 4); + ASSERT_EQ(b4out.Size(1), 3); + + exec.sync(); + for (index_t i = 0; i < b4.Size(0); i++) { + for (index_t j = 0; j < b4.Size(1); j++) { + ASSERT_EQ(b4out(i, j), b4(i, j)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/permute_test.cu b/test/00_operators/permute_test.cu new file mode 100644 index 00000000..65c0bf12 --- /dev/null +++ b/test/00_operators/permute_test.cu @@ -0,0 +1,51 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, PermuteOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto A = make_tensor({10,20,30}); + for(int i=0; i < A.Size(0); i++) { + for(int j=0; j < A.Size(1); j++) { + for(int k=0; k < A.Size(2); k++) { + A(i,j,k) = static_cast::type>( i * A.Size(1)*A.Size(2) + + j * A.Size(2) + k); + } + } + } + + // example-begin permute-test-1 + // Permute from dims {0, 1, 2} to {2, 0, 1} + auto op = permute(A, {2, 0, 1}); + // example-end permute-test-1 + auto At = A.Permute({2, 0, 1}); + + ASSERT_TRUE(op.Size(0) == A.Size(2)); + ASSERT_TRUE(op.Size(1) == A.Size(0)); + ASSERT_TRUE(op.Size(2) == A.Size(1)); + + ASSERT_TRUE(op.Size(0) == At.Size(0)); + ASSERT_TRUE(op.Size(1) == At.Size(1)); + ASSERT_TRUE(op.Size(2) == At.Size(2)); + + for(int i=0; i < op.Size(0); i++) { + for(int j=0; j < op.Size(1); j++) { + for(int k=0; k < op.Size(2); k++) { + ASSERT_TRUE( op(i,j,k) == A(j,k,i)); + ASSERT_TRUE( op(i,j,k) == At(i,j,k)); + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/planar_test.cu b/test/00_operators/planar_test.cu new file mode 100644 index 00000000..c764f048 --- /dev/null +++ b/test/00_operators/planar_test.cu @@ -0,0 +1,39 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, PlanarTransform) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t m = 10; + index_t k = 20; + tensor_t t2({m, k}); + tensor_t t2p({m * 2, k}); + for (index_t i = 0; i < m; i++) { + for (index_t j = 0; j < k; j++) { + TestType tmp = {(float)i, (float)-j}; + t2(i, j) = tmp; + } + } + + (t2p = planar(t2)).run(exec); + exec.sync(); + + for (index_t i = 0; i < m; i++) { + for (index_t j = 0; j < k; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j).real(), t2p(i, j))); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2(i, j).imag(), t2p(i + t2.Size(0), j))) << i << " " << j << "\n"; + } + } + MATX_EXIT_HANDLER(); +} diff --git a/test/00_operators/polyval_test.cu b/test/00_operators/polyval_test.cu new file mode 100644 index 00000000..a553942b --- /dev/null +++ b/test/00_operators/polyval_test.cu @@ -0,0 +1,34 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, PolyVal) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + auto pb = std::make_unique(); + pb->InitAndRunTVGenerator("00_operators", "polyval_operator", "run", {4, 100}); + + ExecType exec{}; + auto x = make_tensor({100}); + auto c = make_tensor({4}); + auto out = make_tensor({100}); + + pb->NumpyToTensorView(x, "x"); + pb->NumpyToTensorView(c, "c"); + + // example-begin polyval-test-1 + (out = polyval(x, c)).run(exec); + // example-end polyval-test-1 + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out, "out", 0.01); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/print_test.cu b/test/00_operators/print_test.cu new file mode 100644 index 00000000..57140071 --- /dev/null +++ b/test/00_operators/print_test.cu @@ -0,0 +1,22 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatAllExecs, Print) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + + auto t1 = make_tensor({3}); + auto r1 = ones(t1.Shape()); + print(r1); + + auto t3 = matx::make_tensor({3, 2, 20}); + print(matx::ones(t3.Shape()), 1, 0, 2); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/r2c_test.cu b/test/00_operators/r2c_test.cu new file mode 100644 index 00000000..15cadda4 --- /dev/null +++ b/test/00_operators/r2c_test.cu @@ -0,0 +1,99 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, R2COp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + ExecType exec{}; + using ComplexType = detail::complex_from_scalar_t; + + // r2c requires FFT support, so we need to check the executor here + if constexpr (!detail::CheckFFTSupport()) { + GTEST_SKIP(); + } + + const int N1 = 5; + const int N2 = 6; + + auto t1 = make_tensor({N1}); + auto t2 = make_tensor({N2}); + auto T1 = make_tensor({N1}); + auto T2 = make_tensor({N2}); + + for (int i = 0; i < N1; i++) { t1(i) = static_cast(i+1); } + for (int i = 0; i < N2; i++) { t2(i) = static_cast(i+1); } + exec.sync(); + + const cuda::std::array T1_expected = {{ + { 15.0, 0.0 }, { -2.5, static_cast(3.4409548) }, { -2.5, static_cast(0.81229924) }, + { -2.5, static_cast(-0.81229924) }, { -2.5, static_cast(-3.4409548) } + }}; + + const cuda::std::array T2_expected = {{ + { 21.0, 0.0 }, { -3.0, static_cast(5.19615242) }, { -3.0, static_cast(1.73205081) }, + { -3.0, static_cast(-4.44089210e-16) }, { -3.0, static_cast(-1.73205081) }, + { -3.0, static_cast(-5.19615242) } + }}; + + const TestType thresh = static_cast(1.0e-6); + + // Test the regular r2c path with fft() deducing the transform size + (T1 = r2c(fft(t1), N1)).run(exec); + (T2 = r2c(fft(t2), N2)).run(exec); + + exec.sync(); + + for (int i = 0; i < N1; i++) { + ASSERT_NEAR(T1(i).real(), T1_expected[i].real(), thresh); + ASSERT_NEAR(T1(i).imag(), T1_expected[i].imag(), thresh); + } + + for (int i = 0; i < N2; i++) { + ASSERT_NEAR(T2(i).real(), T2_expected[i].real(), thresh); + ASSERT_NEAR(T2(i).imag(), T2_expected[i].imag(), thresh); + } + + // Test the r2c path when specifying the fft() transform size + (T1 = r2c(fft(t1, N1), N1)).run(exec); + (T2 = r2c(fft(t2, N2), N2)).run(exec); + + exec.sync(); + + for (int i = 0; i < N1; i++) { + ASSERT_NEAR(T1(i).real(), T1_expected[i].real(), thresh); + ASSERT_NEAR(T1(i).imag(), T1_expected[i].imag(), thresh); + } + + for (int i = 0; i < N2; i++) { + ASSERT_NEAR(T2(i).real(), T2_expected[i].real(), thresh); + ASSERT_NEAR(T2(i).imag(), T2_expected[i].imag(), thresh); + } + + // Add an ifft to the composition to return the original tensor, + // but now in complex rather than real form. The imaginary components + // should be ~0. + (T1 = ifft(r2c(fft(t1), N1))).run(exec); + (T2 = ifft(r2c(fft(t2), N2))).run(exec); + + exec.sync(); + + for (int i = 0; i < N1; i++) { + ASSERT_NEAR(T1(i).real(), t1(i), thresh); + ASSERT_NEAR(T1(i).imag(), static_cast(0.0), thresh); + } + + for (int i = 0; i < N2; i++) { + ASSERT_NEAR(T2(i).real(), t2(i), thresh); + ASSERT_NEAR(T2(i).imag(), static_cast(0.0), thresh); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/real_imag_test.cu b/test/00_operators/real_imag_test.cu new file mode 100644 index 00000000..18e82d62 --- /dev/null +++ b/test/00_operators/real_imag_test.cu @@ -0,0 +1,34 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, RealImagOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + // example-begin real-test-1 + (tov0 = real(tiv0)).run(exec); + // example-end real-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c.real())); + + // example-begin imag-test-1 + (tov0 = imag(tiv0)).run(exec); + // example-end imag-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), c.imag())); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/remap_rank_zero_test.cu b/test/00_operators/remap_rank_zero_test.cu new file mode 100644 index 00000000..ccc47fde --- /dev/null +++ b/test/00_operators/remap_rank_zero_test.cu @@ -0,0 +1,79 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, RemapRankZero) +{ + MATX_ENTER_HANDLER(); + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + const int N = 16; + + // 1D source tensor cases + { + auto from = make_tensor({N}); + (from = range<0>({N}, 0, 1)).run(exec); + exec.sync(); + auto ind = make_tensor({}); + auto r = remap<0>(from, ind); + auto to = make_tensor({1}); + + ind() = N/2; + (to = r).run(exec); + exec.sync(); + + ASSERT_EQ(to(0), N/2); + + ind() = N/4; + (to = r).run(exec); + exec.sync(); + + ASSERT_EQ(to(0), N/4); + } + + // 2D source tensor cases + { + auto from = make_tensor({N,N}); + (from = ones()).run(exec); + exec.sync(); + + auto i0 = make_tensor({}); + auto i1 = make_tensor({}); + auto r0 = remap<0>(from, i0); + auto r1 = remap<1>(from, i0); + + auto to0 = make_tensor({1,N}); + auto to1 = make_tensor({N,1}); + + i0() = N/2; + from(N/2,0) = 2; + from(0,N/2) = 3; + (to0 = r0).run(exec); + (to1 = r1).run(exec); + exec.sync(); + + ASSERT_EQ(to0(0,0), 2); + ASSERT_EQ(to0(0,1), 1); + ASSERT_EQ(to1(0,0), 3); + ASSERT_EQ(to1(1,0), 1); + + i0() = N/3; + i1() = 2*(N/3); + from(N/3, 2*(N/3)) = 11; + + // Select a single entry from the 2D input tensor + auto entry = make_tensor({1,1}); + (entry = remap<0,1>(from, i0, i1)).run(exec); + exec.sync(); + + ASSERT_EQ(entry(0,0), 11); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/remap_test.cu b/test/00_operators/remap_test.cu new file mode 100644 index 00000000..932cdf2c --- /dev/null +++ b/test/00_operators/remap_test.cu @@ -0,0 +1,357 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, RemapOp) +{ + int N = 10; + + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + using inner_type = typename inner_op_type_t::type; + + ExecType exec{}; + + auto tiv = make_tensor({N,N}); + + for(int i = 0; i < N; i++) { + for(int j = 0; j < N; j++) { + tiv(i,j) = inner_type(i*N+j); + } + } + + { // Identity Gather test + + // example-begin remap-test-1 + auto tov = make_tensor({N, N}); + auto idx = make_tensor({N}); + + for(int i = 0; i < N; i++) { + idx(i) = i; + } + + // Remap 2D operator "tiv" by selecting elements from dimension 0 stored in "idx" + (tov = remap<0>(tiv, idx)).run(exec); + // example-end remap-test-1 + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + + (tov = remap<1>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + + // example-begin remap-test-2 + // Remap 2D operator "tiv" by selecting elements from dimensions 0 and 1 stored in "idx" + (tov = remap<0,1>(tiv, idx, idx)).run(exec); + // example-end remap-test-2 + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + } + + { // Identity lvalue test + + auto tov = make_tensor({N, N}); + auto idx = make_tensor({N}); + + for(int i = 0; i < N; i++) { + idx(i) = i; + } + + (tov = (TestType)0).run(exec); + + (remap<0>(tov, idx) = tiv).run(exec); + + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + + (tov = (TestType)0).run(exec); + (remap<1>(tov, idx) = tiv).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + + (tov = (TestType)0).run(exec); + (remap<0,1>(tov, idx, idx) = tiv).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j)); + } + } + } + + { // Reverse test + + auto tov = make_tensor({N,N}); + auto idx = make_tensor({N}); + + for(int i = 0; i < N; i++) { + idx(i) = N-i-1; + } + + (tov = remap<0>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(N-i-1,j)); + } + } + + (tov = remap<1>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i, N-j-1)); + } + } + + (tov = remap<0,1>(tiv, idx, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(N-i-1, N-j-1)); + } + } + } + + { // Reverse lvalue test + + auto tov = make_tensor({N,N}); + auto idx = make_tensor({N}); + + for(int i = 0; i < N; i++) { + idx(i) = N-i-1; + } + + (remap<0>(tov, idx) = tiv).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(N-i-1,j)); + } + } + + (remap<1>(tov, idx) = tiv).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i, N-j-1)); + } + } + + (remap<0,1>(tov, idx, idx) = tiv).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(N-i-1, N-j-1)); + } + } + } + + { // Even test + int M = N/2; + auto idx = make_tensor({M}); + + for(int i = 0; i < M; i++) { + idx(i) = i*2; + } + + { + auto tov = make_tensor({M, N}); + + (tov = remap<0>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < M ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i*2,j)); + } + } + } + + { + auto tov = make_tensor({N, M}); + + (tov = remap<1>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < M ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j*2)); + } + } + } + + { + auto tov = make_tensor({M, M}); + + (tov = remap<0,1>(tiv, idx, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < M ; i++) { + for( int j = 0; j < M ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i*2,j*2)); + } + } + } + } + + { // Braodcast test + int M = N*2; + auto idx = make_tensor({M}); + + for(int i = 0; i < M; i++) { + idx(i) = 1; + } + + { + auto tov = make_tensor({M, N}); + + (tov = remap<0>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < M ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(1,j)); + } + } + } + + { + auto tov = make_tensor({N, M}); + + (tov = remap<1>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < M ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,1)); + } + } + } + } + + { // Advanced test + int M = N*2; + auto idx = make_tensor({M}); + + for(int i = 0; i < M; i++) { + idx(i) = i/4; + } + + { + auto tov = make_tensor({M, N}); + + (tov = remap<0>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < M ; i++) { + for( int j = 0; j < N ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i/4,j)); + } + } + } + + { + auto tov = make_tensor({N, M}); + + (tov = remap<1>(tiv, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < N ; i++) { + for( int j = 0; j < M ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i,j/4)); + } + } + } + + { + auto tov = make_tensor({M, M}); + + (tov = remap<0,1>(tiv, idx, idx)).run(exec); + exec.sync(); + + for( int i = 0; i < M ; i++) { + for( int j = 0; j < M ; j++) { + EXPECT_TRUE(tov(i,j) == tiv(i/4,j/4)); + } + } + } + } + + { + // Remap as both LHS and RHS + auto in = make_tensor({4,4,4}); + auto out = make_tensor({4,4,4}); + TestType c = GenerateData(); + for (int i = 0; i < in.Size(0); i++){ + for (int j = 0; j < in.Size(1); j++){ + for (int k = 0; k < in.Size(2); k++){ + in(i,j,k) = c; + } + } + } + + auto map1 = matx::make_tensor({2}); + auto map2 = matx::make_tensor({2}); + map1(0) = 1; + map1(1) = 2; + map2(0) = 0; + map2(1) = 1; + + (out = static_cast(0)).run(exec); + (matx::remap<2>(out, map2) = matx::remap<2>(in, map1)).run(exec); + exec.sync(); + + for (int i = 0; i < in.Size(0); i++){ + for (int j = 0; j < in.Size(1); j++){ + for (int k = 0; k < in.Size(2); k++){ + if (k > 1) { + ASSERT_EQ(out(i,j,k), (TestType)0); + } + else { + ASSERT_EQ(out(i,j,k), in(i,j,k)); + } + } + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/repmat_test.cu b/test/00_operators/repmat_test.cu new file mode 100644 index 00000000..41ab1e12 --- /dev/null +++ b/test/00_operators/repmat_test.cu @@ -0,0 +1,63 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsAllExecs, RepMat) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + // example-begin repmat-test-1 + const index_t count0 = 4; + const index_t count1 = 4; + const index_t same_reps = 10; + tensor_t t2({count0, count1}); + tensor_t t2s({count0 * same_reps, count1 * same_reps}); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + t2(i, j) = static_cast>(i); + } + } + + auto repop = repmat(t2, same_reps); + // example-end repmat-test-1 + ASSERT_TRUE(repop.Size(0) == same_reps * t2.Size(0)); + ASSERT_TRUE(repop.Size(1) == same_reps * t2.Size(1)); + + (t2s = repop).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0 * same_reps; i++) { + for (index_t j = 0; j < count1 * same_reps; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2s(i, j), t2(i % count0, j % count1))); + } + } + + // Now a rectangular repmat + tensor_t t2r({count0 * same_reps, count1 * same_reps * 2}); + + auto rrepop = repmat(t2, {same_reps, same_reps * 2}); + ASSERT_TRUE(rrepop.Size(0) == same_reps * t2.Size(0)); + ASSERT_TRUE(rrepop.Size(1) == same_reps * 2 * t2.Size(1)); + + (t2r = rrepop).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0 * same_reps; i++) { + for (index_t j = 0; j < count1 * same_reps * 2; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2r(i, j), t2(i % count0, j % count1))); + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/reshape_test.cu b/test/00_operators/reshape_test.cu new file mode 100644 index 00000000..5c82e33f --- /dev/null +++ b/test/00_operators/reshape_test.cu @@ -0,0 +1,154 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, ReshapeOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 10; + tensor_t t4({count, count, count, count}); + tensor_t t1({count * count * count * count}); + + for (index_t i = 0; i < t4.Size(0); i++) { + for (index_t j = 0; j < t4.Size(1); j++) { + for (index_t k = 0; k < t4.Size(2); k++) { + for (index_t l = 0; l < t4.Size(3); l++) { + t4(i, j, k, l) = + static_cast>(i + j + k + l); + t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1)) = + static_cast>(i + j + k + l); + } + } + } + } + + // Drop to a single dimension of same original total size + auto rsv1 = t4.View({count * count * count * count}); + for (index_t i = 0; i < t4.Size(0); i++) { + for (index_t j = 0; j < t4.Size(1); j++) { + for (index_t k = 0; k < t4.Size(2); k++) { + for (index_t l = 0; l < t4.Size(3); l++) { + MATX_ASSERT_EQ(rsv1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1)), + (TestType)(i + j + k + (double)l)); + } + } + } + } + + // Drop to 2D with a subset of the original size + auto rsv2 = t4.View({2, 2}); + for (index_t i = 0; i < rsv2.Size(0); i++) { + for (index_t j = 0; j < rsv2.Size(1); j++) { + MATX_ASSERT_EQ(rsv2(i, j), t4(0, 0, 0, i * rsv2.Size(1) + j)); + } + } + + // Create a 4D tensor from the 1D + auto rsv4 = t1.View({count, count, count, count}); + for (index_t i = 0; i < rsv4.Size(0); i++) { + for (index_t j = 0; j < rsv4.Size(1); j++) { + for (index_t k = 0; k < rsv4.Size(2); k++) { + for (index_t l = 0; l < rsv4.Size(3); l++) { + MATX_ASSERT_EQ(rsv4(i, j, k, l), + t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1))); + } + } + } + } + + + // Test if oversized views throw +#ifndef NDEBUG + try { + t4.View({1000, 1000, 100}); + FAIL() << "Oversized views not throwing"; + } catch (detail::matxException &e) {} +#endif + + MATX_EXIT_HANDLER(); +} + + +TYPED_TEST(OperatorTestsNumericAllExecs, Reshape) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 10; + tensor_t t4({count, count, count, count}); + tensor_t t1({count * count * count * count}); + + for (index_t i = 0; i < t4.Size(0); i++) { + for (index_t j = 0; j < t4.Size(1); j++) { + for (index_t k = 0; k < t4.Size(2); k++) { + for (index_t l = 0; l < t4.Size(3); l++) { + t4(i, j, k, l) = + static_cast>(i + j + k + l); + t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1)) = + static_cast>(i + j + k + l); + } + } + } + } + + // Drop to a single dimension of same original total size + auto rsv1 = t4.View({count * count * count * count}); + for (index_t i = 0; i < t4.Size(0); i++) { + for (index_t j = 0; j < t4.Size(1); j++) { + for (index_t k = 0; k < t4.Size(2); k++) { + for (index_t l = 0; l < t4.Size(3); l++) { + MATX_ASSERT_EQ(rsv1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1)), + (TestType)(i + j + k + (double)l)); + } + } + } + } + + // Drop to 2D with a subset of the original size + auto rsv2 = t4.View({2, 2}); + for (index_t i = 0; i < rsv2.Size(0); i++) { + for (index_t j = 0; j < rsv2.Size(1); j++) { + MATX_ASSERT_EQ(rsv2(i, j), t4(0, 0, 0, i * rsv2.Size(1) + j)); + } + } + + // Create a 4D tensor from the 1D + auto rsv4 = t1.View({count, count, count, count}); + for (index_t i = 0; i < rsv4.Size(0); i++) { + for (index_t j = 0; j < rsv4.Size(1); j++) { + for (index_t k = 0; k < rsv4.Size(2); k++) { + for (index_t l = 0; l < rsv4.Size(3); l++) { + MATX_ASSERT_EQ(rsv4(i, j, k, l), + t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + + i * t4.Size(3) * t4.Size(2) * t4.Size(1))); + } + } + } + } + + + // Test if oversized views throw +#ifndef NDEBUG + try { + t4.View({1000, 1000, 100}); + FAIL() << "Oversized views not throwing"; + } catch (detail::matxException &e) {} +#endif + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/reverse_test.cu b/test/00_operators/reverse_test.cu new file mode 100644 index 00000000..9283fe07 --- /dev/null +++ b/test/00_operators/reverse_test.cu @@ -0,0 +1,97 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, Reverse) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t count0 = 100; + index_t count1 = 200; + tensor_t t2({count0, count1}); + tensor_t t2r({count0, count1}); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + t2(i, j) = static_cast>(i * count1 + j); + } + } + + { + // example-begin reverse-test-1 + // Reverse the values of t2 along dimension 0 + (t2r = reverse<0>(t2)).run(exec); + // example-end reverse-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2r(i, j), t2(count0 - i - 1, j))); + } + } + } + + { + (t2r = reverse<1>(t2)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2r(i, j), t2(i, count1 - j - 1))); + } + } + } + + { + (t2r = reverse<0,1>(t2)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare( + t2r(i, j), t2(count0 - i - 1, count1 - j - 1))); + } + } + } + + // Flip versions + { + // example-begin flipud-test-1 + (t2r = flipud(t2)).run(exec); + // example-end flipud-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2r(i, j), t2(count0 - i - 1, j))); + } + } + } + + { + // example-begin fliplr-test-1 + (t2r = fliplr(t2)).run(exec); + // example-end fliplr-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2r(i, j), t2(i, count1 - j - 1))); + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/shift_test.cu b/test/00_operators/shift_test.cu new file mode 100644 index 00000000..3befa0e6 --- /dev/null +++ b/test/00_operators/shift_test.cu @@ -0,0 +1,164 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, ShiftOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t count0 = 100; + index_t count1 = 201; + tensor_t t2({count0, count1}); + tensor_t t2s({count0, count1}); + tensor_t t2s2({count0, count1}); + auto t0 = make_tensor({}); + t0() = -5; + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + t2(i, j) = static_cast>(i * count1 + j); + } + } + + { + // example-begin shift-test-1 + // Shift the first dimension of "t2" by -5 so the 5th element of "t2" is the first element of "t2s" + (t2s = shift<0>(t2, -5)).run(exec); + // example-end shift-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE( + MatXUtils::MatXTypeCompare(t2s(i, j), t2((i + 5) % count0, j))); + } + } + } + + { + (t2s = shift<0>(t2, t0)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE( + MatXUtils::MatXTypeCompare(t2s(i, j), t2((i + 5) % count0, j))); + } + } + } + + { + (t2s = shift<1>(t2, -5)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE( + MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, (j + 5) % count1))); + } + } + } + + { + (t2s = shift<1,0>(t2, -5, -6)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare( + t2s(i, j), t2((i + 6) % count0, (j + 5) % count1))); + } + } + } + + { + // example-begin fftshift2D-test-1 + (t2s = fftshift2D(t2)).run(exec); + // example-end fftshift2D-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare( + t2s(i, j), t2((i + (count0 + 1) / 2) % count0, + (j + (count1 + 1) / 2) % count1))); + } + } + } + + { + // example-begin ifftshift2D-test-1 + (t2s = ifftshift2D(t2)).run(exec); + // example-end ifftshift2D-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare( + t2s(i, j), + t2((i + (count0) / 2) % count0, (j + (count1) / 2) % count1))); + } + } + } + + // Right shifts + { + (t2s = shift<0>(t2, 5)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + index_t idim = i < 5 ? (t2.Size(0) - 5 + i) : (i - 5); + ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(idim, j))); + } + } + } + + { + (t2s = shift<1>(t2, 5)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + index_t jdim = j < 5 ? (t2.Size(1) - 5 + j) : (j - 5); + ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, jdim))); + } + } + } + + // Large shifts + { + (t2s = shift<0>(t2, -t2.Size(0) * 4)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2(i, j))); + } + } + } + + { + // Shift 4 times the size back, minus one. This should be equivalent to + // simply shifting by -1 + (t2s = shift<0>(t2, -t2.Size(0) * 4 - 1)).run(exec); + (t2s2 = shift<0>(t2, -1)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(t2s(i, j), t2s2(i, j))); + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/simple_executor_accessor_test.cu b/test/00_operators/simple_executor_accessor_test.cu new file mode 100644 index 00000000..922055c8 --- /dev/null +++ b/test/00_operators/simple_executor_accessor_test.cu @@ -0,0 +1,77 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsAllExecs, SimpleExecutorAccessorTests) +{ + MATX_ENTER_HANDLER(); + + using TestType = std::tuple_element_t<0, TypeParam>; + using ExecType = std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + const int N = 3; + + auto t0 = make_tensor({}); + auto t1 = make_tensor({N}); + auto t2 = make_tensor({N,N}); + auto t3 = make_tensor({N,N,N}); + auto t4 = make_tensor({N,N,N,N}); + auto t5 = make_tensor({N,N,N,N,N}); + auto t6 = make_tensor({N,N,N,N,N,N}); + + // Simple executor accessor tests for tensors of increasing dimensions. + // These tests verify that we can read from and write to all elements of + // a tensor, which in turn tests the multi-dimensional indexing logic. + // These tests do not assign unique values to each unique index, so they + // are not exhaustive tests. For the CUDA executor, the 5D and higher-rank + // tensors will use matxOpTDKernel whereas the smaller tensors each have + // custom implementations. + const TestType init = TestType(5); + const TestType expected = TestType(7); + (t0 = init).run(exec); + (t1 = init).run(exec); + (t2 = init).run(exec); + (t3 = init).run(exec); + (t4 = init).run(exec); + (t5 = init).run(exec); + (t6 = init).run(exec); + + // We use IF to generate both a read and a write for each tensor index. + IF(t0 == init, t0 = expected).run(exec); + IF(t1 == init, t1 = expected).run(exec); + IF(t2 == init, t2 = expected).run(exec); + IF(t3 == init, t3 = expected).run(exec); + IF(t4 == init, t4 = expected).run(exec); + IF(t5 == init, t5 = expected).run(exec); + IF(t6 == init, t6 = expected).run(exec); + + cudaStreamSynchronize(0); + + ASSERT_EQ(t0(), expected); + for (int i0 = 0; i0 < N; i0++) { + ASSERT_EQ(t1(i0), expected); + for (int i1 = 0; i1 < N; i1++) { + ASSERT_EQ(t2(i0,i1), expected); + for (int i2 = 0; i2 < N; i2++) { + ASSERT_EQ(t3(i0,i1,i2), expected); + for (int i3 = 0; i3 < N; i3++) { + ASSERT_EQ(t4(i0,i1,i2,i3), expected); + for (int i4 = 0; i4 < N; i4++) { + ASSERT_EQ(t5(i0,i1,i2,i3,i4), expected); + for (int i5 = 0; i5 < N; i5++) { + ASSERT_EQ(t6(i0,i1,i2,i3,i4,i5), expected); + } + } + } + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/slice_and_reduce_test.cu b/test/00_operators/slice_and_reduce_test.cu new file mode 100644 index 00000000..c5a928f1 --- /dev/null +++ b/test/00_operators/slice_and_reduce_test.cu @@ -0,0 +1,99 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, SliceAndReduceOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + using inner_type = typename inner_op_type_t::type; + ExecType exec{}; + + tensor_t t2t{{20, 10}}; + tensor_t t3t{{30, 20, 10}}; + (t2t = linspace<1>(t2t.Shape(), (inner_type)0, (inner_type)10)).run(exec); + (t3t = linspace<2>(t3t.Shape(), (inner_type)0, (inner_type)10)).run(exec); + exec.sync(); + + { + index_t j = 0; + // example-begin slice-test-3 + // Slice "t2t" by selecting column "j" from a 2D operator and converting to a 1D operator + auto t2sly = slice<1>(t2t, {0, j}, {matxEnd, matxDropDim}); + // example-end slice-test-3 + for (index_t i = 0; i < t2sly.Size(0); i++) { + ASSERT_EQ(t2sly(i), t2t(i, j)); + } + } + + { + index_t i = 0; + auto t2slx = slice<1>(t2t, {i, 0}, {matxDropDim, matxEnd}); + for (index_t j = 0; j < t2slx.Size(0); j++) { + ASSERT_EQ(t2slx(j), t2t(i, j)); + } + } + + { + index_t j = 0; + index_t k = 0; + auto t3slz = slice<1>(t3t, {0, j, k}, {matxEnd, matxDropDim, matxDropDim}); + for (index_t i = 0; i < t3slz.Size(0); i++) { + ASSERT_EQ(t3slz(i), t3t(i, j, k)); + } + } + + { + index_t i = 0; + index_t k = 0; + auto t3sly = slice<1>(t3t, {i, 0, k}, {matxDropDim, matxEnd, matxDropDim}); + for (index_t j = 0; j < t3sly.Size(0); j++) { + ASSERT_EQ(t3sly(j), t3t(i, j, k)); + } + } + + { + index_t i = 0; + index_t j = 0; + auto t3slx = slice<1>(t3t, {i, j, 0}, {matxDropDim, matxDropDim, matxEnd}); + for (index_t k = 0; k < t3slx.Size(0); k++) { + ASSERT_EQ(t3slx(k), t3t(i, j, k)); + } + } + + { + index_t k = 0; + auto t3slzy = slice<2>(t3t, {0, 0, k}, {matxEnd, matxEnd, matxDropDim}); + for (index_t i = 0; i < t3slzy.Size(0); i++) { + for (index_t j = 0; j < t3slzy.Size(1); j++) { + ASSERT_EQ(t3slzy(i, j), t3t(i, j, k)); + } + } + } + + { + index_t j = 0; + auto t3slzx = slice<2>(t3t, {0, j, 0}, {matxEnd, matxDropDim, matxEnd}); + for (index_t i = 0; i < t3slzx.Size(0); i++) { + for (index_t k = 0; k < t3slzx.Size(1); k++) { + ASSERT_EQ(t3slzx(i, k), t3t(i, j, k)); + } + } + } + + { + index_t i = 0; + auto t3slyx = slice<2>(t3t, {i, 0, 0}, {matxDropDim, matxEnd, matxEnd}); + for (index_t j = 0; j < t3slyx.Size(0); j++) { + for (index_t k = 0; k < t3slyx.Size(1); k++) { + ASSERT_EQ(t3slyx(j, k), t3t(i, j, k)); + } + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/slice_and_reshape_test.cu b/test/00_operators/slice_and_reshape_test.cu new file mode 100644 index 00000000..b76ddc33 --- /dev/null +++ b/test/00_operators/slice_and_reshape_test.cu @@ -0,0 +1,35 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexNonHalfAllExecs, SliceAndReshape) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + { + // Unit test combining slice with reshape which showed a bug in the past + auto t = make_tensor({100}); + (t = linspace<0>(t.Shape(), (TestType)0, (TestType)99)).run(exec); + auto rs = reshape(t, {2, 10, 5}); + auto s = slice(rs, {0, 0, 2}, {matxEnd, matxEnd, matxEnd}); + exec.sync(); + + for (index_t i = 0; i < s.Size(0); i++) { + for (index_t j = 0; j < s.Size(1); j++) { + for (index_t k = 0; k < s.Size(2); k++) { + ASSERT_EQ(t(i*50 + j*5 + k+2), s(i,j,k)); + } + } + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/slice_stride_test.cu b/test/00_operators/slice_stride_test.cu new file mode 100644 index 00000000..35130922 --- /dev/null +++ b/test/00_operators/slice_stride_test.cu @@ -0,0 +1,36 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, SliceStrideOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + // example-begin slice-test-2 + auto t1 = make_tensor({10}); + + t1.SetVals({10, 20, 30, 40, 50, 60, 70, 80, 90, 100}); + + // Slice every other element from a 1D tensor (stride of two) + auto t1t = slice(t1, {0}, {matxEnd}, {2}); + // example-end slice-test-2 + + for (index_t i = 0; i < t1.Size(0); i += 2) { + ASSERT_EQ(t1(i), t1t(i / 2)); + } + + auto t1t2 = slice(t1, {2}, {matxEnd}, {2}); + + for (index_t i = 0; i < t1t2.Size(0); i++) { + ASSERT_EQ(TestType(30 + 20 * i), t1t2(i)); + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/slice_test.cu b/test/00_operators/slice_test.cu new file mode 100644 index 00000000..653e0efb --- /dev/null +++ b/test/00_operators/slice_test.cu @@ -0,0 +1,99 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, SliceOp) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + using inner_type = typename inner_op_type_t::type; + + ExecType exec{}; + + // example-begin slice-test-1 + auto t2 = make_tensor({20, 10}); + auto t3 = make_tensor({30, 20, 10}); + auto t4 = make_tensor({40, 30, 20, 10}); + + (t2 = linspace<1>(t2.Shape(), (inner_type)0, (inner_type)10)).run(exec); + (t3 = linspace<2>(t3.Shape(), (inner_type)0, (inner_type)10)).run(exec); + (t4 = linspace<3>(t4.Shape(), (inner_type)0, (inner_type)10)).run(exec); + exec.sync(); + + // Slice with different start and end points in each dimension + auto t2t = slice(t2, {1, 2}, {3, 5}); + auto t3t = slice(t3, {1, 2, 3}, {3, 5, 7}); + auto t4t = slice(t4, {1, 2, 3, 4}, {3, 5, 7, 9}); + // example-end slice-test-1 + + ASSERT_EQ(t2t.Size(0), 2); + ASSERT_EQ(t2t.Size(1), 3); + + ASSERT_EQ(t3t.Size(0), 2); + ASSERT_EQ(t3t.Size(1), 3); + ASSERT_EQ(t3t.Size(2), 4); + + ASSERT_EQ(t4t.Size(0), 2); + ASSERT_EQ(t4t.Size(1), 3); + ASSERT_EQ(t4t.Size(2), 4); + ASSERT_EQ(t4t.Size(3), 5); + + for (index_t i = 0; i < t2t.Size(0); i++) { + for (index_t j = 0; j < t2t.Size(1); j++) { + ASSERT_EQ(t2t(i, j), t2(i + 1, j + 2)); + } + } + + for (index_t i = 0; i < t3t.Size(0); i++) { + for (index_t j = 0; j < t3t.Size(1); j++) { + for (index_t k = 0; k < t3t.Size(2); k++) { + ASSERT_EQ(t3t(i, j, k), t3(i + 1, j + 2, k + 3)); + } + } + } + + for (index_t i = 0; i < t4t.Size(0); i++) { + for (index_t j = 0; j < t4t.Size(1); j++) { + for (index_t k = 0; k < t4t.Size(2); k++) { + for (index_t l = 0; l < t4t.Size(3); l++) { + ASSERT_EQ(t4t(i, j, k, l), t4(i + 1, j + 2, k + 3, l + 4)); + } + } + } + } + + // Test SliceOp applied to a transform, using transpose() as an example transform + auto t2trans = make_tensor({3, 2}); + (t2trans = slice(transpose(t2), {2, 1}, {5, 3})).run(exec); + exec.sync(); + + ASSERT_EQ(t2trans.Size(0), 3); + ASSERT_EQ(t2trans.Size(1), 2); + for (index_t i = 0; i < t2trans.Size(0); i++) { + for (index_t j = 0; j < t2trans.Size(1); j++) { + ASSERT_EQ(t2trans(i, j), t2(j + 1, i + 2)); + } + } + + // Negative indexing. These should give the same results + // example-begin slice-test-4 + auto t2sn = slice(t2, {-4, -5}, {matxEnd, matxEnd}); + auto t2s = slice(t2, {t2.Size(0) - 4, t2.Size(1) - 5}, {matxEnd, matxEnd}); + + // example-end slice-test-4 + exec.sync(); + ASSERT_EQ(t2sn.Size(0), t2s.Size(0)); + ASSERT_EQ(t2sn.Size(1), t2s.Size(1)); + for (index_t i = 0; i < t2sn.Size(0); i++) { + for (index_t j = 0; j < t2sn.Size(1); j++) { + ASSERT_EQ(t2sn(i, j), t2s(i, j)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/sph2cart_test.cu b/test/00_operators/sph2cart_test.cu new file mode 100644 index 00000000..345047ad --- /dev/null +++ b/test/00_operators/sph2cart_test.cu @@ -0,0 +1,37 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, Sphere2Cart) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + int n = 5; + + auto xi = range<0>({n},(TestType)1,(TestType)1); + auto yi = range<0>({n},(TestType)1,(TestType)1); + auto zi = range<0>({n},(TestType)1,(TestType)1); + + // example-begin cart2sph-test-1 + auto [theta, phi, r] = cart2sph(xi, yi, zi); + // example-end cart2sph-test-1 + + // example-begin sph2cart-test-1 + auto [x, y, z] = sph2cart(theta, phi, r); + // example-end sph2cart-test-1 + + for(int i=0; i; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t count = 512; + tensor_t t2({count, count}); + tensor_t t2t({count, count}); + + for (index_t i = 0; i < count; i++) { + for (index_t j = 0; j < count; j++) { + t2(i, j) = static_cast>(i * count + j); + } + } + + matx::copy(t2t, t2, exec); + + exec.sync(); + + for (index_t i = 0; i < count; i++) { + for (index_t j = 0; j < count; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2t(i, j), + TestType(i * count + (double)j))); + } + } + + (t2t = transpose(t2)).run(exec); + + exec.sync(); + + for (index_t i = 0; i < count; i++) { + for (index_t j = 0; j < count; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j), + TestType(i * count + (double)j))); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(t2t(j, i), TestType(i * count + j))); + } + } + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsNumericAllExecs, NonSquareTranspose) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count = 100; + index_t count1 = 200, count2 = 100; + tensor_t t2({count1, count2}); + tensor_t t2t({count2, count1}); + + for (index_t i = 0; i < count1; i++) { + for (index_t j = 0; j < count2; j++) { + t2(i, j) = static_cast>(i * count + j); + } + } + + (t2t = transpose(t2)).run(exec); + exec.sync(); + + for (index_t i = 0; i < count1; i++) { + for (index_t j = 0; j < count2; j++) { + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2(i, j), + TestType(i * count + (double)j))); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(t2t(j, i), + TestType(i * count + (double)j))); + } + } + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/stack_test.cu b/test/00_operators/stack_test.cu new file mode 100644 index 00000000..86bd72a8 --- /dev/null +++ b/test/00_operators/stack_test.cu @@ -0,0 +1,50 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsNumericAllExecs, Stack) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto t1a = make_tensor({5}); + auto t1b = make_tensor({5}); + auto t1c = make_tensor({5}); + + auto cop = concat(0, t1a, t1b, t1c); + + (cop = (TestType)2).run(exec); + exec.sync(); + + { + // example-begin stack-test-1 + // Stack 1D operators "t1a", "t1b", and "t1c" together along the first dimension + auto op = stack(0, t1a, t1b, t1c); + // example-end stack-test-1 + + for(int i = 0; i < t1a.Size(0); i++) { + ASSERT_EQ(op(0,i), t1a(i)); + ASSERT_EQ(op(1,i), t1b(i)); + ASSERT_EQ(op(2,i), t1c(i)); + } + } + + { + auto op = stack(1, t1a, t1b, t1c); + + for(int i = 0; i < t1a.Size(0); i++) { + ASSERT_EQ(op(i,0), t1a(i)); + ASSERT_EQ(op(i,1), t1b(i)); + ASSERT_EQ(op(i,2), t1c(i)); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/toeplitz_test.cu b/test/00_operators/toeplitz_test.cu new file mode 100644 index 00000000..d384059f --- /dev/null +++ b/test/00_operators/toeplitz_test.cu @@ -0,0 +1,47 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatAllExecs, Toeplitz) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + auto pb = std::make_unique(); + pb->InitAndRunTVGenerator("00_operators", "toeplitz", "run", {5, 5, 6}); + + ExecType exec{}; + auto out1 = make_tensor({5, 5}); + auto out2 = make_tensor({5, 5}); + auto out3 = make_tensor({5, 6}); + auto c = make_tensor({5}); + auto r = make_tensor({5}); + auto r2 = make_tensor({6}); + + pb->NumpyToTensorView(c, "c"); + pb->NumpyToTensorView(r, "r"); + pb->NumpyToTensorView(r2, "r2"); + + // example-begin toeplitz-test-1 + (out1 = toeplitz(c)).run(exec); + // example-end toeplitz-test-1 + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out1, "out1", 0.01); + + // example-begin toeplitz-test-2 + (out2 = toeplitz(c, r)).run(exec); + // example-end toeplitz-test-2 + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out2, "out2", 0.01); + + (out3 = toeplitz(c, r2)).run(exec); + exec.sync(); + MATX_TEST_ASSERT_COMPARE(pb, out3, "out3", 0.01); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/transpose_test.cu b/test/00_operators/transpose_test.cu new file mode 100644 index 00000000..d1e15816 --- /dev/null +++ b/test/00_operators/transpose_test.cu @@ -0,0 +1,131 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + +TYPED_TEST(OperatorTestsNumericAllExecs, Transpose3D) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + index_t num_rows = 5998; + index_t num_cols = 64; + + tensor_t t3 ({1, num_rows, num_cols}); + tensor_t t3t({1, num_cols, num_rows}); + + for (index_t i = 0; i < num_rows; i++) { + for (index_t j = 0; j < num_cols; j++) { + t3(0, i, j) = static_cast>(i * num_cols + j); + } + } + + (t3t = transpose_matrix(t3)).run(exec); + exec.sync(); + + if constexpr (std::is_same_v) { + ASSERT_EQ(cudaGetLastError(), cudaSuccess); + } + + for (index_t i = 0; i < num_rows; i++) { + for (index_t j = 0; j < num_cols; j++) { + EXPECT_EQ(t3(0, i, j), t3t(0, j, i)); + } + } + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsNumericAllExecs, TransposeVsTransposeMatrix) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + // example-begin transpose-test-1 + // ExecType is an executor type (e.g. matx::cudaExecutor for executing on the GPU). + ExecType exec{}; + + const index_t m = 3; + const index_t n = 5; + const index_t p = 7; + + // TestType is the tensor data type + tensor_t t3 ({m,n,p}); + tensor_t t3t ({p,n,m}); + tensor_t t3tm({m,p,n}); + + for (index_t i = 0; i < m; i++) { + for (index_t j = 0; j < n; j++) { + for (index_t k = 0; k < p; k++) { + t3(i, j, k) = static_cast>(i*n*p + j*p + k); + } + } + } + + (t3t = transpose(t3)).run(exec); + (t3tm = transpose_matrix(t3)).run(exec); + + exec.sync(); + if constexpr (std::is_same_v) { + ASSERT_EQ(cudaGetLastError(), cudaSuccess); + } + + for (index_t i = 0; i < m; i++) { + for (index_t j = 0; j < n; j++) { + for (index_t k = 0; k < p; k++) { + // transpose() permutes all dimensions whereas transpose_matrix() only permutes the + // last two dimensions. + EXPECT_EQ(t3(i,j,k), t3t(k,j,i)); + EXPECT_EQ(t3(i,j,k), t3tm(i,k,j)); + } + } + } + // example-end transpose-test-1 + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsComplexTypesAllExecs, HermitianTranspose) +{ + MATX_ENTER_HANDLER(); + + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + index_t count0 = 100; + index_t count1 = 200; + tensor_t t2({count0, count1}); + tensor_t t2s({count1, count0}); + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + TestType tmp = {(float)i, (float)-j}; + t2(i, j) = tmp; + } + } + + // example-begin hermitianT-test-1 + (t2s = hermitianT(t2)).run(exec); + // example-end hermitianT-test-1 + exec.sync(); + + for (index_t i = 0; i < count0; i++) { + for (index_t j = 0; j < count1; j++) { + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(static_cast(t2s(j, i).real()), + static_cast(t2(i, j).real()))); + EXPECT_TRUE( + MatXUtils::MatXTypeCompare(-static_cast(t2s(j, i).imag()), + static_cast(t2(i, j).imag()))); + } + } + MATX_EXIT_HANDLER(); +} diff --git a/test/00_operators/trig_funcs_test.cu b/test/00_operators/trig_funcs_test.cu new file mode 100644 index 00000000..d1c2832c --- /dev/null +++ b/test/00_operators/trig_funcs_test.cu @@ -0,0 +1,95 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + +TYPED_TEST(OperatorTestsFloatNonComplexAllExecs, TrigFuncs) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + auto tiv0 = make_tensor({}); + auto tov0 = make_tensor({}); + + TestType c = GenerateData(); + tiv0() = c; + // example-begin sin-test-1 + (tov0 = sin(tiv0)).run(exec); + // example-end sin-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sin(c))); + + // example-begin cos-test-1 + (tov0 = cos(tiv0)).run(exec); + // example-end cos-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_cos(c))); + + // example-begin tan-test-1 + (tov0 = tan(tiv0)).run(exec); + // example-end tan-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_tan(c))); + + // example-begin asin-test-1 + (tov0 = asin(tiv0)).run(exec); + // example-end asin-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_asin(c))); + + // example-begin acos-test-1 + (tov0 = acos(tiv0)).run(exec); + // example-end acos-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_acos(c))); + + // example-begin atan-test-1 + (tov0 = atan(tiv0)).run(exec); + // example-end atan-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_atan(c))); + + // example-begin sinh-test-1 + (tov0 = sinh(tiv0)).run(exec); + // example-end sinh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_sinh(c))); + + // example-begin cosh-test-1 + (tov0 = cosh(tiv0)).run(exec); + // example-end cosh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_cosh(c))); + + // example-begin tanh-test-1 + (tov0 = tanh(tiv0)).run(exec); + // example-end tanh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_tanh(c))); + + // example-begin asinh-test-1 + (tov0 = asinh(tiv0)).run(exec); + // example-end asinh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_asinh(c))); + + // example-begin acosh-test-1 + (tov0 = acosh(tiv0)).run(exec); + // example-end acosh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_acosh(c))); + + // example-begin atanh-test-1 + (tov0 = atanh(tiv0)).run(exec); + // example-end atanh-test-1 + exec.sync(); + EXPECT_TRUE(MatXUtils::MatXTypeCompare(tov0(), detail::_internal_atanh(c))); + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/00_operators/updownsample_test.cu b/test/00_operators/updownsample_test.cu new file mode 100644 index 00000000..fcdcc084 --- /dev/null +++ b/test/00_operators/updownsample_test.cu @@ -0,0 +1,84 @@ +#include "operator_test_types.hpp" +#include "matx.h" +#include "test_types.h" +#include "utilities.h" + +using namespace matx; +using namespace matx::test; + + + +TYPED_TEST(OperatorTestsNumericAllExecs, Upsample) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + { + // example-begin upsample-test-1 + // Upsample a signal of length 100 by 5 + int n = 5; + + auto t1 = make_tensor({100}); + (t1 = static_cast(1)).run(exec); + auto us_op = upsample(t1, 0, n); + // example-end upsample-test-1 + exec.sync(); + + ASSERT_TRUE(us_op.Size(0) == t1.Size(0) * n); + for (index_t i = 0; i < us_op.Size(0); i++) { + if ((i % n) == 0) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(us_op(i), t1(i / n))); + } + else { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(us_op(i), static_cast(0))); + } + } + } + + MATX_EXIT_HANDLER(); +} + +TYPED_TEST(OperatorTestsNumericAllExecs, Downsample) +{ + MATX_ENTER_HANDLER(); + using TestType = cuda::std::tuple_element_t<0, TypeParam>; + using ExecType = cuda::std::tuple_element_t<1, TypeParam>; + + ExecType exec{}; + + { + // example-begin downsample-test-1 + int n = 5; + + auto t1 = make_tensor({100}); + (t1 = static_cast(1)).run(exec); + auto ds_op = downsample(t1, 0, n); + // example-end downsample-test-1 + exec.sync(); + + ASSERT_TRUE(ds_op.Size(0) == t1.Size(0) / n); + for (index_t i = 0; i < ds_op.Size(0); i++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(ds_op(i), t1(i * n))); + } + } + + { + int n = 3; + + auto t1 = make_tensor({100}); + (t1 = static_cast(1)).run(exec); + auto ds_op = downsample(t1, 0, n); + + exec.sync(); + + ASSERT_TRUE(ds_op.Size(0) == t1.Size(0) / n + 1); + for (index_t i = 0; i < ds_op.Size(0); i++) { + ASSERT_TRUE(MatXUtils::MatXTypeCompare(ds_op(i), t1(i * n))); + } + } + + MATX_EXIT_HANDLER(); +} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 16b6e486..4fa7cb6f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.18) +include(00_operators/CMakeLists.txt) +list(TRANSFORM OPERATOR_TEST_FILES PREPEND "00_operators/") + set (test_sources 00_tensor/BasicTensorTests.cu 00_tensor/CUBTests.cu @@ -7,7 +10,7 @@ set (test_sources 00_tensor/VizTests.cu 00_tensor/TensorCreationTests.cu 00_tensor/EinsumTests.cu - 00_operators/OperatorTests.cu + ${OPERATOR_TEST_FILES} 00_operators/GeneratorTests.cu 00_operators/PWelch.cu 00_operators/ReductionTests.cu From 63952f4f7b427872b37ce67258dfb8ab1b81665a Mon Sep 17 00:00:00 2001 From: cliffburdick Date: Fri, 7 Feb 2025 20:12:27 -0800 Subject: [PATCH 2/2] Update docs links --- docs/_sources/api/casting/as_int8.rst | 2 +- docs/_sources/api/casting/as_type.rst | 2 +- docs/_sources/api/dft/utility/fftshift2d.rst | 2 +- docs/_sources/api/dft/utility/ifftshift2d.rst | 2 +- docs/_sources/api/logic/bitwise/and.rst | 2 +- docs/_sources/api/logic/bitwise/or.rst | 2 +- docs/_sources/api/logic/bitwise/xor.rst | 2 +- docs/_sources/api/logic/comparison/equal.rst | 2 +- docs/_sources/api/logic/comparison/gt.rst | 2 +- docs/_sources/api/logic/comparison/gte.rst | 2 +- .../_sources/api/logic/comparison/isclose.rst | 2 +- docs/_sources/api/logic/comparison/lt.rst | 2 +- docs/_sources/api/logic/comparison/lte.rst | 2 +- docs/_sources/api/logic/comparison/neq.rst | 2 +- docs/_sources/api/logic/logical/and.rst | 2 +- docs/_sources/api/logic/logical/not.rst | 2 +- docs/_sources/api/logic/logical/or.rst | 2 +- docs/_sources/api/manipulation/basic/if.rst | 2 +- .../api/manipulation/basic/ifelse.rst | 2 +- .../api/manipulation/basic/permute.rst | 2 +- .../_sources/api/manipulation/basic/slice.rst | 14 +-- .../api/manipulation/joinrepeat/clone.rst | 2 +- .../api/manipulation/joinrepeat/concat.rst | 2 +- .../api/manipulation/joinrepeat/flatten.rst | 2 +- .../api/manipulation/joinrepeat/lcollapse.rst | 2 +- .../api/manipulation/joinrepeat/rcollapse.rst | 2 +- .../api/manipulation/joinrepeat/repmat.rst | 2 +- .../api/manipulation/joinrepeat/stack.rst | 2 +- .../api/manipulation/rearranging/fliplr.rst | 2 +- .../api/manipulation/rearranging/flipud.rst | 2 +- .../api/manipulation/rearranging/overlap.rst | 2 +- .../api/manipulation/rearranging/permute.rst | 2 +- .../api/manipulation/rearranging/reshape.rst | 2 +- .../api/manipulation/rearranging/reverse.rst | 2 +- .../api/manipulation/rearranging/shift.rst | 2 +- .../api/manipulation/selecting/at.rst | 2 +- .../api/manipulation/selecting/remap.rst | 4 +- docs/_sources/api/math/arithmetic/add.rst | 2 +- docs/_sources/api/math/arithmetic/div.rst | 2 +- docs/_sources/api/math/arithmetic/fmod.rst | 2 +- docs/_sources/api/math/arithmetic/mod.rst | 2 +- docs/_sources/api/math/arithmetic/mul.rst | 2 +- docs/_sources/api/math/arithmetic/neg.rst | 2 +- docs/_sources/api/math/arithmetic/pow.rst | 2 +- docs/_sources/api/math/arithmetic/sub.rst | 2 +- docs/_sources/api/math/complex/angle.rst | 2 +- docs/_sources/api/math/complex/hermitiant.rst | 2 +- docs/_sources/api/math/complex/norm.rst | 2 +- docs/_sources/api/math/complex/real.rst | 2 +- docs/_sources/api/math/explog/exp.rst | 2 +- docs/_sources/api/math/explog/expj.rst | 2 +- docs/_sources/api/math/explog/log.rst | 2 +- docs/_sources/api/math/explog/log10.rst | 2 +- docs/_sources/api/math/explog/log2.rst | 2 +- docs/_sources/api/math/extrema/max.rst | 2 +- docs/_sources/api/math/extrema/min.rst | 2 +- docs/_sources/api/math/misc/abs.rst | 2 +- docs/_sources/api/math/misc/sqrt.rst | 2 +- docs/_sources/api/math/round/ceil.rst | 2 +- docs/_sources/api/math/round/floor.rst | 2 +- docs/_sources/api/math/round/round.rst | 2 +- docs/_sources/api/math/trig/acos.rst | 2 +- docs/_sources/api/math/trig/acosh.rst | 2 +- docs/_sources/api/math/trig/asin.rst | 2 +- docs/_sources/api/math/trig/asinh.rst | 2 +- docs/_sources/api/math/trig/atan.rst | 2 +- docs/_sources/api/math/trig/atanh.rst | 2 +- docs/_sources/api/math/trig/cart2sph.rst | 2 +- docs/_sources/api/math/trig/cos.rst | 2 +- docs/_sources/api/math/trig/cosh.rst | 2 +- docs/_sources/api/math/trig/sin.rst | 2 +- docs/_sources/api/math/trig/sinh.rst | 2 +- docs/_sources/api/math/trig/sph2cart.rst | 2 +- docs/_sources/api/math/trig/tan.rst | 2 +- docs/_sources/api/math/trig/tanh.rst | 2 +- docs/_sources/api/polynomials/legendre.rst | 2 +- .../api/signalimage/general/downsample.rst | 2 +- .../api/signalimage/general/upsample.rst | 2 +- docs_input/api/casting/as_complex_double.rst | 4 +- docs_input/api/casting/as_complex_float.rst | 4 +- docs_input/api/casting/as_int8.rst | 2 +- docs_input/api/casting/as_type.rst | 2 +- docs_input/api/dft/utility/fftshift2d.rst | 4 +- docs_input/api/dft/utility/ifftshift2d.rst | 2 +- docs_input/api/linalg/other/cross.rst | 2 +- docs_input/api/linalg/other/toeplitz.rst | 4 +- docs_input/api/logic/bitwise/and.rst | 2 +- docs_input/api/logic/bitwise/or.rst | 2 +- docs_input/api/logic/bitwise/xor.rst | 2 +- docs_input/api/logic/comparison/equal.rst | 2 +- docs_input/api/logic/comparison/gt.rst | 2 +- docs_input/api/logic/comparison/gte.rst | 2 +- docs_input/api/logic/comparison/isclose.rst | 2 +- docs_input/api/logic/comparison/lt.rst | 2 +- docs_input/api/logic/comparison/lte.rst | 2 +- docs_input/api/logic/comparison/neq.rst | 2 +- docs_input/api/logic/logical/and.rst | 2 +- docs_input/api/logic/logical/not.rst | 2 +- docs_input/api/logic/logical/or.rst | 2 +- docs_input/api/logic/truth/isinf.rst | 2 +- docs_input/api/logic/truth/isnan.rst | 2 +- docs_input/api/manipulation/basic/if.rst | 2 +- docs_input/api/manipulation/basic/ifelse.rst | 2 +- docs_input/api/manipulation/basic/slice.rst | 8 +- .../api/manipulation/joinrepeat/clone.rst | 2 +- .../api/manipulation/joinrepeat/concat.rst | 2 +- .../api/manipulation/joinrepeat/flatten.rst | 2 +- .../api/manipulation/joinrepeat/lcollapse.rst | 2 +- .../api/manipulation/joinrepeat/rcollapse.rst | 2 +- .../api/manipulation/joinrepeat/repmat.rst | 2 +- .../api/manipulation/joinrepeat/stack.rst | 2 +- .../api/manipulation/rearranging/fliplr.rst | 2 +- .../api/manipulation/rearranging/flipud.rst | 2 +- .../api/manipulation/rearranging/overlap.rst | 2 +- .../api/manipulation/rearranging/permute.rst | 2 +- .../api/manipulation/rearranging/reshape.rst | 2 +- .../api/manipulation/rearranging/reverse.rst | 2 +- .../api/manipulation/rearranging/shift.rst | 4 +- .../manipulation/rearranging/transpose.rst | 2 +- docs_input/api/manipulation/selecting/at.rst | 2 +- .../api/manipulation/selecting/remap.rst | 4 +- docs_input/api/math/arithmetic/add.rst | 2 +- docs_input/api/math/arithmetic/div.rst | 2 +- docs_input/api/math/arithmetic/fmod.rst | 4 +- docs_input/api/math/arithmetic/mod.rst | 2 +- docs_input/api/math/arithmetic/mul.rst | 2 +- docs_input/api/math/arithmetic/neg.rst | 2 +- docs_input/api/math/arithmetic/pow.rst | 2 +- docs_input/api/math/arithmetic/sub.rst | 2 +- docs_input/api/math/complex/angle.rst | 2 +- docs_input/api/math/complex/conj.rst | 2 +- docs_input/api/math/complex/hermitiant.rst | 2 +- docs_input/api/math/complex/imag.rst | 4 +- docs_input/api/math/complex/real.rst | 4 +- docs_input/api/math/explog/exp.rst | 2 +- docs_input/api/math/explog/expj.rst | 4 +- docs_input/api/math/explog/log.rst | 5 +- docs_input/api/math/explog/log10.rst | 4 +- docs_input/api/math/explog/log2.rst | 4 +- docs_input/api/math/extrema/max.rst | 2 +- docs_input/api/math/extrema/min.rst | 2 +- docs_input/api/math/misc/abs.rst | 2 +- docs_input/api/math/misc/abs2.rst | 4 +- docs_input/api/math/misc/frexp.rst | 4 +- docs_input/api/math/misc/frexpc.rst | 6 +- docs_input/api/math/misc/rsqrt.rst | 2 +- docs_input/api/math/misc/sqrt.rst | 2 +- docs_input/api/math/round/ceil.rst | 2 +- docs_input/api/math/round/floor.rst | 4 +- docs_input/api/math/round/round.rst | 6 +- docs_input/api/math/trig/acos.rst | 2 +- docs_input/api/math/trig/acosh.rst | 2 +- docs_input/api/math/trig/asin.rst | 2 +- docs_input/api/math/trig/asinh.rst | 2 +- docs_input/api/math/trig/atan.rst | 2 +- docs_input/api/math/trig/atanh.rst | 2 +- docs_input/api/math/trig/cart2sph.rst | 4 +- docs_input/api/math/trig/cos.rst | 4 +- docs_input/api/math/trig/cosh.rst | 4 +- docs_input/api/math/trig/sin.rst | 2 +- docs_input/api/math/trig/sinh.rst | 2 +- docs_input/api/math/trig/sph2cart.rst | 2 +- docs_input/api/math/trig/tan.rst | 2 +- docs_input/api/math/trig/tanh.rst | 2 +- docs_input/api/polynomials/legendre.rst | 2 +- docs_input/api/polynomials/polyval.rst | 2 +- .../api/signalimage/general/downsample.rst | 2 +- .../api/signalimage/general/upsample.rst | 2 +- include/matx/core/make_sparse_tensor.h | 6 +- test/00_operators/reshape_test.cu | 88 +++++++------------ 170 files changed, 237 insertions(+), 260 deletions(-) diff --git a/docs/_sources/api/casting/as_int8.rst b/docs/_sources/api/casting/as_int8.rst index b3c6ee29..1072ce96 100644 --- a/docs/_sources/api/casting/as_int8.rst +++ b/docs/_sources/api/casting/as_int8.rst @@ -10,7 +10,7 @@ Cast an operator to an int8_t Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_int8-test-1 :end-before: example-end as_int8-test-1 diff --git a/docs/_sources/api/casting/as_type.rst b/docs/_sources/api/casting/as_type.rst index 4f358545..05b19add 100644 --- a/docs/_sources/api/casting/as_type.rst +++ b/docs/_sources/api/casting/as_type.rst @@ -10,7 +10,7 @@ Cast an operator to an arbitrary type Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_type-test-1 :end-before: example-end as_type-test-1 diff --git a/docs/_sources/api/dft/utility/fftshift2d.rst b/docs/_sources/api/dft/utility/fftshift2d.rst index 449b24e8..d95de6e1 100644 --- a/docs/_sources/api/dft/utility/fftshift2d.rst +++ b/docs/_sources/api/dft/utility/fftshift2d.rst @@ -9,7 +9,7 @@ Perform a 2D shift by shifting the zero-frequency component to the center of the Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin fftshift2D-test-1 :end-before: example-end fftshift2D-test-1 diff --git a/docs/_sources/api/dft/utility/ifftshift2d.rst b/docs/_sources/api/dft/utility/ifftshift2d.rst index 702b7129..427159d3 100644 --- a/docs/_sources/api/dft/utility/ifftshift2d.rst +++ b/docs/_sources/api/dft/utility/ifftshift2d.rst @@ -9,7 +9,7 @@ Perform a 2D inverse by shifting a zero-frequency-shifted version back to the or Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin ifftshift2D-test-1 :end-before: example-end ifftshift2D-test-1 diff --git a/docs/_sources/api/logic/bitwise/and.rst b/docs/_sources/api/logic/bitwise/and.rst index fa9e0fb4..3a53a852 100644 --- a/docs/_sources/api/logic/bitwise/and.rst +++ b/docs/_sources/api/logic/bitwise/and.rst @@ -10,7 +10,7 @@ Bitwise AND Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin and-test-1 :end-before: example-end and-test-1 diff --git a/docs/_sources/api/logic/bitwise/or.rst b/docs/_sources/api/logic/bitwise/or.rst index 8d19f0ed..f0e502fa 100644 --- a/docs/_sources/api/logic/bitwise/or.rst +++ b/docs/_sources/api/logic/bitwise/or.rst @@ -10,7 +10,7 @@ Bitwise OR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin or-test-1 :end-before: example-end or-test-1 diff --git a/docs/_sources/api/logic/bitwise/xor.rst b/docs/_sources/api/logic/bitwise/xor.rst index ff2ba51b..c30cb010 100644 --- a/docs/_sources/api/logic/bitwise/xor.rst +++ b/docs/_sources/api/logic/bitwise/xor.rst @@ -10,7 +10,7 @@ Bitwise XOR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin xor-test-1 :end-before: example-end xor-test-1 diff --git a/docs/_sources/api/logic/comparison/equal.rst b/docs/_sources/api/logic/comparison/equal.rst index be6b50d8..9d443bf1 100644 --- a/docs/_sources/api/logic/comparison/equal.rst +++ b/docs/_sources/api/logic/comparison/equal.rst @@ -10,7 +10,7 @@ Equality test Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin eq-test-1 :end-before: example-end eq-test-1 diff --git a/docs/_sources/api/logic/comparison/gt.rst b/docs/_sources/api/logic/comparison/gt.rst index 8f42f858..c6b7ad63 100644 --- a/docs/_sources/api/logic/comparison/gt.rst +++ b/docs/_sources/api/logic/comparison/gt.rst @@ -10,7 +10,7 @@ Greater than Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin gt-test-1 :end-before: example-end gt-test-1 diff --git a/docs/_sources/api/logic/comparison/gte.rst b/docs/_sources/api/logic/comparison/gte.rst index c5c113d0..070ad19c 100644 --- a/docs/_sources/api/logic/comparison/gte.rst +++ b/docs/_sources/api/logic/comparison/gte.rst @@ -10,7 +10,7 @@ Greater than or equal to Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin gte-test-1 :end-before: example-end gte-test-1 diff --git a/docs/_sources/api/logic/comparison/isclose.rst b/docs/_sources/api/logic/comparison/isclose.rst index 58d2d750..b124c178 100644 --- a/docs/_sources/api/logic/comparison/isclose.rst +++ b/docs/_sources/api/logic/comparison/isclose.rst @@ -13,7 +13,7 @@ atomics are not available in hardware. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin isclose-test-1 :end-before: example-end isclose-test-1 diff --git a/docs/_sources/api/logic/comparison/lt.rst b/docs/_sources/api/logic/comparison/lt.rst index 2322c15a..b05b8dcf 100644 --- a/docs/_sources/api/logic/comparison/lt.rst +++ b/docs/_sources/api/logic/comparison/lt.rst @@ -10,7 +10,7 @@ Less than Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lt-test-1 :end-before: example-end lt-test-1 diff --git a/docs/_sources/api/logic/comparison/lte.rst b/docs/_sources/api/logic/comparison/lte.rst index 1da681d9..75a03592 100644 --- a/docs/_sources/api/logic/comparison/lte.rst +++ b/docs/_sources/api/logic/comparison/lte.rst @@ -10,7 +10,7 @@ Less than or equal to Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lte-test-1 :end-before: example-end lte-test-1 diff --git a/docs/_sources/api/logic/comparison/neq.rst b/docs/_sources/api/logic/comparison/neq.rst index 25a5277d..992b2d4a 100644 --- a/docs/_sources/api/logic/comparison/neq.rst +++ b/docs/_sources/api/logic/comparison/neq.rst @@ -10,7 +10,7 @@ Non-equality test Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin neq-test-1 :end-before: example-end neq-test-1 diff --git a/docs/_sources/api/logic/logical/and.rst b/docs/_sources/api/logic/logical/and.rst index 8050761d..6e68f341 100644 --- a/docs/_sources/api/logic/logical/and.rst +++ b/docs/_sources/api/logic/logical/and.rst @@ -10,7 +10,7 @@ Logical AND Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin land-test-1 :end-before: example-end land-test-1 diff --git a/docs/_sources/api/logic/logical/not.rst b/docs/_sources/api/logic/logical/not.rst index 9725d85d..a316c060 100644 --- a/docs/_sources/api/logic/logical/not.rst +++ b/docs/_sources/api/logic/logical/not.rst @@ -10,7 +10,7 @@ Logical NOT Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lnot-test-1 :end-before: example-end lnot-test-1 diff --git a/docs/_sources/api/logic/logical/or.rst b/docs/_sources/api/logic/logical/or.rst index c558a0dd..95837947 100644 --- a/docs/_sources/api/logic/logical/or.rst +++ b/docs/_sources/api/logic/logical/or.rst @@ -10,7 +10,7 @@ Logical OR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lor-test-1 :end-before: example-end lor-test-1 diff --git a/docs/_sources/api/manipulation/basic/if.rst b/docs/_sources/api/manipulation/basic/if.rst index 81920c4f..101c004f 100644 --- a/docs/_sources/api/manipulation/basic/if.rst +++ b/docs/_sources/api/manipulation/basic/if.rst @@ -10,7 +10,7 @@ Conditional "if" statement for operators Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin IF-test-1 :end-before: example-end IF-test-1 diff --git a/docs/_sources/api/manipulation/basic/ifelse.rst b/docs/_sources/api/manipulation/basic/ifelse.rst index 8bc01f70..5cc608f6 100644 --- a/docs/_sources/api/manipulation/basic/ifelse.rst +++ b/docs/_sources/api/manipulation/basic/ifelse.rst @@ -10,7 +10,7 @@ Conditional "if/else" statement for operators Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin IFELSE-test-1 :end-before: example-end IFELSE-test-1 diff --git a/docs/_sources/api/manipulation/basic/permute.rst b/docs/_sources/api/manipulation/basic/permute.rst index c2cf8938..a617e6b0 100644 --- a/docs/_sources/api/manipulation/basic/permute.rst +++ b/docs/_sources/api/manipulation/basic/permute.rst @@ -12,7 +12,7 @@ Permute the dimensions of an operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/permute_test.cu :language: cpp :start-after: example-begin permute-test-1 :end-before: example-end permute-test-1 diff --git a/docs/_sources/api/manipulation/basic/slice.rst b/docs/_sources/api/manipulation/basic/slice.rst index 657db1c4..4c0da386 100644 --- a/docs/_sources/api/manipulation/basic/slice.rst +++ b/docs/_sources/api/manipulation/basic/slice.rst @@ -12,21 +12,25 @@ be used to drop ranks, for operations such as selecting a single row. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_test.cu :language: cpp :start-after: example-begin slice-test-1 :end-before: example-end slice-test-1 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_test.cu :language: cpp :start-after: example-begin slice-test-2 :end-before: example-end slice-test-2 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_test.cu :language: cpp - :start-after: example-begin slice-test-2 - :end-before: example-end slice-test-2 + :start-after: example-begin slice-test-3 + :end-before: example-end slice-test-3 :dedent: +.. literalinclude:: ../../../../test/00_operators/slice_test.cu + :language: cpp + :start-after: example-begin slice-test-4 + :end-before: example-end slice-test-4 \ No newline at end of file diff --git a/docs/_sources/api/manipulation/joinrepeat/clone.rst b/docs/_sources/api/manipulation/joinrepeat/clone.rst index 49711cc0..627f04b4 100644 --- a/docs/_sources/api/manipulation/joinrepeat/clone.rst +++ b/docs/_sources/api/manipulation/joinrepeat/clone.rst @@ -11,7 +11,7 @@ Clone one or more dimensions of an operator to a higher rank Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/clone_test.cu :language: cpp :start-after: example-begin clone-test-1 :end-before: example-end clone-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/concat.rst b/docs/_sources/api/manipulation/joinrepeat/concat.rst index 4eccd0dc..d5a94fe3 100644 --- a/docs/_sources/api/manipulation/joinrepeat/concat.rst +++ b/docs/_sources/api/manipulation/joinrepeat/concat.rst @@ -11,7 +11,7 @@ concatenated operators, depending on where it's indexed Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/concat_test.cu :language: cpp :start-after: example-begin concat-test-1 :end-before: example-end concat-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/flatten.rst b/docs/_sources/api/manipulation/joinrepeat/flatten.rst index f7cdccf3..7d3dcfb6 100644 --- a/docs/_sources/api/manipulation/joinrepeat/flatten.rst +++ b/docs/_sources/api/manipulation/joinrepeat/flatten.rst @@ -11,7 +11,7 @@ of the original operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/flatten_test.cu :language: cpp :start-after: example-begin flatten-test-1 :end-before: example-end flatten-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/lcollapse.rst b/docs/_sources/api/manipulation/joinrepeat/lcollapse.rst index 7fe8dc36..b23f73d2 100644 --- a/docs/_sources/api/manipulation/joinrepeat/lcollapse.rst +++ b/docs/_sources/api/manipulation/joinrepeat/lcollapse.rst @@ -10,7 +10,7 @@ Collapse the left-most dimensions Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/collapse_test.cu :language: cpp :start-after: example-begin lcollapse-test-1 :end-before: example-end lcollapse-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/rcollapse.rst b/docs/_sources/api/manipulation/joinrepeat/rcollapse.rst index 443edb7d..89354787 100644 --- a/docs/_sources/api/manipulation/joinrepeat/rcollapse.rst +++ b/docs/_sources/api/manipulation/joinrepeat/rcollapse.rst @@ -10,7 +10,7 @@ Collapse the right-most dimensions Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/collapse_test.cu :language: cpp :start-after: example-begin rcollapse-test-1 :end-before: example-end rcollapse-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/repmat.rst b/docs/_sources/api/manipulation/joinrepeat/repmat.rst index 804d5d50..1b0c7c7f 100644 --- a/docs/_sources/api/manipulation/joinrepeat/repmat.rst +++ b/docs/_sources/api/manipulation/joinrepeat/repmat.rst @@ -12,7 +12,7 @@ Repeat an operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/repmat_test.cu :language: cpp :start-after: example-begin repmat-test-1 :end-before: example-end repmat-test-1 diff --git a/docs/_sources/api/manipulation/joinrepeat/stack.rst b/docs/_sources/api/manipulation/joinrepeat/stack.rst index 5a6c00ec..90d5b547 100644 --- a/docs/_sources/api/manipulation/joinrepeat/stack.rst +++ b/docs/_sources/api/manipulation/joinrepeat/stack.rst @@ -11,7 +11,7 @@ a rank increase of one where the new dimension reflects the stacked operators. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/stack_test.cu :language: cpp :start-after: example-begin stack-test-1 :end-before: example-end stack-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/fliplr.rst b/docs/_sources/api/manipulation/rearranging/fliplr.rst index a9f6ec92..bbb6d98b 100644 --- a/docs/_sources/api/manipulation/rearranging/fliplr.rst +++ b/docs/_sources/api/manipulation/rearranging/fliplr.rst @@ -10,7 +10,7 @@ Flips an operator left to right Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin fliplr-test-1 :end-before: example-end fliplr-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/flipud.rst b/docs/_sources/api/manipulation/rearranging/flipud.rst index 1e5768a9..ddcdabe2 100644 --- a/docs/_sources/api/manipulation/rearranging/flipud.rst +++ b/docs/_sources/api/manipulation/rearranging/flipud.rst @@ -10,7 +10,7 @@ Flips an operator up to down Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin flipud-test-1 :end-before: example-end flipud-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/overlap.rst b/docs/_sources/api/manipulation/rearranging/overlap.rst index 6d23038c..ba410554 100644 --- a/docs/_sources/api/manipulation/rearranging/overlap.rst +++ b/docs/_sources/api/manipulation/rearranging/overlap.rst @@ -27,7 +27,7 @@ end of the data to make the tensor rectangular. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/overlap_test.cu :language: cpp :start-after: example-begin overlap-test-1 :end-before: example-end overlap-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/permute.rst b/docs/_sources/api/manipulation/rearranging/permute.rst index 9157c2f9..54780cd2 100644 --- a/docs/_sources/api/manipulation/rearranging/permute.rst +++ b/docs/_sources/api/manipulation/rearranging/permute.rst @@ -11,7 +11,7 @@ Permute the dimensions of an operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/permute_test.cu :language: cpp :start-after: example-begin permute-test-1 :end-before: example-end permute-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/reshape.rst b/docs/_sources/api/manipulation/rearranging/reshape.rst index 11fb8ece..dedd2b82 100644 --- a/docs/_sources/api/manipulation/rearranging/reshape.rst +++ b/docs/_sources/api/manipulation/rearranging/reshape.rst @@ -12,7 +12,7 @@ the original size. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reshape_test.cu :language: cpp :start-after: example-begin reshape-test-1 :end-before: example-end reshape-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/reverse.rst b/docs/_sources/api/manipulation/rearranging/reverse.rst index 1e047622..b37a75f8 100644 --- a/docs/_sources/api/manipulation/rearranging/reverse.rst +++ b/docs/_sources/api/manipulation/rearranging/reverse.rst @@ -11,7 +11,7 @@ Reverse the values of an operator along a single dimension Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin reverse-test-1 :end-before: example-end reverse-test-1 diff --git a/docs/_sources/api/manipulation/rearranging/shift.rst b/docs/_sources/api/manipulation/rearranging/shift.rst index 66f73842..e9228424 100644 --- a/docs/_sources/api/manipulation/rearranging/shift.rst +++ b/docs/_sources/api/manipulation/rearranging/shift.rst @@ -11,7 +11,7 @@ Shift an operator by a given amount either positive or negative along one dimens Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin shift-test-1 :end-before: example-end shift-test-1 diff --git a/docs/_sources/api/manipulation/selecting/at.rst b/docs/_sources/api/manipulation/selecting/at.rst index a69c7652..7e597e80 100644 --- a/docs/_sources/api/manipulation/selecting/at.rst +++ b/docs/_sources/api/manipulation/selecting/at.rst @@ -23,7 +23,7 @@ the operation is launched: Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/at_test.cu :language: cpp :start-after: example-begin at-test-1 :end-before: example-end at-test-1 diff --git a/docs/_sources/api/manipulation/selecting/remap.rst b/docs/_sources/api/manipulation/selecting/remap.rst index f373d363..6de6a6cd 100644 --- a/docs/_sources/api/manipulation/selecting/remap.rst +++ b/docs/_sources/api/manipulation/selecting/remap.rst @@ -11,13 +11,13 @@ Remaps an input operator by selecting items from an input index operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/remap_test.cu :language: cpp :start-after: example-begin remap-test-1 :end-before: example-end remap-test-1 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/remap_test.cu :language: cpp :start-after: example-begin remap-test-2 :end-before: example-end remap-test-2 diff --git a/docs/_sources/api/math/arithmetic/add.rst b/docs/_sources/api/math/arithmetic/add.rst index ae5d928c..0c5b5fd2 100644 --- a/docs/_sources/api/math/arithmetic/add.rst +++ b/docs/_sources/api/math/arithmetic/add.rst @@ -10,7 +10,7 @@ Binary addition operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin add-test-1 :end-before: example-end add-test-1 diff --git a/docs/_sources/api/math/arithmetic/div.rst b/docs/_sources/api/math/arithmetic/div.rst index db160075..2cf91ddc 100644 --- a/docs/_sources/api/math/arithmetic/div.rst +++ b/docs/_sources/api/math/arithmetic/div.rst @@ -10,7 +10,7 @@ Element-wise division operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin div-test-1 :end-before: example-end div-test-1 diff --git a/docs/_sources/api/math/arithmetic/fmod.rst b/docs/_sources/api/math/arithmetic/fmod.rst index fc8a3d17..d12eb658 100644 --- a/docs/_sources/api/math/arithmetic/fmod.rst +++ b/docs/_sources/api/math/arithmetic/fmod.rst @@ -10,7 +10,7 @@ Division remainder Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/fmod_test.cu :language: cpp :start-after: example-begin fmod-test-1 :end-before: example-end fmod-test-1 diff --git a/docs/_sources/api/math/arithmetic/mod.rst b/docs/_sources/api/math/arithmetic/mod.rst index e16d4ca2..fa6d02b2 100644 --- a/docs/_sources/api/math/arithmetic/mod.rst +++ b/docs/_sources/api/math/arithmetic/mod.rst @@ -10,7 +10,7 @@ Modulo Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin mod-test-1 :end-before: example-end mod-test-1 diff --git a/docs/_sources/api/math/arithmetic/mul.rst b/docs/_sources/api/math/arithmetic/mul.rst index 7c693387..10f6b556 100644 --- a/docs/_sources/api/math/arithmetic/mul.rst +++ b/docs/_sources/api/math/arithmetic/mul.rst @@ -11,7 +11,7 @@ Element-wise multiplication operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin mul-test-1 :end-before: example-end mul-test-1 diff --git a/docs/_sources/api/math/arithmetic/neg.rst b/docs/_sources/api/math/arithmetic/neg.rst index f0948859..788286e4 100644 --- a/docs/_sources/api/math/arithmetic/neg.rst +++ b/docs/_sources/api/math/arithmetic/neg.rst @@ -10,7 +10,7 @@ Unary negation operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin neg-test-1 :end-before: example-end neg-test-1 diff --git a/docs/_sources/api/math/arithmetic/pow.rst b/docs/_sources/api/math/arithmetic/pow.rst index fbb5239c..8a9bacf2 100644 --- a/docs/_sources/api/math/arithmetic/pow.rst +++ b/docs/_sources/api/math/arithmetic/pow.rst @@ -10,7 +10,7 @@ Raise input to a power Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin pow-test-1 :end-before: example-end pow-test-1 diff --git a/docs/_sources/api/math/arithmetic/sub.rst b/docs/_sources/api/math/arithmetic/sub.rst index fa950ba2..b6e6e9e1 100644 --- a/docs/_sources/api/math/arithmetic/sub.rst +++ b/docs/_sources/api/math/arithmetic/sub.rst @@ -10,7 +10,7 @@ Binary subtraction operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin sub-test-1 :end-before: example-end sub-test-1 diff --git a/docs/_sources/api/math/complex/angle.rst b/docs/_sources/api/math/complex/angle.rst index 7cfec8ad..6894b7b1 100644 --- a/docs/_sources/api/math/complex/angle.rst +++ b/docs/_sources/api/math/complex/angle.rst @@ -10,7 +10,7 @@ Phase angle of a complex number Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/angle_test.cu :language: cpp :start-after: example-begin angle-test-1 :end-before: example-end angle-test-1 diff --git a/docs/_sources/api/math/complex/hermitiant.rst b/docs/_sources/api/math/complex/hermitiant.rst index 3470dbd8..df3077e4 100644 --- a/docs/_sources/api/math/complex/hermitiant.rst +++ b/docs/_sources/api/math/complex/hermitiant.rst @@ -10,7 +10,7 @@ Hermitian transpose (complex conjugate transpose) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/transpose_test.cu :language: cpp :start-after: example-begin hermitianT-test-1 :end-before: example-end hermitianT-test-1 diff --git a/docs/_sources/api/math/complex/norm.rst b/docs/_sources/api/math/complex/norm.rst index e34ebfb6..33d87d15 100644 --- a/docs/_sources/api/math/complex/norm.rst +++ b/docs/_sources/api/math/complex/norm.rst @@ -10,7 +10,7 @@ Square of the magnitude of a complex number Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_transform/Norm.cu :language: cpp :start-after: example-begin norm-test-1 :end-before: example-end norm-test-1 diff --git a/docs/_sources/api/math/complex/real.rst b/docs/_sources/api/math/complex/real.rst index 74ab37d4..ced723b6 100644 --- a/docs/_sources/api/math/complex/real.rst +++ b/docs/_sources/api/math/complex/real.rst @@ -10,7 +10,7 @@ Real part of a complex number Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/real_imag_test.cu :language: cpp :start-after: example-begin real-test-1 :end-before: example-end real-test-1 diff --git a/docs/_sources/api/math/explog/exp.rst b/docs/_sources/api/math/explog/exp.rst index a0969cc1..19ddb061 100644 --- a/docs/_sources/api/math/explog/exp.rst +++ b/docs/_sources/api/math/explog/exp.rst @@ -10,7 +10,7 @@ Exponential function Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin exp-test-1 :end-before: example-end exp-test-1 diff --git a/docs/_sources/api/math/explog/expj.rst b/docs/_sources/api/math/explog/expj.rst index 47e1f7f8..74356e48 100644 --- a/docs/_sources/api/math/explog/expj.rst +++ b/docs/_sources/api/math/explog/expj.rst @@ -10,7 +10,7 @@ Computes exp(j*x) for each element x Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin expj-test-1 :end-before: example-end expj-test-1 diff --git a/docs/_sources/api/math/explog/log.rst b/docs/_sources/api/math/explog/log.rst index 5dc15e13..83342c2a 100644 --- a/docs/_sources/api/math/explog/log.rst +++ b/docs/_sources/api/math/explog/log.rst @@ -11,7 +11,7 @@ Base e logarithm Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log-test-1 :end-before: example-end log-test-1 diff --git a/docs/_sources/api/math/explog/log10.rst b/docs/_sources/api/math/explog/log10.rst index c9777b9e..2afaa2be 100644 --- a/docs/_sources/api/math/explog/log10.rst +++ b/docs/_sources/api/math/explog/log10.rst @@ -10,7 +10,7 @@ Base 10 logarithm Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log10-test-1 :end-before: example-end log10-test-1 diff --git a/docs/_sources/api/math/explog/log2.rst b/docs/_sources/api/math/explog/log2.rst index 79d6d835..02c95db2 100644 --- a/docs/_sources/api/math/explog/log2.rst +++ b/docs/_sources/api/math/explog/log2.rst @@ -10,7 +10,7 @@ Base 2 logarithm Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log2-test-1 :end-before: example-end log2-test-1 diff --git a/docs/_sources/api/math/extrema/max.rst b/docs/_sources/api/math/extrema/max.rst index 5b01f58c..3fb06249 100644 --- a/docs/_sources/api/math/extrema/max.rst +++ b/docs/_sources/api/math/extrema/max.rst @@ -10,7 +10,7 @@ Element-wise maximum Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin max-test-1 :end-before: example-end max-test-1 diff --git a/docs/_sources/api/math/extrema/min.rst b/docs/_sources/api/math/extrema/min.rst index ead6cab0..528fd22d 100644 --- a/docs/_sources/api/math/extrema/min.rst +++ b/docs/_sources/api/math/extrema/min.rst @@ -10,7 +10,7 @@ Element-wise minimum Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin min-test-1 :end-before: example-end min-test-1 diff --git a/docs/_sources/api/math/misc/abs.rst b/docs/_sources/api/math/misc/abs.rst index 52939852..831a5af0 100644 --- a/docs/_sources/api/math/misc/abs.rst +++ b/docs/_sources/api/math/misc/abs.rst @@ -10,7 +10,7 @@ Absolute value for real numbers, or complex magnitude for complex numbers Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin abs-test-1 :end-before: example-end abs-test-1 diff --git a/docs/_sources/api/math/misc/sqrt.rst b/docs/_sources/api/math/misc/sqrt.rst index 9e842382..076bff8e 100644 --- a/docs/_sources/api/math/misc/sqrt.rst +++ b/docs/_sources/api/math/misc/sqrt.rst @@ -10,7 +10,7 @@ Square root Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin sqrt-test-1 :end-before: example-end sqrt-test-1 diff --git a/docs/_sources/api/math/round/ceil.rst b/docs/_sources/api/math/round/ceil.rst index 34ddc1a3..ff701f79 100644 --- a/docs/_sources/api/math/round/ceil.rst +++ b/docs/_sources/api/math/round/ceil.rst @@ -10,7 +10,7 @@ Computes the smallest integer not less than the input Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin ceil-test-1 :end-before: example-end ceil-test-1 diff --git a/docs/_sources/api/math/round/floor.rst b/docs/_sources/api/math/round/floor.rst index 6d31fd06..a81a045d 100644 --- a/docs/_sources/api/math/round/floor.rst +++ b/docs/_sources/api/math/round/floor.rst @@ -10,7 +10,7 @@ Computes the largest integer not greater than the input Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin floor-test-1 :end-before: example-end floor-test-1 diff --git a/docs/_sources/api/math/round/round.rst b/docs/_sources/api/math/round/round.rst index 997a7336..4614e5ea 100644 --- a/docs/_sources/api/math/round/round.rst +++ b/docs/_sources/api/math/round/round.rst @@ -10,7 +10,7 @@ Computes the nearest integer value Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin round-test-1 :end-before: example-end round-test-1 diff --git a/docs/_sources/api/math/trig/acos.rst b/docs/_sources/api/math/trig/acos.rst index 8a65093d..960502c1 100644 --- a/docs/_sources/api/math/trig/acos.rst +++ b/docs/_sources/api/math/trig/acos.rst @@ -10,7 +10,7 @@ Inverse cosine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin acos-test-1 :end-before: example-end acos-test-1 diff --git a/docs/_sources/api/math/trig/acosh.rst b/docs/_sources/api/math/trig/acosh.rst index 29afd09d..f65fce0a 100644 --- a/docs/_sources/api/math/trig/acosh.rst +++ b/docs/_sources/api/math/trig/acosh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse cosine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin acosh-test-1 :end-before: example-end acosh-test-1 diff --git a/docs/_sources/api/math/trig/asin.rst b/docs/_sources/api/math/trig/asin.rst index f65858b0..6df762c7 100644 --- a/docs/_sources/api/math/trig/asin.rst +++ b/docs/_sources/api/math/trig/asin.rst @@ -10,7 +10,7 @@ Inverse sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin asin-test-1 :end-before: example-end asin-test-1 diff --git a/docs/_sources/api/math/trig/asinh.rst b/docs/_sources/api/math/trig/asinh.rst index 23e2581b..d0745a20 100644 --- a/docs/_sources/api/math/trig/asinh.rst +++ b/docs/_sources/api/math/trig/asinh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin asinh-test-1 :end-before: example-end asinh-test-1 diff --git a/docs/_sources/api/math/trig/atan.rst b/docs/_sources/api/math/trig/atan.rst index eb6458a1..d0639e55 100644 --- a/docs/_sources/api/math/trig/atan.rst +++ b/docs/_sources/api/math/trig/atan.rst @@ -10,7 +10,7 @@ Inverse tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin atan-test-1 :end-before: example-end atan-test-1 diff --git a/docs/_sources/api/math/trig/atanh.rst b/docs/_sources/api/math/trig/atanh.rst index 1ee40bce..a258ab0c 100644 --- a/docs/_sources/api/math/trig/atanh.rst +++ b/docs/_sources/api/math/trig/atanh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin atanh-test-1 :end-before: example-end atanh-test-1 diff --git a/docs/_sources/api/math/trig/cart2sph.rst b/docs/_sources/api/math/trig/cart2sph.rst index 87d2aaba..f8356ae9 100644 --- a/docs/_sources/api/math/trig/cart2sph.rst +++ b/docs/_sources/api/math/trig/cart2sph.rst @@ -10,7 +10,7 @@ Cartesian coordinates to spherical Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/sph2cart_test.cu :language: cpp :start-after: example-begin cart2sph-test-1 :end-before: example-end cart2sph-test-1 diff --git a/docs/_sources/api/math/trig/cos.rst b/docs/_sources/api/math/trig/cos.rst index 4c199ee9..6af291e3 100644 --- a/docs/_sources/api/math/trig/cos.rst +++ b/docs/_sources/api/math/trig/cos.rst @@ -10,7 +10,7 @@ Cosine in radians Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin cos-test-1 :end-before: example-end cos-test-1 diff --git a/docs/_sources/api/math/trig/cosh.rst b/docs/_sources/api/math/trig/cosh.rst index c43efcef..efbd221b 100644 --- a/docs/_sources/api/math/trig/cosh.rst +++ b/docs/_sources/api/math/trig/cosh.rst @@ -10,7 +10,7 @@ Hyperbolic coshine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin cosh-test-1 :end-before: example-end cosh-test-1 diff --git a/docs/_sources/api/math/trig/sin.rst b/docs/_sources/api/math/trig/sin.rst index fbcf3600..e6156c8c 100644 --- a/docs/_sources/api/math/trig/sin.rst +++ b/docs/_sources/api/math/trig/sin.rst @@ -10,7 +10,7 @@ Sine in radians Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin sin-test-1 :end-before: example-end sin-test-1 diff --git a/docs/_sources/api/math/trig/sinh.rst b/docs/_sources/api/math/trig/sinh.rst index d5e06c19..1e30df75 100644 --- a/docs/_sources/api/math/trig/sinh.rst +++ b/docs/_sources/api/math/trig/sinh.rst @@ -10,7 +10,7 @@ Hyperbolic sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin sinh-test-1 :end-before: example-end sinh-test-1 diff --git a/docs/_sources/api/math/trig/sph2cart.rst b/docs/_sources/api/math/trig/sph2cart.rst index 37a5814d..a415d558 100644 --- a/docs/_sources/api/math/trig/sph2cart.rst +++ b/docs/_sources/api/math/trig/sph2cart.rst @@ -10,7 +10,7 @@ Spherical to Cartesian coordinates Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/sph2cart_test.cu :language: cpp :start-after: example-begin sph2cart-test-1 :end-before: example-end sph2cart-test-1 diff --git a/docs/_sources/api/math/trig/tan.rst b/docs/_sources/api/math/trig/tan.rst index 14b68713..c479cc0d 100644 --- a/docs/_sources/api/math/trig/tan.rst +++ b/docs/_sources/api/math/trig/tan.rst @@ -10,7 +10,7 @@ Tangent in radians Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin tan-test-1 :end-before: example-end tan-test-1 diff --git a/docs/_sources/api/math/trig/tanh.rst b/docs/_sources/api/math/trig/tanh.rst index ad9a8a80..6dd21e5d 100644 --- a/docs/_sources/api/math/trig/tanh.rst +++ b/docs/_sources/api/math/trig/tanh.rst @@ -10,7 +10,7 @@ Hyperbolic tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_func_test.cu :language: cpp :start-after: example-begin tanh-test-1 :end-before: example-end tanh-test-1 diff --git a/docs/_sources/api/polynomials/legendre.rst b/docs/_sources/api/polynomials/legendre.rst index 903d43f8..8c97cc9d 100644 --- a/docs/_sources/api/polynomials/legendre.rst +++ b/docs/_sources/api/polynomials/legendre.rst @@ -12,7 +12,7 @@ Return Legendre polynomial coefficients at the input operator Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/legendre_test.cu :language: cpp :start-after: example-begin legendre-test-1 :end-before: example-end legendre-test-1 diff --git a/docs/_sources/api/signalimage/general/downsample.rst b/docs/_sources/api/signalimage/general/downsample.rst index 7304bdfd..420d93af 100644 --- a/docs/_sources/api/signalimage/general/downsample.rst +++ b/docs/_sources/api/signalimage/general/downsample.rst @@ -10,7 +10,7 @@ downsample a signal by dropping samples Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/updownsample_test.cu :language: cpp :start-after: example-begin downsample-test-1 :end-before: example-end downsample-test-1 diff --git a/docs/_sources/api/signalimage/general/upsample.rst b/docs/_sources/api/signalimage/general/upsample.rst index ab9c7092..b5b2af61 100644 --- a/docs/_sources/api/signalimage/general/upsample.rst +++ b/docs/_sources/api/signalimage/general/upsample.rst @@ -10,7 +10,7 @@ Upsample a signal by stuffing zeros Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/updownsample_test.cu :language: cpp :start-after: example-begin upsample-test-1 :end-before: example-end upsample-test-1 diff --git a/docs_input/api/casting/as_complex_double.rst b/docs_input/api/casting/as_complex_double.rst index 8762d135..4a0e63e3 100644 --- a/docs_input/api/casting/as_complex_double.rst +++ b/docs_input/api/casting/as_complex_double.rst @@ -11,13 +11,13 @@ Cast an operator to cuda::std::complex Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_complex_double-test-1 :end-before: example-end as_complex_double-test-1 :dedent: -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/complex_cast_test.cu :language: cpp :start-after: example-begin as_complex_double-test-2 :end-before: example-end as_complex_double-test-2 diff --git a/docs_input/api/casting/as_complex_float.rst b/docs_input/api/casting/as_complex_float.rst index 9a8378b9..8b997d1d 100644 --- a/docs_input/api/casting/as_complex_float.rst +++ b/docs_input/api/casting/as_complex_float.rst @@ -11,13 +11,13 @@ Cast an operator to cuda::std::complex Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_complex_float-test-1 :end-before: example-end as_complex_float-test-1 :dedent: -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/complex_cast_test.cu :language: cpp :start-after: example-begin as_complex_float-test-2 :end-before: example-end as_complex_float-test-2 diff --git a/docs_input/api/casting/as_int8.rst b/docs_input/api/casting/as_int8.rst index b3c6ee29..1072ce96 100644 --- a/docs_input/api/casting/as_int8.rst +++ b/docs_input/api/casting/as_int8.rst @@ -10,7 +10,7 @@ Cast an operator to an int8_t Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_int8-test-1 :end-before: example-end as_int8-test-1 diff --git a/docs_input/api/casting/as_type.rst b/docs_input/api/casting/as_type.rst index 4f358545..05b19add 100644 --- a/docs_input/api/casting/as_type.rst +++ b/docs_input/api/casting/as_type.rst @@ -10,7 +10,7 @@ Cast an operator to an arbitrary type Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/cast_test.cu :language: cpp :start-after: example-begin as_type-test-1 :end-before: example-end as_type-test-1 diff --git a/docs_input/api/dft/utility/fftshift2d.rst b/docs_input/api/dft/utility/fftshift2d.rst index 449b24e8..ffdc4142 100644 --- a/docs_input/api/dft/utility/fftshift2d.rst +++ b/docs_input/api/dft/utility/fftshift2d.rst @@ -3,13 +3,13 @@ fftshift2D ########## -Perform a 2D shift by shifting the zero-frequency component to the center of the tensor +Perform a 2D FFT shift by moving zero-frequency components to the center .. doxygenfunction:: fftshift2D Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin fftshift2D-test-1 :end-before: example-end fftshift2D-test-1 diff --git a/docs_input/api/dft/utility/ifftshift2d.rst b/docs_input/api/dft/utility/ifftshift2d.rst index 702b7129..427159d3 100644 --- a/docs_input/api/dft/utility/ifftshift2d.rst +++ b/docs_input/api/dft/utility/ifftshift2d.rst @@ -9,7 +9,7 @@ Perform a 2D inverse by shifting a zero-frequency-shifted version back to the or Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin ifftshift2D-test-1 :end-before: example-end ifftshift2D-test-1 diff --git a/docs_input/api/linalg/other/cross.rst b/docs_input/api/linalg/other/cross.rst index 141259e1..8381011e 100644 --- a/docs_input/api/linalg/other/cross.rst +++ b/docs_input/api/linalg/other/cross.rst @@ -13,7 +13,7 @@ on all dimensions besides the last dimension. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/cross_test.cu :language: cpp :start-after: example-begin cross-test-1 :end-before: example-end cross-test-1 diff --git a/docs_input/api/linalg/other/toeplitz.rst b/docs_input/api/linalg/other/toeplitz.rst index cf87f2a6..1a7e99d7 100644 --- a/docs_input/api/linalg/other/toeplitz.rst +++ b/docs_input/api/linalg/other/toeplitz.rst @@ -19,13 +19,13 @@ input as the second parameter. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/toeplitz_test.cu :language: cpp :start-after: example-begin toeplitz-test-1 :end-before: example-end toeplitz-test-1 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/toeplitz_test.cu :language: cpp :start-after: example-begin toeplitz-test-2 :end-before: example-end toeplitz-test-2 diff --git a/docs_input/api/logic/bitwise/and.rst b/docs_input/api/logic/bitwise/and.rst index fa9e0fb4..3a53a852 100644 --- a/docs_input/api/logic/bitwise/and.rst +++ b/docs_input/api/logic/bitwise/and.rst @@ -10,7 +10,7 @@ Bitwise AND Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin and-test-1 :end-before: example-end and-test-1 diff --git a/docs_input/api/logic/bitwise/or.rst b/docs_input/api/logic/bitwise/or.rst index 8d19f0ed..f0e502fa 100644 --- a/docs_input/api/logic/bitwise/or.rst +++ b/docs_input/api/logic/bitwise/or.rst @@ -10,7 +10,7 @@ Bitwise OR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin or-test-1 :end-before: example-end or-test-1 diff --git a/docs_input/api/logic/bitwise/xor.rst b/docs_input/api/logic/bitwise/xor.rst index ff2ba51b..c30cb010 100644 --- a/docs_input/api/logic/bitwise/xor.rst +++ b/docs_input/api/logic/bitwise/xor.rst @@ -10,7 +10,7 @@ Bitwise XOR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin xor-test-1 :end-before: example-end xor-test-1 diff --git a/docs_input/api/logic/comparison/equal.rst b/docs_input/api/logic/comparison/equal.rst index be6b50d8..9d443bf1 100644 --- a/docs_input/api/logic/comparison/equal.rst +++ b/docs_input/api/logic/comparison/equal.rst @@ -10,7 +10,7 @@ Equality test Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin eq-test-1 :end-before: example-end eq-test-1 diff --git a/docs_input/api/logic/comparison/gt.rst b/docs_input/api/logic/comparison/gt.rst index 8f42f858..c6b7ad63 100644 --- a/docs_input/api/logic/comparison/gt.rst +++ b/docs_input/api/logic/comparison/gt.rst @@ -10,7 +10,7 @@ Greater than Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin gt-test-1 :end-before: example-end gt-test-1 diff --git a/docs_input/api/logic/comparison/gte.rst b/docs_input/api/logic/comparison/gte.rst index c5c113d0..070ad19c 100644 --- a/docs_input/api/logic/comparison/gte.rst +++ b/docs_input/api/logic/comparison/gte.rst @@ -10,7 +10,7 @@ Greater than or equal to Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin gte-test-1 :end-before: example-end gte-test-1 diff --git a/docs_input/api/logic/comparison/isclose.rst b/docs_input/api/logic/comparison/isclose.rst index 58d2d750..980ff07f 100644 --- a/docs_input/api/logic/comparison/isclose.rst +++ b/docs_input/api/logic/comparison/isclose.rst @@ -13,7 +13,7 @@ atomics are not available in hardware. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/isclose_test.cu :language: cpp :start-after: example-begin isclose-test-1 :end-before: example-end isclose-test-1 diff --git a/docs_input/api/logic/comparison/lt.rst b/docs_input/api/logic/comparison/lt.rst index 2322c15a..b05b8dcf 100644 --- a/docs_input/api/logic/comparison/lt.rst +++ b/docs_input/api/logic/comparison/lt.rst @@ -10,7 +10,7 @@ Less than Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lt-test-1 :end-before: example-end lt-test-1 diff --git a/docs_input/api/logic/comparison/lte.rst b/docs_input/api/logic/comparison/lte.rst index 1da681d9..75a03592 100644 --- a/docs_input/api/logic/comparison/lte.rst +++ b/docs_input/api/logic/comparison/lte.rst @@ -10,7 +10,7 @@ Less than or equal to Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lte-test-1 :end-before: example-end lte-test-1 diff --git a/docs_input/api/logic/comparison/neq.rst b/docs_input/api/logic/comparison/neq.rst index 25a5277d..992b2d4a 100644 --- a/docs_input/api/logic/comparison/neq.rst +++ b/docs_input/api/logic/comparison/neq.rst @@ -10,7 +10,7 @@ Non-equality test Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin neq-test-1 :end-before: example-end neq-test-1 diff --git a/docs_input/api/logic/logical/and.rst b/docs_input/api/logic/logical/and.rst index 8050761d..6e68f341 100644 --- a/docs_input/api/logic/logical/and.rst +++ b/docs_input/api/logic/logical/and.rst @@ -10,7 +10,7 @@ Logical AND Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin land-test-1 :end-before: example-end land-test-1 diff --git a/docs_input/api/logic/logical/not.rst b/docs_input/api/logic/logical/not.rst index 9725d85d..a316c060 100644 --- a/docs_input/api/logic/logical/not.rst +++ b/docs_input/api/logic/logical/not.rst @@ -10,7 +10,7 @@ Logical NOT Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lnot-test-1 :end-before: example-end lnot-test-1 diff --git a/docs_input/api/logic/logical/or.rst b/docs_input/api/logic/logical/or.rst index c558a0dd..95837947 100644 --- a/docs_input/api/logic/logical/or.rst +++ b/docs_input/api/logic/logical/or.rst @@ -10,7 +10,7 @@ Logical OR Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin lor-test-1 :end-before: example-end lor-test-1 diff --git a/docs_input/api/logic/truth/isinf.rst b/docs_input/api/logic/truth/isinf.rst index ccf59260..c2301d0b 100644 --- a/docs_input/api/logic/truth/isinf.rst +++ b/docs_input/api/logic/truth/isinf.rst @@ -10,7 +10,7 @@ Returns a truth value if operator value is infinite Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/isnaninf_test.cu :language: cpp :start-after: example-begin inf-test-1 :end-before: example-end inf-test-1 diff --git a/docs_input/api/logic/truth/isnan.rst b/docs_input/api/logic/truth/isnan.rst index 68174580..94d0b237 100644 --- a/docs_input/api/logic/truth/isnan.rst +++ b/docs_input/api/logic/truth/isnan.rst @@ -10,7 +10,7 @@ Returns a truth value if operator value is NaN Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/isnaninf_test.cu :language: cpp :start-after: example-begin nan-test-1 :end-before: example-end nan-test-1 diff --git a/docs_input/api/manipulation/basic/if.rst b/docs_input/api/manipulation/basic/if.rst index 81920c4f..101c004f 100644 --- a/docs_input/api/manipulation/basic/if.rst +++ b/docs_input/api/manipulation/basic/if.rst @@ -10,7 +10,7 @@ Conditional "if" statement for operators Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin IF-test-1 :end-before: example-end IF-test-1 diff --git a/docs_input/api/manipulation/basic/ifelse.rst b/docs_input/api/manipulation/basic/ifelse.rst index 8bc01f70..5cc608f6 100644 --- a/docs_input/api/manipulation/basic/ifelse.rst +++ b/docs_input/api/manipulation/basic/ifelse.rst @@ -10,7 +10,7 @@ Conditional "if/else" statement for operators Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin IFELSE-test-1 :end-before: example-end IFELSE-test-1 diff --git a/docs_input/api/manipulation/basic/slice.rst b/docs_input/api/manipulation/basic/slice.rst index 78a0b54a..15e5709d 100644 --- a/docs_input/api/manipulation/basic/slice.rst +++ b/docs_input/api/manipulation/basic/slice.rst @@ -15,25 +15,25 @@ When slicing along any given tensor dimension, the start index is treated as inc Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_test.cu :language: cpp :start-after: example-begin slice-test-1 :end-before: example-end slice-test-1 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_stride_test.cu :language: cpp :start-after: example-begin slice-test-2 :end-before: example-end slice-test-2 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_and_reduce_test.cu :language: cpp :start-after: example-begin slice-test-3 :end-before: example-end slice-test-3 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/slice_test.cu :language: cpp :start-after: example-begin slice-test-4 :end-before: example-end slice-test-4 diff --git a/docs_input/api/manipulation/joinrepeat/clone.rst b/docs_input/api/manipulation/joinrepeat/clone.rst index 822c7cda..9720d793 100644 --- a/docs_input/api/manipulation/joinrepeat/clone.rst +++ b/docs_input/api/manipulation/joinrepeat/clone.rst @@ -11,7 +11,7 @@ Clone one or more dimensions of an operator to a higher rank Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/clone_test.cu :language: cpp :start-after: example-begin clone-test-1 :end-before: example-end clone-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/concat.rst b/docs_input/api/manipulation/joinrepeat/concat.rst index 4eccd0dc..d5a94fe3 100644 --- a/docs_input/api/manipulation/joinrepeat/concat.rst +++ b/docs_input/api/manipulation/joinrepeat/concat.rst @@ -11,7 +11,7 @@ concatenated operators, depending on where it's indexed Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/concat_test.cu :language: cpp :start-after: example-begin concat-test-1 :end-before: example-end concat-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/flatten.rst b/docs_input/api/manipulation/joinrepeat/flatten.rst index f7cdccf3..7d3dcfb6 100644 --- a/docs_input/api/manipulation/joinrepeat/flatten.rst +++ b/docs_input/api/manipulation/joinrepeat/flatten.rst @@ -11,7 +11,7 @@ of the original operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/flatten_test.cu :language: cpp :start-after: example-begin flatten-test-1 :end-before: example-end flatten-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/lcollapse.rst b/docs_input/api/manipulation/joinrepeat/lcollapse.rst index 7fe8dc36..b23f73d2 100644 --- a/docs_input/api/manipulation/joinrepeat/lcollapse.rst +++ b/docs_input/api/manipulation/joinrepeat/lcollapse.rst @@ -10,7 +10,7 @@ Collapse the left-most dimensions Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/collapse_test.cu :language: cpp :start-after: example-begin lcollapse-test-1 :end-before: example-end lcollapse-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/rcollapse.rst b/docs_input/api/manipulation/joinrepeat/rcollapse.rst index 443edb7d..89354787 100644 --- a/docs_input/api/manipulation/joinrepeat/rcollapse.rst +++ b/docs_input/api/manipulation/joinrepeat/rcollapse.rst @@ -10,7 +10,7 @@ Collapse the right-most dimensions Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/collapse_test.cu :language: cpp :start-after: example-begin rcollapse-test-1 :end-before: example-end rcollapse-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/repmat.rst b/docs_input/api/manipulation/joinrepeat/repmat.rst index 5d889d7a..faa87496 100644 --- a/docs_input/api/manipulation/joinrepeat/repmat.rst +++ b/docs_input/api/manipulation/joinrepeat/repmat.rst @@ -12,7 +12,7 @@ Repeat an operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/repmat_test.cu :language: cpp :start-after: example-begin repmat-test-1 :end-before: example-end repmat-test-1 diff --git a/docs_input/api/manipulation/joinrepeat/stack.rst b/docs_input/api/manipulation/joinrepeat/stack.rst index 5a6c00ec..90d5b547 100644 --- a/docs_input/api/manipulation/joinrepeat/stack.rst +++ b/docs_input/api/manipulation/joinrepeat/stack.rst @@ -11,7 +11,7 @@ a rank increase of one where the new dimension reflects the stacked operators. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/stack_test.cu :language: cpp :start-after: example-begin stack-test-1 :end-before: example-end stack-test-1 diff --git a/docs_input/api/manipulation/rearranging/fliplr.rst b/docs_input/api/manipulation/rearranging/fliplr.rst index a9f6ec92..bbb6d98b 100644 --- a/docs_input/api/manipulation/rearranging/fliplr.rst +++ b/docs_input/api/manipulation/rearranging/fliplr.rst @@ -10,7 +10,7 @@ Flips an operator left to right Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin fliplr-test-1 :end-before: example-end fliplr-test-1 diff --git a/docs_input/api/manipulation/rearranging/flipud.rst b/docs_input/api/manipulation/rearranging/flipud.rst index 1e5768a9..ddcdabe2 100644 --- a/docs_input/api/manipulation/rearranging/flipud.rst +++ b/docs_input/api/manipulation/rearranging/flipud.rst @@ -10,7 +10,7 @@ Flips an operator up to down Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin flipud-test-1 :end-before: example-end flipud-test-1 diff --git a/docs_input/api/manipulation/rearranging/overlap.rst b/docs_input/api/manipulation/rearranging/overlap.rst index ead2b567..1f4155f5 100644 --- a/docs_input/api/manipulation/rearranging/overlap.rst +++ b/docs_input/api/manipulation/rearranging/overlap.rst @@ -27,7 +27,7 @@ end of the data to make the tensor rectangular. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/overlap_test.cu :language: cpp :start-after: example-begin overlap-test-1 :end-before: example-end overlap-test-1 diff --git a/docs_input/api/manipulation/rearranging/permute.rst b/docs_input/api/manipulation/rearranging/permute.rst index 8c78096a..fcea1fd0 100644 --- a/docs_input/api/manipulation/rearranging/permute.rst +++ b/docs_input/api/manipulation/rearranging/permute.rst @@ -11,7 +11,7 @@ Permute the dimensions of an operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/permute_test.cu :language: cpp :start-after: example-begin permute-test-1 :end-before: example-end permute-test-1 diff --git a/docs_input/api/manipulation/rearranging/reshape.rst b/docs_input/api/manipulation/rearranging/reshape.rst index e4fde1d1..daf4a43e 100644 --- a/docs_input/api/manipulation/rearranging/reshape.rst +++ b/docs_input/api/manipulation/rearranging/reshape.rst @@ -12,7 +12,7 @@ the original size. Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reshape_test.cu :language: cpp :start-after: example-begin reshape-test-1 :end-before: example-end reshape-test-1 diff --git a/docs_input/api/manipulation/rearranging/reverse.rst b/docs_input/api/manipulation/rearranging/reverse.rst index 82693588..9eccba02 100644 --- a/docs_input/api/manipulation/rearranging/reverse.rst +++ b/docs_input/api/manipulation/rearranging/reverse.rst @@ -11,7 +11,7 @@ Reverse the values of an operator along a single dimension Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/reverse_test.cu :language: cpp :start-after: example-begin reverse-test-1 :end-before: example-end reverse-test-1 diff --git a/docs_input/api/manipulation/rearranging/shift.rst b/docs_input/api/manipulation/rearranging/shift.rst index 83e25c41..10a69dd7 100644 --- a/docs_input/api/manipulation/rearranging/shift.rst +++ b/docs_input/api/manipulation/rearranging/shift.rst @@ -1,7 +1,7 @@ .. _shift_func: shift -======= +===== Shift an operator by a given amount either positive or negative along one dimension @@ -11,7 +11,7 @@ Shift an operator by a given amount either positive or negative along one dimens Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/shift_test.cu :language: cpp :start-after: example-begin shift-test-1 :end-before: example-end shift-test-1 diff --git a/docs_input/api/manipulation/rearranging/transpose.rst b/docs_input/api/manipulation/rearranging/transpose.rst index 2b911b4f..814acda1 100644 --- a/docs_input/api/manipulation/rearranging/transpose.rst +++ b/docs_input/api/manipulation/rearranging/transpose.rst @@ -12,7 +12,7 @@ than calling `permute()` since it's not lazily evaluated and can use an optimize Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/transpose_test.cu :language: cpp :start-after: example-begin transpose-test-1 :end-before: example-end transpose-test-1 diff --git a/docs_input/api/manipulation/selecting/at.rst b/docs_input/api/manipulation/selecting/at.rst index 30413b50..93dc1bc8 100644 --- a/docs_input/api/manipulation/selecting/at.rst +++ b/docs_input/api/manipulation/selecting/at.rst @@ -23,7 +23,7 @@ the operation is launched: Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/at_test.cu :language: cpp :start-after: example-begin at-test-1 :end-before: example-end at-test-1 diff --git a/docs_input/api/manipulation/selecting/remap.rst b/docs_input/api/manipulation/selecting/remap.rst index 684645a0..ba867cb5 100644 --- a/docs_input/api/manipulation/selecting/remap.rst +++ b/docs_input/api/manipulation/selecting/remap.rst @@ -11,13 +11,13 @@ Remaps an input operator by selecting items from an input index operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/remap_test.cu :language: cpp :start-after: example-begin remap-test-1 :end-before: example-end remap-test-1 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/remap_test.cu :language: cpp :start-after: example-begin remap-test-2 :end-before: example-end remap-test-2 diff --git a/docs_input/api/math/arithmetic/add.rst b/docs_input/api/math/arithmetic/add.rst index ae5d928c..0c5b5fd2 100644 --- a/docs_input/api/math/arithmetic/add.rst +++ b/docs_input/api/math/arithmetic/add.rst @@ -10,7 +10,7 @@ Binary addition operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin add-test-1 :end-before: example-end add-test-1 diff --git a/docs_input/api/math/arithmetic/div.rst b/docs_input/api/math/arithmetic/div.rst index db160075..2cf91ddc 100644 --- a/docs_input/api/math/arithmetic/div.rst +++ b/docs_input/api/math/arithmetic/div.rst @@ -10,7 +10,7 @@ Element-wise division operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin div-test-1 :end-before: example-end div-test-1 diff --git a/docs_input/api/math/arithmetic/fmod.rst b/docs_input/api/math/arithmetic/fmod.rst index fc8a3d17..11e3cf59 100644 --- a/docs_input/api/math/arithmetic/fmod.rst +++ b/docs_input/api/math/arithmetic/fmod.rst @@ -3,14 +3,14 @@ fmod ==== -Division remainder +Floating point modulo .. doxygenfunction:: fmod(Op t, Op t2) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/fmod_test.cu :language: cpp :start-after: example-begin fmod-test-1 :end-before: example-end fmod-test-1 diff --git a/docs_input/api/math/arithmetic/mod.rst b/docs_input/api/math/arithmetic/mod.rst index e16d4ca2..fa6d02b2 100644 --- a/docs_input/api/math/arithmetic/mod.rst +++ b/docs_input/api/math/arithmetic/mod.rst @@ -10,7 +10,7 @@ Modulo Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin mod-test-1 :end-before: example-end mod-test-1 diff --git a/docs_input/api/math/arithmetic/mul.rst b/docs_input/api/math/arithmetic/mul.rst index 7c693387..10f6b556 100644 --- a/docs_input/api/math/arithmetic/mul.rst +++ b/docs_input/api/math/arithmetic/mul.rst @@ -11,7 +11,7 @@ Element-wise multiplication operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin mul-test-1 :end-before: example-end mul-test-1 diff --git a/docs_input/api/math/arithmetic/neg.rst b/docs_input/api/math/arithmetic/neg.rst index f0948859..788286e4 100644 --- a/docs_input/api/math/arithmetic/neg.rst +++ b/docs_input/api/math/arithmetic/neg.rst @@ -10,7 +10,7 @@ Unary negation operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin neg-test-1 :end-before: example-end neg-test-1 diff --git a/docs_input/api/math/arithmetic/pow.rst b/docs_input/api/math/arithmetic/pow.rst index fbb5239c..8a9bacf2 100644 --- a/docs_input/api/math/arithmetic/pow.rst +++ b/docs_input/api/math/arithmetic/pow.rst @@ -10,7 +10,7 @@ Raise input to a power Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin pow-test-1 :end-before: example-end pow-test-1 diff --git a/docs_input/api/math/arithmetic/sub.rst b/docs_input/api/math/arithmetic/sub.rst index fa950ba2..b6e6e9e1 100644 --- a/docs_input/api/math/arithmetic/sub.rst +++ b/docs_input/api/math/arithmetic/sub.rst @@ -10,7 +10,7 @@ Binary subtraction operator Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin sub-test-1 :end-before: example-end sub-test-1 diff --git a/docs_input/api/math/complex/angle.rst b/docs_input/api/math/complex/angle.rst index 7cfec8ad..6894b7b1 100644 --- a/docs_input/api/math/complex/angle.rst +++ b/docs_input/api/math/complex/angle.rst @@ -10,7 +10,7 @@ Phase angle of a complex number Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/angle_test.cu :language: cpp :start-after: example-begin angle-test-1 :end-before: example-end angle-test-1 diff --git a/docs_input/api/math/complex/conj.rst b/docs_input/api/math/complex/conj.rst index b03c9809..d97294fe 100644 --- a/docs_input/api/math/complex/conj.rst +++ b/docs_input/api/math/complex/conj.rst @@ -12,7 +12,7 @@ If input is real the same value is returned Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin conj-test-1 :end-before: example-end conj-test-1 diff --git a/docs_input/api/math/complex/hermitiant.rst b/docs_input/api/math/complex/hermitiant.rst index 3470dbd8..df3077e4 100644 --- a/docs_input/api/math/complex/hermitiant.rst +++ b/docs_input/api/math/complex/hermitiant.rst @@ -10,7 +10,7 @@ Hermitian transpose (complex conjugate transpose) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/transpose_test.cu :language: cpp :start-after: example-begin hermitianT-test-1 :end-before: example-end hermitianT-test-1 diff --git a/docs_input/api/math/complex/imag.rst b/docs_input/api/math/complex/imag.rst index 4db12970..c743d1b0 100644 --- a/docs_input/api/math/complex/imag.rst +++ b/docs_input/api/math/complex/imag.rst @@ -3,14 +3,14 @@ imag ==== -Imaginary part of a complex number +Imaginary part of complex number .. doxygenfunction:: imag(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/real_imag_test.cu :language: cpp :start-after: example-begin imag-test-1 :end-before: example-end imag-test-1 diff --git a/docs_input/api/math/complex/real.rst b/docs_input/api/math/complex/real.rst index 74ab37d4..30deefd3 100644 --- a/docs_input/api/math/complex/real.rst +++ b/docs_input/api/math/complex/real.rst @@ -3,14 +3,14 @@ real ==== -Real part of a complex number +Real part of complex number .. doxygenfunction:: real(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/real_imag_test.cu :language: cpp :start-after: example-begin real-test-1 :end-before: example-end real-test-1 diff --git a/docs_input/api/math/explog/exp.rst b/docs_input/api/math/explog/exp.rst index a0969cc1..19ddb061 100644 --- a/docs_input/api/math/explog/exp.rst +++ b/docs_input/api/math/explog/exp.rst @@ -10,7 +10,7 @@ Exponential function Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin exp-test-1 :end-before: example-end exp-test-1 diff --git a/docs_input/api/math/explog/expj.rst b/docs_input/api/math/explog/expj.rst index 47e1f7f8..6f3f49e3 100644 --- a/docs_input/api/math/explog/expj.rst +++ b/docs_input/api/math/explog/expj.rst @@ -3,14 +3,14 @@ expj ==== -Computes exp(j*x) for each element x +Complex exponential .. doxygenfunction:: expj(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin expj-test-1 :end-before: example-end expj-test-1 diff --git a/docs_input/api/math/explog/log.rst b/docs_input/api/math/explog/log.rst index 5dc15e13..561ac28f 100644 --- a/docs_input/api/math/explog/log.rst +++ b/docs_input/api/math/explog/log.rst @@ -3,15 +3,14 @@ log === -Base e logarithm +Natural logarithm .. doxygenfunction:: log(Op t) -.. doxygenfunction:: loge(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log-test-1 :end-before: example-end log-test-1 diff --git a/docs_input/api/math/explog/log10.rst b/docs_input/api/math/explog/log10.rst index c9777b9e..158e158e 100644 --- a/docs_input/api/math/explog/log10.rst +++ b/docs_input/api/math/explog/log10.rst @@ -3,14 +3,14 @@ log10 ===== -Base 10 logarithm +Base-10 logarithm .. doxygenfunction:: log10(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log10-test-1 :end-before: example-end log10-test-1 diff --git a/docs_input/api/math/explog/log2.rst b/docs_input/api/math/explog/log2.rst index 79d6d835..269f69e0 100644 --- a/docs_input/api/math/explog/log2.rst +++ b/docs_input/api/math/explog/log2.rst @@ -3,14 +3,14 @@ log2 ==== -Base 2 logarithm +Base-2 logarithm .. doxygenfunction:: log2(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin log2-test-1 :end-before: example-end log2-test-1 diff --git a/docs_input/api/math/extrema/max.rst b/docs_input/api/math/extrema/max.rst index 2d7afcb4..f50f2d9f 100644 --- a/docs_input/api/math/extrema/max.rst +++ b/docs_input/api/math/extrema/max.rst @@ -25,7 +25,7 @@ Examples :end-before: example-end max-test-2 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin max-el-test-1 :end-before: example-end max-el-test-1 diff --git a/docs_input/api/math/extrema/min.rst b/docs_input/api/math/extrema/min.rst index 98274d46..d96e17e5 100644 --- a/docs_input/api/math/extrema/min.rst +++ b/docs_input/api/math/extrema/min.rst @@ -25,7 +25,7 @@ Examples :end-before: example-end min-test-2 :dedent: -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin min-el-test-1 :end-before: example-end min-el-test-1 diff --git a/docs_input/api/math/misc/abs.rst b/docs_input/api/math/misc/abs.rst index 52939852..831a5af0 100644 --- a/docs_input/api/math/misc/abs.rst +++ b/docs_input/api/math/misc/abs.rst @@ -10,7 +10,7 @@ Absolute value for real numbers, or complex magnitude for complex numbers Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin abs-test-1 :end-before: example-end abs-test-1 diff --git a/docs_input/api/math/misc/abs2.rst b/docs_input/api/math/misc/abs2.rst index 8e8736cf..a1b3cfb3 100644 --- a/docs_input/api/math/misc/abs2.rst +++ b/docs_input/api/math/misc/abs2.rst @@ -8,11 +8,11 @@ complex magnitude, or real(t)\ :sup:`2` + imag(t)\ :sup:`2`. For real numbers, this is equivalent to the squared value, or t\ :sup:`2`. .. doxygenfunction:: abs2(Op t) - + Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/abs2_test.cu :language: cpp :start-after: example-begin abs2-test-1 :end-before: example-end abs2-test-1 diff --git a/docs_input/api/math/misc/frexp.rst b/docs_input/api/math/misc/frexp.rst index f2a7ee5e..17e02fdc 100644 --- a/docs_input/api/math/misc/frexp.rst +++ b/docs_input/api/math/misc/frexp.rst @@ -6,11 +6,11 @@ frexp Return the normalized fraction and exponent part of a floating point number .. doxygenfunction:: frexp(const OpA &a) - + Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/frexp_test.cu :language: cpp :start-after: example-begin frexp-test-1 :end-before: example-end frexp-test-1 diff --git a/docs_input/api/math/misc/frexpc.rst b/docs_input/api/math/misc/frexpc.rst index d46b4a1e..ea79df3e 100644 --- a/docs_input/api/math/misc/frexpc.rst +++ b/docs_input/api/math/misc/frexpc.rst @@ -5,12 +5,12 @@ frexpc Return the normalized fraction and exponent part of a complex floating point number -.. doxygenfunction:: frexpc(const OpA &a) - +.. doxygenfunction:: frexpc(const OpA &a) + Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/frexpc_test.cu :language: cpp :start-after: example-begin frexpc-test-1 :end-before: example-end frexpc-test-1 diff --git a/docs_input/api/math/misc/rsqrt.rst b/docs_input/api/math/misc/rsqrt.rst index 00c64b43..2f57f487 100644 --- a/docs_input/api/math/misc/rsqrt.rst +++ b/docs_input/api/math/misc/rsqrt.rst @@ -10,7 +10,7 @@ Reciprocal square root Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin rsqrt-test-1 :end-before: example-end rsqrt-test-1 diff --git a/docs_input/api/math/misc/sqrt.rst b/docs_input/api/math/misc/sqrt.rst index 9e842382..076bff8e 100644 --- a/docs_input/api/math/misc/sqrt.rst +++ b/docs_input/api/math/misc/sqrt.rst @@ -10,7 +10,7 @@ Square root Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin sqrt-test-1 :end-before: example-end sqrt-test-1 diff --git a/docs_input/api/math/round/ceil.rst b/docs_input/api/math/round/ceil.rst index 34ddc1a3..ff701f79 100644 --- a/docs_input/api/math/round/ceil.rst +++ b/docs_input/api/math/round/ceil.rst @@ -10,7 +10,7 @@ Computes the smallest integer not less than the input Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin ceil-test-1 :end-before: example-end ceil-test-1 diff --git a/docs_input/api/math/round/floor.rst b/docs_input/api/math/round/floor.rst index 6d31fd06..c685b9c2 100644 --- a/docs_input/api/math/round/floor.rst +++ b/docs_input/api/math/round/floor.rst @@ -3,14 +3,14 @@ floor ===== -Computes the largest integer not greater than the input +Round down to nearest integer .. doxygenfunction:: floor(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin floor-test-1 :end-before: example-end floor-test-1 diff --git a/docs_input/api/math/round/round.rst b/docs_input/api/math/round/round.rst index 997a7336..c5d7a697 100644 --- a/docs_input/api/math/round/round.rst +++ b/docs_input/api/math/round/round.rst @@ -3,14 +3,14 @@ round ===== -Computes the nearest integer value +Round to nearest integer -.. doxygenfunction:: round(Op t) +.. doxygenfunction:: round(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/operator_func_test.cu :language: cpp :start-after: example-begin round-test-1 :end-before: example-end round-test-1 diff --git a/docs_input/api/math/trig/acos.rst b/docs_input/api/math/trig/acos.rst index 8a65093d..4a132606 100644 --- a/docs_input/api/math/trig/acos.rst +++ b/docs_input/api/math/trig/acos.rst @@ -10,7 +10,7 @@ Inverse cosine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin acos-test-1 :end-before: example-end acos-test-1 diff --git a/docs_input/api/math/trig/acosh.rst b/docs_input/api/math/trig/acosh.rst index 29afd09d..befbdb50 100644 --- a/docs_input/api/math/trig/acosh.rst +++ b/docs_input/api/math/trig/acosh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse cosine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin acosh-test-1 :end-before: example-end acosh-test-1 diff --git a/docs_input/api/math/trig/asin.rst b/docs_input/api/math/trig/asin.rst index f65858b0..aba085e1 100644 --- a/docs_input/api/math/trig/asin.rst +++ b/docs_input/api/math/trig/asin.rst @@ -10,7 +10,7 @@ Inverse sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin asin-test-1 :end-before: example-end asin-test-1 diff --git a/docs_input/api/math/trig/asinh.rst b/docs_input/api/math/trig/asinh.rst index 23e2581b..b3e3141b 100644 --- a/docs_input/api/math/trig/asinh.rst +++ b/docs_input/api/math/trig/asinh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin asinh-test-1 :end-before: example-end asinh-test-1 diff --git a/docs_input/api/math/trig/atan.rst b/docs_input/api/math/trig/atan.rst index eb6458a1..0c29d70b 100644 --- a/docs_input/api/math/trig/atan.rst +++ b/docs_input/api/math/trig/atan.rst @@ -10,7 +10,7 @@ Inverse tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin atan-test-1 :end-before: example-end atan-test-1 diff --git a/docs_input/api/math/trig/atanh.rst b/docs_input/api/math/trig/atanh.rst index 1ee40bce..482aaa60 100644 --- a/docs_input/api/math/trig/atanh.rst +++ b/docs_input/api/math/trig/atanh.rst @@ -10,7 +10,7 @@ Hyperbolic inverse tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin atanh-test-1 :end-before: example-end atanh-test-1 diff --git a/docs_input/api/math/trig/cart2sph.rst b/docs_input/api/math/trig/cart2sph.rst index 87d2aaba..5c4bc983 100644 --- a/docs_input/api/math/trig/cart2sph.rst +++ b/docs_input/api/math/trig/cart2sph.rst @@ -3,14 +3,14 @@ cart2sph ======== -Cartesian coordinates to spherical +Cartesian to spherical coordinates .. doxygenfunction:: cart2sph Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/sph2cart_test.cu :language: cpp :start-after: example-begin cart2sph-test-1 :end-before: example-end cart2sph-test-1 diff --git a/docs_input/api/math/trig/cos.rst b/docs_input/api/math/trig/cos.rst index 4c199ee9..316c6473 100644 --- a/docs_input/api/math/trig/cos.rst +++ b/docs_input/api/math/trig/cos.rst @@ -3,14 +3,14 @@ cos === -Cosine in radians +Cosine .. doxygenfunction:: cos(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin cos-test-1 :end-before: example-end cos-test-1 diff --git a/docs_input/api/math/trig/cosh.rst b/docs_input/api/math/trig/cosh.rst index c43efcef..4bf61375 100644 --- a/docs_input/api/math/trig/cosh.rst +++ b/docs_input/api/math/trig/cosh.rst @@ -3,14 +3,14 @@ cosh ==== -Hyperbolic coshine +Hyperbolic cosine .. doxygenfunction:: cosh(Op t) Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin cosh-test-1 :end-before: example-end cosh-test-1 diff --git a/docs_input/api/math/trig/sin.rst b/docs_input/api/math/trig/sin.rst index fbcf3600..2a23198b 100644 --- a/docs_input/api/math/trig/sin.rst +++ b/docs_input/api/math/trig/sin.rst @@ -10,7 +10,7 @@ Sine in radians Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin sin-test-1 :end-before: example-end sin-test-1 diff --git a/docs_input/api/math/trig/sinh.rst b/docs_input/api/math/trig/sinh.rst index d5e06c19..5948e4b1 100644 --- a/docs_input/api/math/trig/sinh.rst +++ b/docs_input/api/math/trig/sinh.rst @@ -10,7 +10,7 @@ Hyperbolic sine Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin sinh-test-1 :end-before: example-end sinh-test-1 diff --git a/docs_input/api/math/trig/sph2cart.rst b/docs_input/api/math/trig/sph2cart.rst index 37a5814d..a415d558 100644 --- a/docs_input/api/math/trig/sph2cart.rst +++ b/docs_input/api/math/trig/sph2cart.rst @@ -10,7 +10,7 @@ Spherical to Cartesian coordinates Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/sph2cart_test.cu :language: cpp :start-after: example-begin sph2cart-test-1 :end-before: example-end sph2cart-test-1 diff --git a/docs_input/api/math/trig/tan.rst b/docs_input/api/math/trig/tan.rst index 14b68713..3ee7691b 100644 --- a/docs_input/api/math/trig/tan.rst +++ b/docs_input/api/math/trig/tan.rst @@ -10,7 +10,7 @@ Tangent in radians Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin tan-test-1 :end-before: example-end tan-test-1 diff --git a/docs_input/api/math/trig/tanh.rst b/docs_input/api/math/trig/tanh.rst index ad9a8a80..dbcf7602 100644 --- a/docs_input/api/math/trig/tanh.rst +++ b/docs_input/api/math/trig/tanh.rst @@ -10,7 +10,7 @@ Hyperbolic tangent Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/trig_funcs_test.cu :language: cpp :start-after: example-begin tanh-test-1 :end-before: example-end tanh-test-1 diff --git a/docs_input/api/polynomials/legendre.rst b/docs_input/api/polynomials/legendre.rst index 59ec3a78..256a1c5d 100644 --- a/docs_input/api/polynomials/legendre.rst +++ b/docs_input/api/polynomials/legendre.rst @@ -12,7 +12,7 @@ Return Legendre polynomial coefficients at the input operator Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/legendre_test.cu :language: cpp :start-after: example-begin legendre-test-1 :end-before: example-end legendre-test-1 diff --git a/docs_input/api/polynomials/polyval.rst b/docs_input/api/polynomials/polyval.rst index 11639e0f..3d0722d0 100644 --- a/docs_input/api/polynomials/polyval.rst +++ b/docs_input/api/polynomials/polyval.rst @@ -10,7 +10,7 @@ Evaluate a polynomial given an input sequence and coefficients Examples ~~~~~~~~ -.. literalinclude:: ../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../test/00_operators/polyval_test.cu :language: cpp :start-after: example-begin polyval-test-1 :end-before: example-end polyval-test-1 diff --git a/docs_input/api/signalimage/general/downsample.rst b/docs_input/api/signalimage/general/downsample.rst index 7304bdfd..420d93af 100644 --- a/docs_input/api/signalimage/general/downsample.rst +++ b/docs_input/api/signalimage/general/downsample.rst @@ -10,7 +10,7 @@ downsample a signal by dropping samples Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/updownsample_test.cu :language: cpp :start-after: example-begin downsample-test-1 :end-before: example-end downsample-test-1 diff --git a/docs_input/api/signalimage/general/upsample.rst b/docs_input/api/signalimage/general/upsample.rst index ab9c7092..b5b2af61 100644 --- a/docs_input/api/signalimage/general/upsample.rst +++ b/docs_input/api/signalimage/general/upsample.rst @@ -10,7 +10,7 @@ Upsample a signal by stuffing zeros Examples ~~~~~~~~ -.. literalinclude:: ../../../../test/00_operators/OperatorTests.cu +.. literalinclude:: ../../../../test/00_operators/updownsample_test.cu :language: cpp :start-after: example-begin upsample-test-1 :end-before: example-end upsample-test-1 diff --git a/include/matx/core/make_sparse_tensor.h b/include/matx/core/make_sparse_tensor.h index d2c4c9d6..86d9e21a 100644 --- a/include/matx/core/make_sparse_tensor.h +++ b/include/matx/core/make_sparse_tensor.h @@ -78,7 +78,7 @@ auto make_tensor_coo(ValTensor &val, CrdTensor &row, CrdTensor &col, using CRD = typename CrdTensor::value_type; using POS = index_t; // Proper structure. - MATX_STATIC_ASSERT_STR(val.Rank() == 1 && row.Rank() == 1 && col.Rank() == 1, + MATX_STATIC_ASSERT_STR(ValTensor::Rank() == 1 && CrdTensor::Rank() == 1 && CrdTensor::Rank() == 1, matxInvalidParameter, "data arrays should be rank-1"); MATX_ASSERT_STR(val.Size(0) == row.Size(0) && val.Size(0) == col.Size(0), matxInvalidParameter, @@ -119,7 +119,7 @@ auto make_tensor_csr(ValTensor &val, PosTensor &rowp, CrdTensor &col, using CRD = typename CrdTensor::value_type; using POS = typename PosTensor::value_type; // Proper structure. - MATX_STATIC_ASSERT_STR(val.Rank() == 1 && rowp.Rank() == 1 && col.Rank() == 1, + MATX_STATIC_ASSERT_STR(ValTensor::Rank() == 1 && PosTensor::Rank() == 1 && CrdTensor::Rank() == 1, matxInvalidParameter, "data arrays should be rank-1"); MATX_ASSERT_STR(rowp.Size(0) == shape[0] + 1, matxInvalidParameter, "row positions arrays should have length #rows + 1"); @@ -155,7 +155,7 @@ auto make_tensor_csc(ValTensor &val, PosTensor &colp, CrdTensor &row, using CRD = typename CrdTensor::value_type; using POS = typename PosTensor::value_type; // Proper structure. - MATX_STATIC_ASSERT_STR(val.Rank() == 1 && row.Rank() == 1 && colp.Rank() == 1, + MATX_STATIC_ASSERT_STR(ValTensor::Rank() == 1 && CrdTensor::Rank() == 1 && PosTensor::Rank() == 1, matxInvalidParameter, "data arrays should be rank-1"); MATX_ASSERT_STR(colp.Size(0) == shape[1] + 1, matxInvalidParameter, "column positions array should have length #columns + 1"); diff --git a/test/00_operators/reshape_test.cu b/test/00_operators/reshape_test.cu index 5c82e33f..d9eca2e4 100644 --- a/test/00_operators/reshape_test.cu +++ b/test/00_operators/reshape_test.cu @@ -12,72 +12,46 @@ TYPED_TEST(OperatorTestsAllExecs, ReshapeOp) using TestType = cuda::std::tuple_element_t<0, TypeParam>; using ExecType = cuda::std::tuple_element_t<1, TypeParam>; - ExecType exec{}; - index_t count = 10; - tensor_t t4({count, count, count, count}); - tensor_t t1({count * count * count * count}); - - for (index_t i = 0; i < t4.Size(0); i++) { - for (index_t j = 0; j < t4.Size(1); j++) { - for (index_t k = 0; k < t4.Size(2); k++) { - for (index_t l = 0; l < t4.Size(3); l++) { - t4(i, j, k, l) = - static_cast>(i + j + k + l); - t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1)) = - static_cast>(i + j + k + l); - } - } - } - } - - // Drop to a single dimension of same original total size - auto rsv1 = t4.View({count * count * count * count}); - for (index_t i = 0; i < t4.Size(0); i++) { - for (index_t j = 0; j < t4.Size(1); j++) { - for (index_t k = 0; k < t4.Size(2); k++) { - for (index_t l = 0; l < t4.Size(3); l++) { - MATX_ASSERT_EQ(rsv1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1)), - (TestType)(i + j + k + (double)l)); - } - } - } - } + ExecType exec{}; - // Drop to 2D with a subset of the original size - auto rsv2 = t4.View({2, 2}); - for (index_t i = 0; i < rsv2.Size(0); i++) { - for (index_t j = 0; j < rsv2.Size(1); j++) { - MATX_ASSERT_EQ(rsv2(i, j), t4(0, 0, 0, i * rsv2.Size(1) + j)); - } + // example-begin reshape-test-1 + auto A = make_tensor({2*4*8*16}); + for(int i = 0; i < A.Size(0); i++) { + A(i) = static_cast::type>(i); } - // Create a 4D tensor from the 1D - auto rsv4 = t1.View({count, count, count, count}); - for (index_t i = 0; i < rsv4.Size(0); i++) { - for (index_t j = 0; j < rsv4.Size(1); j++) { - for (index_t k = 0; k < rsv4.Size(2); k++) { - for (index_t l = 0; l < rsv4.Size(3); l++) { - MATX_ASSERT_EQ(rsv4(i, j, k, l), - t1(l + k * t4.Size(3) + j * t4.Size(3) * t4.Size(2) + - i * t4.Size(3) * t4.Size(2) * t4.Size(1))); + // op is a 4D operator + auto op = reshape(A, {2, 4, 8, 16}); + + // op2 is a 1D operator + auto op2 = reshape(op, {2 * 4 * 8 * 16}); + // example-end reshape-test-1 + + ASSERT_TRUE(op.Rank() == 4); + ASSERT_TRUE(op2.Rank() == 1); + + ASSERT_TRUE(op.Size(0) == 2 ); + ASSERT_TRUE(op.Size(1) == 4 ); + ASSERT_TRUE(op.Size(2) == 8 ); + ASSERT_TRUE(op.Size(3) == 16 ); + + ASSERT_TRUE(op2.Size(0) == A.TotalSize() ); + + int idx = 0; + for(int i=0; i < op.Size(0); i++) { + for(int j=0; j < op.Size(1); j++) { + for(int k=0; k < op.Size(2); k++) { + for(int l=0; l < op.Size(3); l++) { + ASSERT_TRUE( A(idx) == op(i,j,k,l) ); + ASSERT_TRUE( A(idx) == op2(idx)); + idx++; } } } } - - // Test if oversized views throw -#ifndef NDEBUG - try { - t4.View({1000, 1000, 100}); - FAIL() << "Oversized views not throwing"; - } catch (detail::matxException &e) {} -#endif - MATX_EXIT_HANDLER(); -} +} TYPED_TEST(OperatorTestsNumericAllExecs, Reshape)