summaryrefslogtreecommitdiff
path: root/libcxx/test/libcxx-03/numerics/numarray
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/libcxx-03/numerics/numarray')
-rw-r--r--libcxx/test/libcxx-03/numerics/numarray/class.gslice.array/get.pass.cpp52
-rw-r--r--libcxx/test/libcxx-03/numerics/numarray/class.indirect.array/get.pass.cpp44
-rw-r--r--libcxx/test/libcxx-03/numerics/numarray/class.mask.array/get.pass.cpp51
-rw-r--r--libcxx/test/libcxx-03/numerics/numarray/class.slice.array/get.pass.cpp46
4 files changed, 193 insertions, 0 deletions
diff --git a/libcxx/test/libcxx-03/numerics/numarray/class.gslice.array/get.pass.cpp b/libcxx/test/libcxx-03/numerics/numarray/class.gslice.array/get.pass.cpp
new file mode 100644
index 000000000000..2a1842f69fd2
--- /dev/null
+++ b/libcxx/test/libcxx-03/numerics/numarray/class.gslice.array/get.pass.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class gslice_array;
+
+// T __get(size_t i);
+
+#include <valarray>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ unsigned input[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ const unsigned N = sizeof(input) / sizeof(input[0]);
+
+ std::valarray<unsigned> array(input, N);
+
+ {
+ std::gslice_array<unsigned> result =
+ array[std::gslice(0, std::valarray<std::size_t>(N, 1), std::valarray<std::size_t>(1, 1))];
+ for (unsigned i = 0; i < N; ++i)
+ assert(result.__get(i) == i);
+ }
+
+ {
+ std::valarray<std::size_t> sizes(2);
+ sizes[0] = 2;
+ sizes[1] = 3;
+
+ std::valarray<std::size_t> strides(2);
+ strides[0] = 6;
+ strides[1] = 1;
+
+ std::gslice_array<unsigned> result = array[std::gslice(1, sizes, strides)];
+ assert(result.__get(0) == input[1 + 0 * 6 + 0 * 1]);
+ assert(result.__get(1) == input[1 + 0 * 6 + 1 * 1]);
+ assert(result.__get(2) == input[1 + 0 * 6 + 2 * 1]);
+
+ assert(result.__get(3) == input[1 + 1 * 6 + 0 * 1]);
+ assert(result.__get(4) == input[1 + 1 * 6 + 1 * 1]);
+ assert(result.__get(5) == input[1 + 1 * 6 + 2 * 1]);
+ }
+ return 0;
+}
diff --git a/libcxx/test/libcxx-03/numerics/numarray/class.indirect.array/get.pass.cpp b/libcxx/test/libcxx-03/numerics/numarray/class.indirect.array/get.pass.cpp
new file mode 100644
index 000000000000..3c50c740bcab
--- /dev/null
+++ b/libcxx/test/libcxx-03/numerics/numarray/class.indirect.array/get.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class indirect_array;
+
+// T __get(size_t i);
+
+#include <valarray>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ unsigned input[] = {0, 1, 2, 3, 4};
+ const unsigned N = sizeof(input) / sizeof(input[0]);
+
+ std::valarray<unsigned> array(input, N);
+
+ {
+ std::indirect_array<unsigned> result = array[std::valarray<std::size_t>(std::size_t(0), std::size_t(N))];
+ for (unsigned i = 0; i < N; ++i)
+ assert(result.__get(i) == 0);
+ }
+
+ {
+ std::valarray<std::size_t> indirect(std::size_t(0), std::size_t(3));
+ indirect[0] = 4;
+ indirect[1] = 1;
+ indirect[2] = 3;
+ std::indirect_array<unsigned> result = array[indirect];
+ assert(result.__get(0) == 4);
+ assert(result.__get(1) == 1);
+ assert(result.__get(2) == 3);
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/libcxx-03/numerics/numarray/class.mask.array/get.pass.cpp b/libcxx/test/libcxx-03/numerics/numarray/class.mask.array/get.pass.cpp
new file mode 100644
index 000000000000..e34c38289222
--- /dev/null
+++ b/libcxx/test/libcxx-03/numerics/numarray/class.mask.array/get.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class mask_array;
+
+// T __get(size_t i);
+
+#include <valarray>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ unsigned input[] = {0, 1, 2, 3, 4};
+ const unsigned N = sizeof(input) / sizeof(input[0]);
+
+ std::valarray<unsigned> array(input, N);
+
+ {
+ std::mask_array<unsigned> result = array[std::valarray<bool>(true, N)];
+ for (unsigned i = 0; i < N; ++i)
+ assert(result.__get(i) == i);
+ }
+
+ {
+ std::valarray<bool> mask(false, N);
+ mask[1] = true;
+ mask[3] = true;
+ std::mask_array<unsigned> result = array[mask];
+ assert(result.__get(0) == 1);
+ assert(result.__get(1) == 3);
+ }
+
+ {
+ std::valarray<bool> mask(false, N);
+ mask[0] = true;
+ mask[4] = true;
+ std::mask_array<unsigned> result = array[mask];
+ assert(result.__get(0) == 0);
+ assert(result.__get(1) == 4);
+ }
+
+ return 0;
+}
diff --git a/libcxx/test/libcxx-03/numerics/numarray/class.slice.array/get.pass.cpp b/libcxx/test/libcxx-03/numerics/numarray/class.slice.array/get.pass.cpp
new file mode 100644
index 000000000000..26871f310bae
--- /dev/null
+++ b/libcxx/test/libcxx-03/numerics/numarray/class.slice.array/get.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// template<class T> class slice_array;
+
+// T __get(size_t i);
+
+#include <valarray>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ unsigned input[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ const unsigned N = sizeof(input) / sizeof(input[0]);
+
+ std::valarray<unsigned> array(input, N);
+
+ {
+ std::slice_array<unsigned> result = array[std::slice(0, N, 1)];
+ for (unsigned i = 0; i < N; ++i)
+ assert(result.__get(i) == i);
+ }
+
+ {
+ std::slice_array<unsigned> result = array[std::slice(3, 2, 2)];
+ assert(result.__get(0) == 3);
+ assert(result.__get(1) == 5);
+ }
+
+ {
+ std::slice_array<unsigned> result = array[std::slice(1, 3, 4)];
+ assert(result.__get(0) == 1);
+ assert(result.__get(1) == 5);
+ assert(result.__get(2) == 9);
+ }
+
+ return 0;
+}