Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T>
// class valarray
// {
// public:
// typedef T value_type;
// ...
#include <valarray>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::valarray<int>::value_type, int>::value), "");
static_assert((std::is_same<std::valarray<double>::value_type, double>::value), "");
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type& operator[](size_t i);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {5, 4, 3, 2, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
for (int i = 0; i < N; ++i)
{
assert(v[i] == a[i]);
v[i] = i;
assert(v[i] == i);
}
}
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// const value_type& operator[](size_t i) const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {5, 4, 3, 2, 1};
const unsigned N = sizeof(a)/sizeof(a[0]);
const std::valarray<T> v(a, N);
for (int i = 0; i < N; ++i)
{
assert(v[i] == a[i]);
}
}
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2(a, N-2);
v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == v[i][j]);
}
}
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const gslice_array<value_type>& ga);
#include <valarray>
#include <cassert>
int main()
{
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(24);
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);
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const indirect_array<value_type>& ia);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(initializer_list<value_type> il);
#include <valarray>
#include <cassert>
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2;
v2 = {1, 2, 3, 4, 5};
assert(v2.size() == N);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2;
v2 = {1, 2.5, 3, 4.25, 5};
assert(v2.size() == N);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v2(a, N-2);
v2 = {T(1), T(2), T(3), T(4), T(5)};
assert(v2.size() == N);
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (int j = 0; j < a[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const mask_array<value_type>& ma);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(valarray&& v);
#include <valarray>
#include <cassert>
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2;
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2(a, N-2);
v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (int j = 0; j < a[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const slice_array<value_type>& sa);
#include <valarray>
#include <cassert>
int main()
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::valarray<int> v(5);
v = v1[std::slice(1, 5, 3)];
assert(v.size() == 5);
assert(v[0] == 1);
assert(v[1] == 4);
assert(v[2] == 7);
assert(v[3] == 10);
assert(v[4] == 13);
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
v = 7;
assert(v.size() == N);
for (int i = 0; i < v.size(); ++i)
assert(v[i] == 7);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator&=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {0, 2, 0, 0, 0};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 &= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator&=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 1, 2, 3, 0, 1};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 &= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator/=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {6, 14, 24, 36, 50};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 /= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator/=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 12, 18, 24, 30};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v2 /= 6;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator-=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 9, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 -= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator-=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = {-2, -1, 0, 1, 2};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 -= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator%=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {0, 1, 2, 1, 0};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v2 %= v1;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v2[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator%=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {1, 2, 0, 1, 2};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 %= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator|=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 7, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 |= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator|=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 3, 3, 3, 7, 7};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 |= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator+=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 9, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 += v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator+=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {4, 5, 6, 7, 8};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 += 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator<<=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 6, 7, 8, 9, 10};
T a3[] = {64, 256, 768, 2048, 5120};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 <<= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator<<=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 8, 16, 24, 32, 40};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 <<= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator>>=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 6, 7, 8, 9, 10};
T a3[] = {64, 256, 768, 2048, 5120};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v3 >>= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator>>=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 8, 16, 24, 32, 40};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v2 >>= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator*=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {6, 14, 24, 36, 50};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 *= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator*=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 12, 18, 24, 30};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 *= 6;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator^=(const valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10};
T a3[] = {7, 5, 11, 13, 15};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
std::valarray<T> v3(a3, N);
v1 ^= v2;
assert(v1.size() == v2.size());
assert(v1.size() == v3.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v3[i]);
}
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray& operator^=(const value_type& x);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = { 1, 2, 3, 4, 5};
T a2[] = { 2, 1, 0, 7, 6};
const unsigned N = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N);
std::valarray<T> v2(a2, N);
v1 ^= 3;
assert(v1.size() == v2.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2[i]);
}
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const valarray<value_type>& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = v;
assert(v2.size() == v.size());
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == v[i][j]);
}
}
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray();
#include <valarray>
#include <cassert>
int main()
{
{
std::valarray<int> v;
assert(v.size() == 0);
}
{
std::valarray<float> v;
assert(v.size() == 0);
}
{
std::valarray<double> v;
assert(v.size() == 0);
}
{
std::valarray<std::valarray<double> > v;
assert(v.size() == 0);
}
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const gslice_array<value_type>& sa);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const indirect_array<value_type>& ia);
#include <valarray>
#include <cassert>
int main()
{
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(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);
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(initializer_list<value_type>);
#include <valarray>
#include <cassert>
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v = {1, 2, 3, 4, 5};
assert(v.size() == N);
for (int i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v = {1, 2, 3, 4, 5};
assert(v.size() == N);
for (int i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const mask_array<value_type>& ma);
#include <valarray>
#include <cassert>
int main()
{
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[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);
}

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const valarray<value_type>& v);
#include <valarray>
#include <utility>
#include <cassert>
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = std::move(v);
assert(v2.size() == N);
assert(v.size() == 0);
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == a[i].size());
for (int j = 0; j < v2[i].size(); ++j)
assert(v2[i][j] == a[i][j]);
}
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const value_type* p, size_t n);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (int i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (int i = 0; i < N; ++i)
assert(v[i] == a[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
assert(v.size() == N);
for (int i = 0; i < N; ++i)
{
assert(v[i].size() == a[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v[i][j] == a[i][j]);
}
}
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// explicit valarray(size_t);
#include <valarray>
#include <cassert>
int main()
{
{
std::valarray<int> v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 0);
}
{
std::valarray<double> v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 0);
}
{
std::valarray<std::valarray<double> > v(100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i].size() == 0);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const slice_array<value_type>& sa);
#include <valarray>
#include <cassert>
int main()
{
int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
std::valarray<int> v1(a, sizeof(a)/sizeof(a[0]));
std::valarray<int> v(v1[std::slice(1, 5, 3)]);
assert(v.size() == 5);
assert(v[0] == 1);
assert(v[1] == 4);
assert(v[2] == 7);
assert(v[3] == 10);
assert(v[4] == 13);
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray(const value_type& x, size_t n);
#include <valarray>
#include <cassert>
int main()
{
{
std::valarray<int> v(5, 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 5);
}
{
std::valarray<double> v(2.5, 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i] == 2.5);
}
{
std::valarray<std::valarray<double> > v(std::valarray<double>(10), 100);
assert(v.size() == 100);
for (int i = 0; i < 100; ++i)
assert(v[i].size() == 10);
}
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray apply(value_type f(const value_type&)) const;
#include <valarray>
#include <cassert>
typedef int T;
T f(const T& t) {return t + 5;}
int main()
{
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
}
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1+v1).apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray apply(value_type f(value_type)) const;
#include <valarray>
#include <cassert>
typedef int T;
T f(T t) {return t + 5;}
int main()
{
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.apply(f);
assert(v2.size() == N1);
}
{
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {7, 9, 11, 13, 15, 17, 19, 21, 23, 25};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1+v1).apply(f);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
}

View File

@@ -0,0 +1,127 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray cshift(int i) const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(0);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(10);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(17);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 9, 10, 1, 2, 3, 4, 5, 6, 7};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-10);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {4, 5, 6, 7, 8, 9, 10, 1, 2, 3};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.cshift(-17);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.cshift(-17);
assert(v2.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 10, 12, 14, 16, 18, 20, 2, 4, 6};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).cshift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {16, 18, 20, 2, 4, 6, 8, 10, 12, 14};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).cshift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type max() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, -5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.max() == 4.0);
}
{
typedef double T;
std::valarray<T> v1;
v1.max();
}
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, -5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert((2*v1).max() == 8.0);
}
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type min() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.min() == -3.0);
}
{
typedef double T;
std::valarray<T> v1;
v1.min();
}
{
typedef double T;
T a1[] = {1.5, 2.5, -3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert((2*v1).min() == -6.0);
}
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// void resize(size_t n, value_type x = value_type());
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
v1.resize(8);
assert(v1.size() == 8);
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
v1.resize(0);
assert(v1.size() == 0);
v1.resize(80);
assert(v1.size() == 80);
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
v1.resize(40);
assert(v1.size() == 40);
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == 0);
}
}

View File

@@ -0,0 +1,127 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray shift(int i) const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(0);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(1);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(9);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(90);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-1);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-9);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = v1.shift(-90);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
std::valarray<T> v2 = v1.shift(-90);
assert(v2.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {8, 10, 12, 14, 16, 18, 20, 0, 0, 0};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).shift(3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
T a2[] = {0, 0, 0, 2, 4, 6, 8, 10, 12, 14};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2 = (v1 + v1).shift(-3);
assert(v2.size() == N1);
for (unsigned i = 0; i < N1; ++i)
assert(v2[i] == a2[i]);
}
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// size_t size() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.size() == N1);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = 0;
std::valarray<T> v1(a1, N1);
assert(v1.size() == N1);
}
{
typedef int T;
const unsigned N1 = 0;
std::valarray<T> v1;
assert(v1.size() == N1);
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// value_type sum() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef double T;
T a1[] = {1.5, 2.5, 3, 4, 5.5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
std::valarray<T> v1(a1, N1);
assert(v1.sum() == 16.5);
}
}

View File

@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// void swap(valarray& v);
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
T a2[] = {6, 7, 8, 9, 10, 11, 12};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
std::valarray<T> v1(a1, N1);
std::valarray<T> v2(a2, N2);
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
T a1[] = {1, 2, 3, 4, 5};
const unsigned N1 = sizeof(a1)/sizeof(a1[0]);
const unsigned N2 = 0;
std::valarray<T> v1(a1, N1);
std::valarray<T> v2;
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
T a2[] = {6, 7, 8, 9, 10, 11, 12};
const unsigned N1 = 0;
const unsigned N2 = sizeof(a2)/sizeof(a2[0]);
std::valarray<T> v1;
std::valarray<T> v2(a2, N2);
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
{
typedef int T;
const unsigned N1 = 0;
const unsigned N2 = 0;
std::valarray<T> v1;
std::valarray<T> v2;
std::valarray<T> v1_save = v1;
std::valarray<T> v2_save = v2;
v1.swap(v2);
assert(v1.size() == v2_save.size());
for (int i = 0; i < v1.size(); ++i)
assert(v1[i] == v2_save[i]);
assert(v2.size() == v1_save.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == v1_save[i]);
}
}

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// gslice_array<value_type> operator[](const gslice& gs);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const gslice& gs) const;
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const valarray<size_t>& vs) const;
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// indirect_array<value_type> operator[](const valarray<size_t>& vs);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](slice s) const;
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// slice_array<value_type> operator[](slice s);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator[](const valarray<bool>& vb) const;
#include <valarray>
#include <cassert>
int main()
{
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[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);
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// mask_array<value_type> operator[](const valarray<bool>& vb);
#include <valarray>
#include <cassert>
int main()
{
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);
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator~() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == ~v[i]);
}
{
typedef std::valarray<int> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~v;
assert(v2.size() == v.size());
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == ~v[i][j]);
}
}
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = ~(v + v);
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == ~(2*v[i]));
}
}

View File

@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator-() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == -v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == -v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -v;
assert(v2.size() == v.size());
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == -v[i][j]);
}
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = -(v + v);
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == -2*v[i]);
}
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray<bool> operator!() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<bool> v2 = !v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == !v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<bool> v2 = !(v + v);
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == !2*v[i]);
}
}

View File

@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <valarray>
// template<class T> class valarray;
// valarray operator+() const;
#include <valarray>
#include <cassert>
int main()
{
{
typedef int T;
T a[] = {1, 2, 3, 4, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == +v[i]);
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == +v[i]);
}
{
typedef std::valarray<double> T;
T a[] = {T(1), T(2), T(3), T(4), T(5)};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +v;
assert(v2.size() == v.size());
for (int i = 0; i < N; ++i)
{
assert(v2[i].size() == v[i].size());
for (int j = 0; j < v[i].size(); ++j)
assert(v2[i][j] == +v[i][j]);
}
}
{
typedef double T;
T a[] = {1, 2.5, 3, 4.25, 5};
const unsigned N = sizeof(a)/sizeof(a[0]);
std::valarray<T> v(a, N);
std::valarray<T> v2 = +(v + v);
assert(v2.size() == v.size());
for (int i = 0; i < v2.size(); ++i)
assert(v2[i] == +2*v[i]);
}
}