Add functions to 1D(nan, finite, padding, not)
This commit is contained in:
@@ -319,6 +319,84 @@ TEST_F(Function1D_Cuda_Test, log)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, nanAndFinite)
|
||||
{
|
||||
float n=std::nan("");
|
||||
float infinite=std::numeric_limits<float>::infinity();
|
||||
|
||||
float* data = new float[9]{infinite,3,n,2,2,1,4,4,7};
|
||||
auto matrix = Aurora::Matrix::fromRawData(data, 9,1,1).toDeviceMatrix();
|
||||
auto r = Aurora::isnan(matrix);
|
||||
EXPECT_FLOAT_EQ(r.getValue(0),0);
|
||||
EXPECT_FLOAT_EQ(r.getValue(1),0);
|
||||
EXPECT_FLOAT_EQ(r.getValue(2),1);
|
||||
|
||||
r = Aurora::isfinite(matrix);
|
||||
EXPECT_FLOAT_EQ(r.getValue(0),0);
|
||||
EXPECT_FLOAT_EQ(r.getValue(1),1);
|
||||
EXPECT_FLOAT_EQ(r.getValue(2),0);
|
||||
|
||||
Aurora::nantoval(matrix,1);
|
||||
EXPECT_FLOAT_EQ(matrix.getValue(2),1);
|
||||
|
||||
float* data2 = new float[1]{n};
|
||||
auto matrix2 = Aurora::Matrix::fromRawData(data2, 1,1,1).toDeviceMatrix();
|
||||
r = Aurora::isnan(matrix2);
|
||||
EXPECT_FLOAT_EQ(r.getValue(0),1);
|
||||
|
||||
r = Aurora::isfinite(matrix2);
|
||||
EXPECT_FLOAT_EQ(r.getValue(0),0);
|
||||
|
||||
Aurora::nantoval(matrix2,1);
|
||||
EXPECT_FLOAT_EQ(matrix2.getValue(0),1);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, isnanOrfinite)
|
||||
{
|
||||
float *input = new float[18]{10,2,1,3,4,4,16,3,1,2,15,-2,1,-3,4,-4,1,-3};
|
||||
auto ma = Aurora::Matrix::fromRawData(input,18,1,1).toDeviceMatrix();
|
||||
Aurora::padding(ma,20,1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(19),1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(20),1);
|
||||
Aurora::padding(ma,10,-1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(10),-1);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, padding)
|
||||
{
|
||||
float *input = new float[18]{10,2,1,3,4,4,16,3,1,2,15,-2,1,-3,4,-4,1,-3};
|
||||
auto ma = Aurora::Matrix::fromRawData(input,18,1,1).toDeviceMatrix();
|
||||
Aurora::padding(ma,20,1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(19),1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(20),1);
|
||||
Aurora::padding(ma,10,-1);
|
||||
EXPECT_FLOAT_AE(ma.getValue(10),-1);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, not)
|
||||
{
|
||||
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{-1.1,2.2,-3.3,0,-5.5,6.6,0.7,-0.8}, 2,4);
|
||||
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
||||
|
||||
auto result1 = Aurora::auroraNot(hostMatrix);
|
||||
auto result2 = Aurora::auroraNot(deviceMatrix);
|
||||
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.getValue(i));
|
||||
}
|
||||
|
||||
result1 = Aurora::auroraNot(hostMatrix);
|
||||
result2 = Aurora::auroraNot(hostMatrix.toDeviceMatrix());
|
||||
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.getValue(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, compareSet)
|
||||
{
|
||||
|
||||
@@ -560,8 +560,10 @@ TEST_F(Function1D_Test, padding) {
|
||||
float *input = new float[18]{10,2,1,3,4,4,16,3,1,2,15,-2,1,-3,4,-4,1,-3};
|
||||
auto ma = Aurora::Matrix::fromRawData(input,18,1,1);
|
||||
Aurora::padding(ma,20,1);
|
||||
auto result = ma.getData();
|
||||
|
||||
EXPECT_FLOAT_AE(ma[19],1);
|
||||
EXPECT_FLOAT_AE(ma[20],1);
|
||||
Aurora::padding(ma,10,-1);
|
||||
EXPECT_FLOAT_AE(ma[10],-1);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Test, convertfp16tofloat) {
|
||||
|
||||
Reference in New Issue
Block a user