From 1a36590e8475f688ef42122c0dd96f7a3b89654e Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 14 Jan 2015 12:43:20 -0800 Subject: Fixed the printing of RowMajor tensors --- unsupported/test/cxx11_tensor_io.cpp | 58 +++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'unsupported/test/cxx11_tensor_io.cpp') diff --git a/unsupported/test/cxx11_tensor_io.cpp b/unsupported/test/cxx11_tensor_io.cpp index b73c024f5..8bbcf7089 100644 --- a/unsupported/test/cxx11_tensor_io.cpp +++ b/unsupported/test/cxx11_tensor_io.cpp @@ -13,9 +13,10 @@ #include +template static void test_output_1d() { - Tensor tensor(5); + Tensor tensor(5); for (int i = 0; i < 5; ++i) { tensor(i) = i; } @@ -28,9 +29,10 @@ static void test_output_1d() } +template static void test_output_2d() { - Tensor tensor(5, 3); + Tensor tensor(5, 3); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 3; ++j) { tensor(i, j) = i*j; @@ -45,10 +47,11 @@ static void test_output_2d() } +template static void test_output_expr() { - Tensor tensor1(5); - Tensor tensor2(5); + Tensor tensor1(5); + Tensor tensor2(5); for (int i = 0; i < 5; ++i) { tensor1(i) = i; tensor2(i) = 7; @@ -62,9 +65,50 @@ static void test_output_expr() } +template +static void test_output_string() +{ + Tensor tensor(5, 3); + tensor.setConstant(std::string("foo")); + + std::cout << tensor << std::endl; + + std::stringstream os; + os << tensor; + + std::string expected("foo foo foo\nfoo foo foo\nfoo foo foo\nfoo foo foo\nfoo foo foo"); + VERIFY_IS_EQUAL(std::string(os.str()), expected); +} + + +template +static void test_output_const() +{ + Tensor tensor(5); + for (int i = 0; i < 5; ++i) { + tensor(i) = i; + } + + TensorMap > tensor_map(tensor.data(), 5); + + std::stringstream os; + os << tensor_map; + + std::string expected("0\n1\n2\n3\n4"); + VERIFY_IS_EQUAL(std::string(os.str()), expected); +} + + void test_cxx11_tensor_io() { - CALL_SUBTEST(test_output_1d()); - CALL_SUBTEST(test_output_2d()); - CALL_SUBTEST(test_output_expr()); + CALL_SUBTEST(test_output_1d()); + CALL_SUBTEST(test_output_1d()); + CALL_SUBTEST(test_output_2d()); + CALL_SUBTEST(test_output_2d()); + CALL_SUBTEST(test_output_expr()); + CALL_SUBTEST(test_output_expr()); + CALL_SUBTEST(test_output_string()); + CALL_SUBTEST(test_output_string()); + CALL_SUBTEST(test_output_const()); + CALL_SUBTEST(test_output_const()); } -- cgit v1.2.3