-
Notifications
You must be signed in to change notification settings - Fork 1.6k
<valarray>: Implement copies for slice_array, gslice_array, mask_array, and indirect_array #988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e00b11a
563960d
a445153
e10ba6a
7c1ef11
8c97417
974ccb2
b776945
7d4b040
e4afd4b
ae46fb4
662fbe9
dd3d547
243bb3a
5e7a331
8b84713
c5a2ba7
8c251df
471720c
caf1fc0
1a12d38
454246e
11e1412
2a6a122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\usual_matrix.lst |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <cstddef> | ||
| #include <iostream> | ||
| #include <valarray> | ||
|
|
||
| template <class T> | ||
| bool eq(const std::valarray<T>& v, std::initializer_list<T> il) { | ||
| return std::equal(begin(v), end(v), il.begin(), il.end()); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void test_slice() { | ||
| std::valarray<int> v{0, 1, 2, 3, 4}; | ||
|
|
||
| std::slice_array<int> slice_array = v[std::slice(2, 2, 2)]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No change requested, just a stylistic comment - while we have tests that vary in their usage of Since it looks like this PR will be ready to merge with a couple of include fixups (yay!), I don't think it's worth renaming now, but I wanted to mention it. |
||
| std::slice_array<int> slice_array_copy = slice_array; | ||
| (void) slice_array_copy; | ||
|
|
||
| assert(eq(v, {0, 1, 2, 3, 4})); | ||
|
|
||
| std::slice_array<int> other_slice_array = v[std::slice(0, 2, 1)]; | ||
| other_slice_array = slice_array; | ||
AlexGuteniev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assert(eq(v, {2, 4, 2, 3, 4})); | ||
| } | ||
|
|
||
| void test_gslice() { | ||
| std::valarray<int> v{0, 1, 2, 3, 4}; | ||
|
|
||
| std::gslice gslice(2, std::valarray<std::size_t>{2}, std::valarray<std::size_t>{2}); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::gslice_array<int> gslice_array = v[gslice]; | ||
| std::gslice_array<int> gslice_array_copy = gslice_array; | ||
| (void) gslice_array_copy; | ||
|
|
||
| assert(eq(v, {0, 1, 2, 3, 4})); | ||
|
|
||
| std::gslice other_gslice(0, std::valarray<std::size_t>{2}, std::valarray<std::size_t>{1}); | ||
| std::gslice_array<int> other_gslice_array = v[other_gslice]; | ||
| other_gslice_array = gslice_array; | ||
AlexGuteniev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| assert(eq(v, {2, 4, 2, 3, 4})); | ||
| } | ||
|
|
||
| void test_mask() { | ||
| std::valarray<int> v{0, 1, 2, 3, 4}; | ||
|
|
||
| std::valarray<bool> mask{true, false, false, false, true}; | ||
| std::mask_array<int> mask_array = v[mask]; | ||
| std::mask_array<int> mask_array_copy = mask_array; | ||
| (void) mask_array_copy; | ||
|
|
||
| assert(eq(v, {0, 1, 2, 3, 4})); | ||
|
|
||
| std::valarray<bool> other_mask{false, true, true, false, false}; | ||
| std::mask_array<int> other_mask_array = v[other_mask]; | ||
| other_mask_array = mask_array; | ||
|
|
||
| assert(eq(v, {0, 0, 4, 3, 4})); | ||
| } | ||
|
|
||
| void test_indirect() { | ||
| std::valarray<int> v{0, 1, 2, 3, 4}; | ||
|
|
||
| std::valarray<std::size_t> indices{2, 3}; | ||
| std::indirect_array<int> indirect_array = v[indices]; | ||
| std::indirect_array<int> indirect_array_copy = indirect_array; | ||
| (void) indirect_array_copy; | ||
|
|
||
| assert(eq(v, {0, 1, 2, 3, 4})); | ||
|
|
||
| std::valarray<std::size_t> other_indices{4, 0}; | ||
| std::indirect_array<int> other_indirect_array = v[other_indices]; | ||
| other_indirect_array = indirect_array; | ||
|
|
||
| assert(eq(v, {3, 1, 2, 3, 2})); | ||
| } | ||
|
|
||
| int main() { | ||
| test_slice(); | ||
| test_gslice(); | ||
| test_mask(); | ||
| test_indirect(); | ||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.