]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement output operator for VectorizedArray
authorDaniel Arndt <arndtd@ornl.gov>
Mon, 29 Jul 2019 22:38:38 +0000 (18:38 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Tue, 30 Jul 2019 12:59:26 +0000 (08:59 -0400)
include/deal.II/base/vectorization.h
tests/base/vectorization_12.cc [new file with mode: 0644]
tests/base/vectorization_12.output [new file with mode: 0644]

index c582929593fa207231729089c535b448057a584b..38936091c35ee5a1dc4b1c38c5a2f750b25d9736 100644 (file)
@@ -3841,9 +3841,24 @@ inline DEAL_II_ALWAYS_INLINE VectorizedArray<Number, width>
   return VectorizedArray<Number, width>() - u;
 }
 
+/**
+ * Output operator for vectorized array.
+ *
+ * @relatesalso VectorizedArray
+ */
+template <typename Number, int width>
+inline std::ostream &
+operator<<(std::ostream &out, const VectorizedArray<Number, width> &p)
+{
+  constexpr unsigned int n = VectorizedArray<Number, width>::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 (file)
index 0000000..a196b99
--- /dev/null
@@ -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 <deal.II/base/vectorization.h>
+
+#include <sstream>
+
+#include "../tests.h"
+
+
+template <typename Number>
+void
+test()
+{
+  constexpr unsigned int n = VectorizedArray<Number>::n_array_elements;
+
+  VectorizedArray<Number> 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<double>();
+  deallog << "Test int: ";
+  test<int>();
+}
diff --git a/tests/base/vectorization_12.output b/tests/base/vectorization_12.output
new file mode 100644 (file)
index 0000000..a27493f
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Test double: OK
+DEAL::Test int: OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.