Add exp, mod, acos, acosd, conj, norm and unittest.
This commit is contained in:
@@ -647,3 +647,156 @@ TEST_F(Function1D_Cuda_Test, compareSet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, exp)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::exp(hostMatrix);
|
||||
auto result2 = Aurora::exp(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
|
||||
hostMatrix = Aurora::Matrix::fromRawData(new float[12]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10,11,12}, 3, 2, 1,Aurora::Complex);
|
||||
deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
result1 = Aurora::exp(hostMatrix);
|
||||
result2 = Aurora::exp(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, mod)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::mod(hostMatrix, 2);
|
||||
auto result2 = Aurora::mod(deviceMatrix, 2).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
|
||||
result1 = Aurora::mod(hostMatrix, 3);
|
||||
result2 = Aurora::mod(deviceMatrix, 3).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, acos)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::acos(hostMatrix);
|
||||
auto result2 = Aurora::acos(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, acosd)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::acosd(hostMatrix);
|
||||
auto result2 = Aurora::acosd(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, conj)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::conj(hostMatrix);
|
||||
auto result2 = Aurora::conj(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
|
||||
hostMatrix = Aurora::Matrix::fromRawData(new float[12]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10,11,12}, 3, 2, 1,Aurora::Complex);
|
||||
deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
result1 = Aurora::conj(hostMatrix);
|
||||
result2 = Aurora::conj(deviceMatrix).toHostMatrix();
|
||||
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
||||
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
||||
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, norm) {
|
||||
//1Dim
|
||||
float *data = new float[3]{1,2,-3};
|
||||
auto matrix = Aurora::Matrix::fromRawData(data, 3);
|
||||
auto deviceMatrix = matrix.toDeviceMatrix();
|
||||
auto result = Aurora::norm(matrix.toDeviceMatrix(), Aurora::NormMethod::Norm1);
|
||||
EXPECT_FLOAT_AE(result,6);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm2);
|
||||
EXPECT_FLOAT_AE(result,3.74166);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::NormF);
|
||||
EXPECT_FLOAT_AE(result,3.74166);
|
||||
|
||||
//2Dims
|
||||
data = new float[8]{1,2,-3,6,7,9,22.3,-8.6};
|
||||
matrix = Aurora::Matrix::fromRawData(data, 4,2);
|
||||
deviceMatrix = matrix.toDeviceMatrix();
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm1);
|
||||
EXPECT_FLOAT_AE(result,46.9);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm2);
|
||||
EXPECT_FLOAT_AE(result,26.7284);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::NormF);
|
||||
EXPECT_FLOAT_AE(result,27.4089);
|
||||
|
||||
//1Dim Complex
|
||||
data = new float[6]{1,2,-3,4,5,-6};
|
||||
matrix = Aurora::Matrix::fromRawData(data, 3,1,1,Aurora::Complex);
|
||||
deviceMatrix = matrix.toDeviceMatrix();
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm1);
|
||||
EXPECT_FLOAT_AE(result,15.0463);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm2);
|
||||
EXPECT_FLOAT_AE(result,9.5394);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::NormF);
|
||||
EXPECT_FLOAT_AE(result,9.5394);
|
||||
|
||||
//2Dims Complex
|
||||
data = new float[12]{1,2,-3,4,5,-6,7,8,9,22,24,25};
|
||||
matrix = Aurora::Matrix::fromRawData(data, 3,2,1,Aurora::Complex);
|
||||
deviceMatrix = matrix.toDeviceMatrix();
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::Norm1);
|
||||
EXPECT_FLOAT_AE(result,69.0553);
|
||||
//not support
|
||||
//result = Aurora::norm(matrix,Aurora::NormMethod::Norm2);
|
||||
//EXPECT_FLOAT_AE(result,43.5314);
|
||||
result = Aurora::norm(deviceMatrix,Aurora::NormMethod::NormF);
|
||||
EXPECT_FLOAT_AE(result,44.3847);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user