mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Resolve merge.
This commit is contained in:
@@ -112,6 +112,10 @@ ei_add_test(kronecker_product)
|
||||
|
||||
# TODO: The following test names are prefixed with the cxx11 string, since historically
|
||||
# the tests depended on c++11. This isn't the case anymore so we ought to rename them.
|
||||
# FIXME: Old versions of MSVC fail to compile this code, so we just disable these tests
|
||||
# when using visual studio. We should make the check more strict to enable the tests for
|
||||
# newer versions of MSVC.
|
||||
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
ei_add_test(cxx11_float16)
|
||||
ei_add_test(cxx11_tensor_dimension)
|
||||
ei_add_test(cxx11_tensor_map)
|
||||
@@ -130,7 +134,8 @@ ei_add_test(cxx11_tensor_io)
|
||||
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
|
||||
# This test requires __uint128_t which is only available on 64bit systems
|
||||
ei_add_test(cxx11_tensor_uint128)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(EIGEN_TEST_CXX11)
|
||||
# It should be safe to always run these tests as there is some fallback code for
|
||||
|
||||
@@ -1019,6 +1019,153 @@ void test_cuda_erfc(const Scalar stddev)
|
||||
cudaFree(d_out);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
void test_cuda_betainc()
|
||||
{
|
||||
Tensor<Scalar, 1> in_x(125);
|
||||
Tensor<Scalar, 1> in_a(125);
|
||||
Tensor<Scalar, 1> in_b(125);
|
||||
Tensor<Scalar, 1> out(125);
|
||||
Tensor<Scalar, 1> expected_out(125);
|
||||
out.setZero();
|
||||
|
||||
Scalar nan = std::numeric_limits<Scalar>::quiet_NaN();
|
||||
|
||||
Array<Scalar, 1, Dynamic> x(125);
|
||||
Array<Scalar, 1, Dynamic> a(125);
|
||||
Array<Scalar, 1, Dynamic> b(125);
|
||||
Array<Scalar, 1, Dynamic> v(125);
|
||||
|
||||
a << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999,
|
||||
0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999,
|
||||
0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 0.999, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999, 999.999, 999.999, 999.999, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999, 999.999, 999.999, 999.999, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999, 999.999, 999.999, 999.999, 999.999;
|
||||
|
||||
b << 0.0, 0.0, 0.0, 0.0, 0.0, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379, 0.999,
|
||||
0.999, 0.999, 0.999, 0.999, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999, 0.0, 0.0, 0.0, 0.0, 0.0, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.999, 0.999, 0.999, 0.999, 0.999, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 999.999, 999.999, 999.999, 999.999, 999.999, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379, 0.999,
|
||||
0.999, 0.999, 0.999, 0.999, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999, 0.0, 0.0, 0.0, 0.0, 0.0, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.999, 0.999, 0.999, 0.999, 0.999, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 999.999, 999.999, 999.999, 999.999, 999.999, 0.0, 0.0,
|
||||
0.0, 0.0, 0.0, 0.03062277660168379, 0.03062277660168379,
|
||||
0.03062277660168379, 0.03062277660168379, 0.03062277660168379, 0.999,
|
||||
0.999, 0.999, 0.999, 0.999, 31.62177660168379, 31.62177660168379,
|
||||
31.62177660168379, 31.62177660168379, 31.62177660168379, 999.999, 999.999,
|
||||
999.999, 999.999, 999.999;
|
||||
|
||||
x << -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8,
|
||||
1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5,
|
||||
0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2,
|
||||
0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1,
|
||||
0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1,
|
||||
-0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8,
|
||||
1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5,
|
||||
0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2,
|
||||
0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1, -0.1, 0.2, 0.5, 0.8, 1.1;
|
||||
|
||||
v << nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
|
||||
nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
|
||||
nan, nan, 0.47972119876364683, 0.5, 0.5202788012363533, nan, nan,
|
||||
0.9518683957740043, 0.9789663010413743, 0.9931729188073435, nan, nan,
|
||||
0.999995949033062, 0.9999999999993698, 0.9999999999999999, nan, nan,
|
||||
0.9999999999999999, 0.9999999999999999, 0.9999999999999999, nan, nan, nan,
|
||||
nan, nan, nan, nan, 0.006827081192655869, 0.0210336989586256,
|
||||
0.04813160422599567, nan, nan, 0.20014344256217678, 0.5000000000000001,
|
||||
0.7998565574378232, nan, nan, 0.9991401428435834, 0.999999999698403,
|
||||
0.9999999999999999, nan, nan, 0.9999999999999999, 0.9999999999999999,
|
||||
0.9999999999999999, nan, nan, nan, nan, nan, nan, nan,
|
||||
1.0646600232370887e-25, 6.301722877826246e-13, 4.050966937974938e-06, nan,
|
||||
nan, 7.864342668429763e-23, 3.015969667594166e-10, 0.0008598571564165444,
|
||||
nan, nan, 6.031987710123844e-08, 0.5000000000000007, 0.9999999396801229,
|
||||
nan, nan, 0.9999999999999999, 0.9999999999999999, 0.9999999999999999, nan,
|
||||
nan, nan, nan, nan, nan, nan, 0.0, 7.029920380986636e-306,
|
||||
2.2450728208591345e-101, nan, nan, 0.0, 9.275871147869727e-302,
|
||||
1.2232913026152827e-97, nan, nan, 0.0, 3.0891393081932924e-252,
|
||||
2.9303043666183996e-60, nan, nan, 2.248913486879199e-196,
|
||||
0.5000000000004947, 0.9999999999999999, nan;
|
||||
|
||||
for (int i = 0; i < 125; ++i) {
|
||||
in_x(i) = x(i);
|
||||
in_a(i) = a(i);
|
||||
in_b(i) = b(i);
|
||||
expected_out(i) = v(i);
|
||||
}
|
||||
|
||||
std::size_t bytes = in_x.size() * sizeof(Scalar);
|
||||
|
||||
Scalar* d_in_x;
|
||||
Scalar* d_in_a;
|
||||
Scalar* d_in_b;
|
||||
Scalar* d_out;
|
||||
cudaMalloc((void**)(&d_in_x), bytes);
|
||||
cudaMalloc((void**)(&d_in_a), bytes);
|
||||
cudaMalloc((void**)(&d_in_b), bytes);
|
||||
cudaMalloc((void**)(&d_out), bytes);
|
||||
|
||||
cudaMemcpy(d_in_x, in_x.data(), bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_in_a, in_a.data(), bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_in_b, in_b.data(), bytes, cudaMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<Scalar, 1> > gpu_in_x(d_in_x, 125);
|
||||
Eigen::TensorMap<Eigen::Tensor<Scalar, 1> > gpu_in_a(d_in_a, 125);
|
||||
Eigen::TensorMap<Eigen::Tensor<Scalar, 1> > gpu_in_b(d_in_b, 125);
|
||||
Eigen::TensorMap<Eigen::Tensor<Scalar, 1> > gpu_out(d_out, 125);
|
||||
|
||||
gpu_out.device(gpu_device) = betainc(gpu_in_a, gpu_in_b, gpu_in_x);
|
||||
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
|
||||
for (int i = 1; i < 125; ++i) {
|
||||
if ((std::isnan)(expected_out(i))) {
|
||||
VERIFY((std::isnan)(out(i)));
|
||||
} else {
|
||||
VERIFY_IS_APPROX(out(i), expected_out(i));
|
||||
}
|
||||
}
|
||||
|
||||
cudaFree(d_in_x);
|
||||
cudaFree(d_in_a);
|
||||
cudaFree(d_in_b);
|
||||
cudaFree(d_out);
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_cuda()
|
||||
{
|
||||
CALL_SUBTEST_1(test_cuda_elementwise_small());
|
||||
@@ -1086,5 +1233,8 @@ void test_cxx11_tensor_cuda()
|
||||
|
||||
CALL_SUBTEST_5(test_cuda_igamma<double>());
|
||||
CALL_SUBTEST_5(test_cuda_igammac<double>());
|
||||
|
||||
CALL_SUBTEST_6(test_cuda_betainc<float>());
|
||||
CALL_SUBTEST_6(test_cuda_betainc<double>());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -13,6 +13,20 @@
|
||||
#include <Eigen/CXX11/Tensor>
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_output_0d()
|
||||
{
|
||||
Tensor<int, 0, DataLayout> tensor;
|
||||
tensor() = 123;
|
||||
|
||||
std::stringstream os;
|
||||
os << tensor;
|
||||
|
||||
std::string expected("123");
|
||||
VERIFY_IS_EQUAL(std::string(os.str()), expected);
|
||||
}
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
static void test_output_1d()
|
||||
{
|
||||
@@ -26,6 +40,12 @@ static void test_output_1d()
|
||||
|
||||
std::string expected("0\n1\n2\n3\n4");
|
||||
VERIFY_IS_EQUAL(std::string(os.str()), expected);
|
||||
|
||||
Eigen::Tensor<double,1,DataLayout> empty_tensor(0);
|
||||
std::stringstream empty_os;
|
||||
empty_os << empty_tensor;
|
||||
std::string empty_string;
|
||||
VERIFY_IS_EQUAL(std::string(empty_os.str()), empty_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +121,8 @@ static void test_output_const()
|
||||
|
||||
void test_cxx11_tensor_io()
|
||||
{
|
||||
CALL_SUBTEST(test_output_0d<ColMajor>());
|
||||
CALL_SUBTEST(test_output_0d<RowMajor>());
|
||||
CALL_SUBTEST(test_output_1d<ColMajor>());
|
||||
CALL_SUBTEST(test_output_1d<RowMajor>());
|
||||
CALL_SUBTEST(test_output_2d<ColMajor>());
|
||||
|
||||
@@ -38,6 +38,30 @@ static void test_1d_scan()
|
||||
}
|
||||
}
|
||||
|
||||
template <int DataLayout, typename Type=float>
|
||||
static void test_1d_inclusive_scan()
|
||||
{
|
||||
int size = 50;
|
||||
Tensor<Type, 1, DataLayout> tensor(size);
|
||||
tensor.setRandom();
|
||||
Tensor<Type, 1, DataLayout> result = tensor.cumsum(0, true);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor.dimension(0), result.dimension(0));
|
||||
|
||||
float accum = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
VERIFY_IS_EQUAL(result(i), accum);
|
||||
accum += tensor(i);
|
||||
}
|
||||
|
||||
accum = 1;
|
||||
result = tensor.cumprod(0, true);
|
||||
for (int i = 0; i < size; i++) {
|
||||
VERIFY_IS_EQUAL(result(i), accum);
|
||||
accum *= tensor(i);
|
||||
}
|
||||
}
|
||||
|
||||
template <int DataLayout, typename Type=float>
|
||||
static void test_4d_scan()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user