[libcxx-commits] [libcxx] r357453 - Fix a number of bugs in __val_expr's subset operator[].
Eric Fiselier via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Apr 2 01:05:23 PDT 2019
Author: ericwf
Date: Tue Apr 2 01:05:23 2019
New Revision: 357453
URL: http://llvm.org/viewvc/llvm-project?rev=357453&view=rev
Log:
Fix a number of bugs in __val_expr's subset operator[].
The current definitions were entirely broken. They didn't call any
existing constructor and the forgot to friend the expression types they
were trying to construct.
Modified:
libcxx/trunk/include/valarray
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp
libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp
Modified: libcxx/trunk/include/valarray
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/valarray?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/include/valarray (original)
+++ libcxx/trunk/include/valarray Tue Apr 2 01:05:23 2019
@@ -673,6 +673,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __size_;}
+ template <class> friend class __val_expr;
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
};
@@ -2221,6 +2222,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __1d_.size();}
+ template <class> friend class __val_expr;
template <class> friend class valarray;
};
@@ -2591,6 +2593,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __1d_.size();}
+ template <class> friend class __val_expr;
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
};
@@ -2613,19 +2616,31 @@ public:
_LIBCPP_INLINE_VISIBILITY
__val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
- {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);}
+ {
+ typedef __slice_expr<_ValExpr> _NewExpr;
+ return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
+ }
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
- {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);}
+ {
+ typedef __indirect_expr<_ValExpr> _NewExpr;
+ return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
+ }
_LIBCPP_INLINE_VISIBILITY
__val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
- {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);}
+ {
+ typedef __mask_expr<_ValExpr> _NewExpr;
+ return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
+ }
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
- {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);}
+ {
+ typedef __indirect_expr<_ValExpr> _NewExpr;
+ return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
+ }
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,62 +17,64 @@
int main(int, char**)
{
- int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- 36, 37, 38, 39, 40};
- int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11,
- -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23};
- std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
- std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
- std::size_t sz[] = {2, 4, 3};
- std::size_t st[] = {19, 4, 1};
- typedef std::valarray<std::size_t> sizes;
- typedef std::valarray<std::size_t> strides;
- v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
- strides(st, sizeof(st)/sizeof(st[0])))] = v2;
- assert(v1.size() == 41);
- assert(v1[ 0] == 0);
- assert(v1[ 1] == 1);
- assert(v1[ 2] == 2);
- assert(v1[ 3] == 0);
- assert(v1[ 4] == -1);
- assert(v1[ 5] == -2);
- assert(v1[ 6] == 6);
- assert(v1[ 7] == -3);
- assert(v1[ 8] == -4);
- assert(v1[ 9] == -5);
- assert(v1[10] == 10);
- assert(v1[11] == -6);
- assert(v1[12] == -7);
- assert(v1[13] == -8);
- assert(v1[14] == 14);
- assert(v1[15] == -9);
- assert(v1[16] == -10);
- assert(v1[17] == -11);
- assert(v1[18] == 18);
- assert(v1[19] == 19);
- assert(v1[20] == 20);
- assert(v1[21] == 21);
- assert(v1[22] == -12);
- assert(v1[23] == -13);
- assert(v1[24] == -14);
- assert(v1[25] == 25);
- assert(v1[26] == -15);
- assert(v1[27] == -16);
- assert(v1[28] == -17);
- assert(v1[29] == 29);
- assert(v1[30] == -18);
- assert(v1[31] == -19);
- assert(v1[32] == -20);
- assert(v1[33] == 33);
- assert(v1[34] == -21);
- assert(v1[35] == -22);
- assert(v1[36] == -23);
- assert(v1[37] == 37);
- assert(v1[38] == 38);
- assert(v1[39] == 39);
- assert(v1[40] == 40);
+ {
+ int a1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40};
+ int a2[] = { -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11,
+ -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23};
+ std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
+ std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
+ std::size_t sz[] = {2, 4, 3};
+ std::size_t st[] = {19, 4, 1};
+ typedef std::valarray<std::size_t> sizes;
+ typedef std::valarray<std::size_t> strides;
+ v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
+ strides(st, sizeof(st)/sizeof(st[0])))] = v2;
+ assert(v1.size() == 41);
+ assert(v1[ 0] == 0);
+ assert(v1[ 1] == 1);
+ assert(v1[ 2] == 2);
+ assert(v1[ 3] == 0);
+ assert(v1[ 4] == -1);
+ assert(v1[ 5] == -2);
+ assert(v1[ 6] == 6);
+ assert(v1[ 7] == -3);
+ assert(v1[ 8] == -4);
+ assert(v1[ 9] == -5);
+ assert(v1[10] == 10);
+ assert(v1[11] == -6);
+ assert(v1[12] == -7);
+ assert(v1[13] == -8);
+ assert(v1[14] == 14);
+ assert(v1[15] == -9);
+ assert(v1[16] == -10);
+ assert(v1[17] == -11);
+ assert(v1[18] == 18);
+ assert(v1[19] == 19);
+ assert(v1[20] == 20);
+ assert(v1[21] == 21);
+ assert(v1[22] == -12);
+ assert(v1[23] == -13);
+ assert(v1[24] == -14);
+ assert(v1[25] == 25);
+ assert(v1[26] == -15);
+ assert(v1[27] == -16);
+ assert(v1[28] == -17);
+ assert(v1[29] == 29);
+ assert(v1[30] == -18);
+ assert(v1[31] == -19);
+ assert(v1[32] == -20);
+ assert(v1[33] == 33);
+ assert(v1[34] == -21);
+ assert(v1[35] == -22);
+ assert(v1[36] == -23);
+ assert(v1[37] == 37);
+ assert(v1[38] == 38);
+ assert(v1[39] == 39);
+ assert(v1[40] == 40);
+ }
- return 0;
+ return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/gslice_non_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,42 +17,81 @@
int main(int, char**)
{
- int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- 36, 37, 38, 39, 40};
- std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
- std::size_t sz[] = {2, 4, 3};
- std::size_t st[] = {19, 4, 1};
- typedef std::valarray<std::size_t> sizes;
- typedef std::valarray<std::size_t> strides;
- std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
- strides(st, sizeof(st)/sizeof(st[0])))]);
- assert(v.size() == 24);
- assert(v[ 0] == 3);
- assert(v[ 1] == 4);
- assert(v[ 2] == 5);
- assert(v[ 3] == 7);
- assert(v[ 4] == 8);
- assert(v[ 5] == 9);
- assert(v[ 6] == 11);
- assert(v[ 7] == 12);
- assert(v[ 8] == 13);
- assert(v[ 9] == 15);
- assert(v[10] == 16);
- assert(v[11] == 17);
- assert(v[12] == 22);
- assert(v[13] == 23);
- assert(v[14] == 24);
- assert(v[15] == 26);
- assert(v[16] == 27);
- assert(v[17] == 28);
- assert(v[18] == 30);
- assert(v[19] == 31);
- assert(v[20] == 32);
- assert(v[21] == 34);
- assert(v[22] == 35);
- assert(v[23] == 36);
-
+ {
+ int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40};
+ std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
+ std::size_t sz[] = {2, 4, 3};
+ std::size_t st[] = {19, 4, 1};
+ typedef std::valarray<std::size_t> sizes;
+ typedef std::valarray<std::size_t> strides;
+ std::valarray<int> v(v1[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
+ strides(st, sizeof(st)/sizeof(st[0])))]);
+ assert(v.size() == 24);
+ assert(v[ 0] == 3);
+ assert(v[ 1] == 4);
+ assert(v[ 2] == 5);
+ assert(v[ 3] == 7);
+ assert(v[ 4] == 8);
+ assert(v[ 5] == 9);
+ assert(v[ 6] == 11);
+ assert(v[ 7] == 12);
+ assert(v[ 8] == 13);
+ assert(v[ 9] == 15);
+ assert(v[10] == 16);
+ assert(v[11] == 17);
+ assert(v[12] == 22);
+ assert(v[13] == 23);
+ assert(v[14] == 24);
+ assert(v[15] == 26);
+ assert(v[16] == 27);
+ assert(v[17] == 28);
+ assert(v[18] == 30);
+ assert(v[19] == 31);
+ assert(v[20] == 32);
+ assert(v[21] == 34);
+ assert(v[22] == 35);
+ assert(v[23] == 36);
+ }
+ {
+ int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40};
+ std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
+ std::size_t sz[] = {2, 4, 3};
+ std::size_t st[] = {19, 4, 1};
+ typedef std::valarray<std::size_t> sizes;
+ typedef std::valarray<std::size_t> strides;
+ std::valarray<int> v((v1 + 0)[std::gslice(3, sizes(sz, sizeof(sz)/sizeof(sz[0])),
+ strides(st, sizeof(st)/sizeof(st[0])))]);
+ assert(v.size() == 24);
+ assert(v[ 0] == 3);
+ assert(v[ 1] == 4);
+ assert(v[ 2] == 5);
+ assert(v[ 3] == 7);
+ assert(v[ 4] == 8);
+ assert(v[ 5] == 9);
+ assert(v[ 6] == 11);
+ assert(v[ 7] == 12);
+ assert(v[ 8] == 13);
+ assert(v[ 9] == 15);
+ assert(v[10] == 16);
+ assert(v[11] == 17);
+ assert(v[12] == 22);
+ assert(v[13] == 23);
+ assert(v[14] == 24);
+ assert(v[15] == 26);
+ assert(v[16] == 27);
+ assert(v[17] == 28);
+ assert(v[18] == 30);
+ assert(v[19] == 31);
+ assert(v[20] == 32);
+ assert(v[21] == 34);
+ assert(v[22] == 35);
+ assert(v[23] == 36);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,42 +17,56 @@
int main(int, char**)
{
- int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- 36, 37, 38, 39, 40};
- const std::size_t N1 = sizeof(a)/sizeof(a[0]);
- std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
- 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
- const std::size_t S = sizeof(s)/sizeof(s[0]);
- const std::valarray<int> v1(a, N1);
- std::valarray<std::size_t> ia(s, S);
- std::valarray<int> v = v1[ia];
- assert(v.size() == 24);
- assert(v[ 0] == 3);
- assert(v[ 1] == 4);
- assert(v[ 2] == 5);
- assert(v[ 3] == 7);
- assert(v[ 4] == 8);
- assert(v[ 5] == 9);
- assert(v[ 6] == 11);
- assert(v[ 7] == 12);
- assert(v[ 8] == 13);
- assert(v[ 9] == 15);
- assert(v[10] == 16);
- assert(v[11] == 17);
- assert(v[12] == 22);
- assert(v[13] == 23);
- assert(v[14] == 24);
- assert(v[15] == 26);
- assert(v[16] == 27);
- assert(v[17] == 28);
- assert(v[18] == 30);
- assert(v[19] == 31);
- assert(v[20] == 32);
- assert(v[21] == 34);
- assert(v[22] == 35);
- assert(v[23] == 36);
-
+ {
+ int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40};
+ const std::size_t N1 = sizeof(a)/sizeof(a[0]);
+ std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
+ 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
+ const std::size_t S = sizeof(s)/sizeof(s[0]);
+ const std::valarray<int> v1(a, N1);
+ std::valarray<std::size_t> ia(s, S);
+ std::valarray<int> v = v1[ia];
+ assert(v.size() == 24);
+ assert(v[ 0] == 3);
+ assert(v[ 1] == 4);
+ assert(v[ 2] == 5);
+ assert(v[ 3] == 7);
+ assert(v[ 4] == 8);
+ assert(v[ 5] == 9);
+ assert(v[ 6] == 11);
+ assert(v[ 7] == 12);
+ assert(v[ 8] == 13);
+ assert(v[ 9] == 15);
+ assert(v[10] == 16);
+ assert(v[11] == 17);
+ assert(v[12] == 22);
+ assert(v[13] == 23);
+ assert(v[14] == 24);
+ assert(v[15] == 26);
+ assert(v[16] == 27);
+ assert(v[17] == 28);
+ assert(v[18] == 30);
+ assert(v[19] == 31);
+ assert(v[20] == 32);
+ assert(v[21] == 34);
+ assert(v[22] == 35);
+ assert(v[23] == 36);
+ }
+ {
+ int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
+ std::size_t idx_data[] = {0,2,4,6,8};
+ const std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
+ std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
+ std::valarray<int> result = (data + 0)[idx];
+ assert(result.size() == 5);
+ assert(result[0] == data[idx[0]]);
+ assert(result[1] == data[idx[1]]);
+ assert(result[2] == data[idx[2]]);
+ assert(result[3] == data[idx[3]]);
+ assert(result[4] == data[idx[4]]);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/indirect_array_non_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,43 +17,57 @@
int main(int, char**)
{
- int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
- 36, 37, 38, 39, 40};
- const std::size_t N1 = sizeof(a)/sizeof(a[0]);
- std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
- 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
- const std::size_t S = sizeof(s)/sizeof(s[0]);
- std::valarray<int> v1(a, N1);
- std::valarray<std::size_t> ia(s, S);
- std::valarray<int> v(24);
- v = v1[ia];
- assert(v.size() == 24);
- assert(v[ 0] == 3);
- assert(v[ 1] == 4);
- assert(v[ 2] == 5);
- assert(v[ 3] == 7);
- assert(v[ 4] == 8);
- assert(v[ 5] == 9);
- assert(v[ 6] == 11);
- assert(v[ 7] == 12);
- assert(v[ 8] == 13);
- assert(v[ 9] == 15);
- assert(v[10] == 16);
- assert(v[11] == 17);
- assert(v[12] == 22);
- assert(v[13] == 23);
- assert(v[14] == 24);
- assert(v[15] == 26);
- assert(v[16] == 27);
- assert(v[17] == 28);
- assert(v[18] == 30);
- assert(v[19] == 31);
- assert(v[20] == 32);
- assert(v[21] == 34);
- assert(v[22] == 35);
- assert(v[23] == 36);
-
+ {
+ int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
+ 36, 37, 38, 39, 40};
+ const std::size_t N1 = sizeof(a)/sizeof(a[0]);
+ std::size_t s[] = { 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17,
+ 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36};
+ const std::size_t S = sizeof(s)/sizeof(s[0]);
+ std::valarray<int> v1(a, N1);
+ std::valarray<std::size_t> ia(s, S);
+ std::valarray<int> v(24);
+ v = v1[ia];
+ assert(v.size() == 24);
+ assert(v[ 0] == 3);
+ assert(v[ 1] == 4);
+ assert(v[ 2] == 5);
+ assert(v[ 3] == 7);
+ assert(v[ 4] == 8);
+ assert(v[ 5] == 9);
+ assert(v[ 6] == 11);
+ assert(v[ 7] == 12);
+ assert(v[ 8] == 13);
+ assert(v[ 9] == 15);
+ assert(v[10] == 16);
+ assert(v[11] == 17);
+ assert(v[12] == 22);
+ assert(v[13] == 23);
+ assert(v[14] == 24);
+ assert(v[15] == 26);
+ assert(v[16] == 27);
+ assert(v[17] == 28);
+ assert(v[18] == 30);
+ assert(v[19] == 31);
+ assert(v[20] == 32);
+ assert(v[21] == 34);
+ assert(v[22] == 35);
+ assert(v[23] == 36);
+ }
+ {
+ int raw_data[] = {0,1,2,3,4,5,6,7,8,9};
+ std::size_t idx_data[] = {0,2,4,6,8};
+ std::valarray<int> data(raw_data, sizeof(raw_data)/sizeof(raw_data[0]));
+ std::valarray<std::size_t> idx(idx_data, sizeof(idx_data)/sizeof(idx_data[0]));
+ std::valarray<int> result = (data + 0)[idx];
+ assert(result.size() == 5);
+ assert(result[0] == data[idx[0]]);
+ assert(result[1] == data[idx[1]]);
+ assert(result[2] == data[idx[2]]);
+ assert(result[3] == data[idx[3]]);
+ assert(result[4] == data[idx[4]]);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,15 +17,24 @@
int main(int, char**)
{
- int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
- std::valarray<int> v2 = v1[std::slice(1, 5, 3)];
- assert(v2.size() == 5);
- assert(v2[0] == 1);
- assert(v2[1] == 4);
- assert(v2[2] == 7);
- assert(v2[3] == 10);
- assert(v2[4] == 13);
-
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
+ std::valarray<int> v2 = v1[std::slice(1, 5, 3)];
+ assert(v2.size() == 5);
+ assert(v2[0] == 1);
+ assert(v2[1] == 4);
+ assert(v2[2] == 7);
+ assert(v2[3] == 10);
+ assert(v2[4] == 13);
+ }
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
+ std::valarray<int> v2 = (v1 + 0)[std::slice(0, 2, 3)];
+ assert(v2.size() == 2);
+ assert(v2[0] == 0);
+ assert(v2[1] == 3);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/slice_non_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,28 +17,38 @@
int main(int, char**)
{
- int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- int a2[] = {-1, -2, -3, -4, -5};
- std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
- std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
- v1[std::slice(1, 5, 3)] = v2;
- assert(v1.size() == 16);
- assert(v1[ 0] == 0);
- assert(v1[ 1] == -1);
- assert(v1[ 2] == 2);
- assert(v1[ 3] == 3);
- assert(v1[ 4] == -2);
- assert(v1[ 5] == 5);
- assert(v1[ 6] == 6);
- assert(v1[ 7] == -3);
- assert(v1[ 8] == 8);
- assert(v1[ 9] == 9);
- assert(v1[10] == -4);
- assert(v1[11] == 11);
- assert(v1[12] == 12);
- assert(v1[13] == -5);
- assert(v1[14] == 14);
- assert(v1[15] == 15);
-
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ int a2[] = {-1, -2, -3, -4, -5};
+ std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
+ std::valarray<int> v2(a2, sizeof(a2)/sizeof(a2[0]));
+ v1[std::slice(1, 5, 3)] = v2;
+ assert(v1.size() == 16);
+ assert(v1[ 0] == 0);
+ assert(v1[ 1] == -1);
+ assert(v1[ 2] == 2);
+ assert(v1[ 3] == 3);
+ assert(v1[ 4] == -2);
+ assert(v1[ 5] == 5);
+ assert(v1[ 6] == 6);
+ assert(v1[ 7] == -3);
+ assert(v1[ 8] == 8);
+ assert(v1[ 9] == 9);
+ assert(v1[10] == -4);
+ assert(v1[11] == 11);
+ assert(v1[12] == 12);
+ assert(v1[13] == -5);
+ assert(v1[14] == 14);
+ assert(v1[15] == 15);
+ }
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5};
+ std::valarray<int> v1(a1, sizeof(a1)/sizeof(a1[0]));
+ std::valarray<int> v2((v1 + 0)[std::slice(0, 3, 2)]);
+ assert(v2.size() == 3);
+ assert(v2[0] == 0);
+ assert(v2[1] == 2);
+ assert(v2[2] == 4);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -15,8 +15,10 @@
#include <valarray>
#include <cassert>
+
int main(int, char**)
{
+ {
int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
bool b[N1] = {true, false, false, true, true, false,
@@ -30,6 +32,21 @@ int main(int, char**)
assert(v2[ 2] == 4);
assert(v2[ 3] == 7);
assert(v2[ 4] == 11);
-
+ }
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
+ bool b[N1] = {true, false, false, true, true, false,
+ false, true, false, false, false, true};
+ std::valarray<int> v1(a1, N1);
+ std::valarray<bool> vb(b, N1);
+ std::valarray<int> v2((v1 - 1)[vb]);
+ assert(v2.size() == 5);
+ assert(v2[ 0] == -1);
+ assert(v2[ 1] == 2);
+ assert(v2[ 2] == 3);
+ assert(v2[ 3] == 6);
+ assert(v2[ 4] == 10);
+ }
return 0;
}
Modified: libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp?rev=357453&r1=357452&r2=357453&view=diff
==============================================================================
--- libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp (original)
+++ libcxx/trunk/test/std/numerics/numarray/template.valarray/valarray.sub/valarray_bool_non_const.pass.cpp Tue Apr 2 01:05:23 2019
@@ -17,20 +17,37 @@
int main(int, char**)
{
- int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
- bool b[N1] = {true, false, false, true, true, false,
- false, true, false, false, false, true};
- std::valarray<int> v1(a1, N1);
- std::valarray<bool> vb(b, N1);
- std::valarray<int> v2(5);
- v2 = v1[vb];
- assert(v2.size() == 5);
- assert(v2[ 0] == 0);
- assert(v2[ 1] == 3);
- assert(v2[ 2] == 4);
- assert(v2[ 3] == 7);
- assert(v2[ 4] == 11);
-
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
+ bool b[N1] = {true, false, false, true, true, false,
+ false, true, false, false, false, true};
+ std::valarray<int> v1(a1, N1);
+ std::valarray<bool> vb(b, N1);
+ std::valarray<int> v2(5);
+ v2 = v1[vb];
+ assert(v2.size() == 5);
+ assert(v2[ 0] == 0);
+ assert(v2[ 1] == 3);
+ assert(v2[ 2] == 4);
+ assert(v2[ 3] == 7);
+ assert(v2[ 4] == 11);
+ }
+ {
+ int a1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ const std::size_t N1 = sizeof(a1)/sizeof(a1[0]);
+ bool b[N1] = {true, false, false, true, true, false,
+ false, true, false, false, false, true};
+ std::valarray<int> v1(a1, N1);
+ std::valarray<bool> vb(b, N1);
+ std::valarray<int> v2(5);
+ v2 = (v1 + 0)[vb];
+ assert(v2.size() == 5);
+ assert(v2[ 0] == 0);
+ assert(v2[ 1] == 3);
+ assert(v2[ 2] == 4);
+ assert(v2[ 3] == 7);
+ assert(v2[ 4] == 11);
+ }
return 0;
}
More information about the libcxx-commits
mailing list