Add cuda reshape, xcorr and unittest.

This commit is contained in:
sunwen
2023-12-04 17:35:01 +08:00
parent 09d9e52eb0
commit 00a21a37ef
3 changed files with 96 additions and 1 deletions

View File

@@ -1065,3 +1065,41 @@ TEST_F(Function1D_Cuda_Test, intersect) {
EXPECT_FLOAT_AE(iaHost.getData()[1],3);
EXPECT_FLOAT_AE(iaHost.getData()[2],9);
}
TEST_F(Function1D_Cuda_Test, reshape) {
float* data = new float[9]{3,3,2,2,2,1,4,4,7};
auto matrixHost = Aurora::Matrix::fromRawData(data, 9,1,1);
auto matrixDevice = matrixHost.toDeviceMatrix();
auto result = Aurora::reshape(matrixDevice,3,3,1);
EXPECT_FLOAT_AE(result.getDimSize(0),3);
EXPECT_FLOAT_AE(result.getDimSize(1),3);
EXPECT_FLOAT_AE(result.getDimSize(2),1);
result = Aurora::reshape(matrixDevice,3,1,3);
EXPECT_FLOAT_AE(result.getDimSize(0),3);
EXPECT_FLOAT_AE(result.getDimSize(1),1);
EXPECT_FLOAT_AE(result.getDimSize(2),3);
result = Aurora::reshape(matrixDevice,1,3,3);
EXPECT_FLOAT_AE(result.getDimSize(0),1);
EXPECT_FLOAT_AE(result.getDimSize(1),3);
EXPECT_FLOAT_AE(result.getDimSize(2),3);
auto resultHost = result.toHostMatrix();
for(int i=0; i<9; ++i)
{
EXPECT_FLOAT_AE(resultHost[i], data[i]);
}
}
TEST_F(Function1D_Cuda_Test, xcorr) {
auto matrixHost1 = Aurora::Matrix::fromRawData(new float[4]{7,8,9,10}, 4,1,1);
auto matrixHost2 = Aurora::Matrix::fromRawData(new float[4]{2,3,6,7}, 4,1,1);
auto matrixDevice1 = matrixHost1.toDeviceMatrix();
auto matrixDevice2 = matrixHost2.toDeviceMatrix();
auto result = Aurora::xcorr(matrixDevice1,matrixDevice2).toHostMatrix();
EXPECT_FLOAT_AE(result[0], 49);
EXPECT_FLOAT_AE(result[1], 98);
EXPECT_FLOAT_AE(result[2], 132);
EXPECT_FLOAT_AE(result[3], 162);
EXPECT_FLOAT_AE(result[4], 103);
EXPECT_FLOAT_AE(result[5], 48);
EXPECT_FLOAT_AE(result[6], 20);
}