From 93ace218dc4cc28b3731ef2ffb5b18681f4c5e2b Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 29 Jul 2019 18:38:38 -0400 Subject: [PATCH] Implement output operator for VectorizedArray --- include/deal.II/base/vectorization.h | 17 +++++++- tests/base/vectorization_12.cc | 65 ++++++++++++++++++++++++++++ tests/base/vectorization_12.output | 3 ++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/base/vectorization_12.cc create mode 100644 tests/base/vectorization_12.output diff --git a/include/deal.II/base/vectorization.h b/include/deal.II/base/vectorization.h index c582929593..38936091c3 100644 --- a/include/deal.II/base/vectorization.h +++ b/include/deal.II/base/vectorization.h @@ -3841,9 +3841,24 @@ inline DEAL_II_ALWAYS_INLINE VectorizedArray return VectorizedArray() - u; } +/** + * Output operator for vectorized array. + * + * @relatesalso VectorizedArray + */ +template +inline std::ostream & +operator<<(std::ostream &out, const VectorizedArray &p) +{ + constexpr unsigned int n = VectorizedArray::n_array_elements; + for (unsigned int i = 0; i < n - 1; ++i) + out << p[i] << ' '; + out << p[n - 1]; -DEAL_II_NAMESPACE_CLOSE + return out; +} +DEAL_II_NAMESPACE_CLOSE /** * Implementation of functions from cmath on VectorizedArray. These functions diff --git a/tests/base/vectorization_12.cc b/tests/base/vectorization_12.cc new file mode 100644 index 0000000000..a196b99579 --- /dev/null +++ b/tests/base/vectorization_12.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// test printing a VectorizedArray object + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + constexpr unsigned int n = VectorizedArray::n_array_elements; + + VectorizedArray a; + std::stringstream test_stream; + for (unsigned int i = 0; i < n; ++i) + a[i] = (i + 1); + test_stream << a; + + std::stringstream reference_stream; + for (unsigned int i = 0; i < n - 1; ++i) + { + reference_stream << Number(i + 1) << " "; + } + reference_stream << Number(n); + + if (reference_stream.str() != test_stream.str()) + { + deallog << "Error: " << test_stream.str() << " should be " + << reference_stream.str() << std::endl; + AssertThrow(false, ExcInternalError()); + } + deallog << "OK" << std::endl; +} + + + +int +main() +{ + initlog(); + + deallog << "Test double: "; + test(); + deallog << "Test int: "; + test(); +} diff --git a/tests/base/vectorization_12.output b/tests/base/vectorization_12.output new file mode 100644 index 0000000000..a27493ff4b --- /dev/null +++ b/tests/base/vectorization_12.output @@ -0,0 +1,3 @@ + +DEAL::Test double: OK +DEAL::Test int: OK -- 2.39.5