Add deleteColumn and createCudaVectorMatrix.
This commit is contained in:
@@ -1433,3 +1433,50 @@ CudaMatrix Aurora::xcorr(const CudaMatrix& aMatrix1, const CudaMatrix& aMatrix2)
|
||||
|
||||
return CudaMatrix::fromRawData(data, size);
|
||||
}
|
||||
|
||||
CudaMatrix Aurora::deleteColumn(const CudaMatrix& aMatrix, int aColumnIndex)
|
||||
{
|
||||
int rows = aMatrix.getDimSize(0);
|
||||
int columns = aMatrix.getDimSize(1);
|
||||
if (aColumnIndex < 0 || aColumnIndex >= columns)
|
||||
{
|
||||
return aMatrix;
|
||||
}
|
||||
|
||||
float* resultData = nullptr;
|
||||
cudaMalloc((void**)&resultData, sizeof(float) * rows* (columns-1));
|
||||
if(aColumnIndex == 0)
|
||||
{
|
||||
cudaMemcpy(resultData, aMatrix.getData() + rows, sizeof(float) * rows* (columns-1), cudaMemcpyDeviceToDevice);
|
||||
}
|
||||
else if(aColumnIndex == (columns - 1))
|
||||
{
|
||||
cblas_scopy(rows* (columns-1), aMatrix.getData(), 1, resultData, 1);
|
||||
cudaMemcpy(resultData, aMatrix.getData(), sizeof(float) * rows* (columns-1), cudaMemcpyDeviceToDevice);
|
||||
}
|
||||
else
|
||||
{
|
||||
cudaMemcpy(resultData, aMatrix.getData(), sizeof(float) * rows * aColumnIndex, cudaMemcpyDeviceToDevice);
|
||||
cudaMemcpy(resultData + rows * aColumnIndex, aMatrix.getData() + rows * (aColumnIndex + 1), sizeof(float) * rows * (columns - aColumnIndex - 1), cudaMemcpyDeviceToDevice);
|
||||
}
|
||||
|
||||
return CudaMatrix::fromRawData(resultData, rows, columns-1);
|
||||
}
|
||||
|
||||
CudaMatrix Aurora::createCudaVectorMatrix(float aStartValue, float aStepValue, float aEndValue)
|
||||
{
|
||||
std::vector<float> matrixData;
|
||||
float tempValue = aStartValue;
|
||||
matrixData.push_back(tempValue);
|
||||
long long compare1 = std::round(aEndValue * 10e13);
|
||||
long long compare2 = std::round(tempValue * 10e13);
|
||||
while(std::round(tempValue* 10e13) <= compare1)
|
||||
{
|
||||
tempValue += aStepValue;
|
||||
matrixData.push_back(tempValue);
|
||||
compare2 = std::round(tempValue * 10e14);
|
||||
}
|
||||
matrixData.pop_back();
|
||||
|
||||
return Matrix::copyFromRawData(matrixData.data(), 1, matrixData.size()).toDeviceMatrix();
|
||||
}
|
||||
|
||||
@@ -83,6 +83,10 @@ namespace Aurora
|
||||
|
||||
CudaMatrix xcorr(const CudaMatrix& aMatrix1, const CudaMatrix& aMatrix2);
|
||||
|
||||
CudaMatrix deleteColumn(const CudaMatrix& aMatrix, int aColumnIndex);
|
||||
|
||||
CudaMatrix createCudaVectorMatrix(float aStartValue, float aStepValue, float aEndValue);
|
||||
|
||||
/**
|
||||
* 将所有nan值设置为特定值
|
||||
* @attention 直接在原数据上进行修改!
|
||||
|
||||
@@ -1103,3 +1103,21 @@ TEST_F(Function1D_Cuda_Test, xcorr) {
|
||||
EXPECT_FLOAT_AE(result[5], 48);
|
||||
EXPECT_FLOAT_AE(result[6], 20);
|
||||
}
|
||||
|
||||
TEST_F(Function1D_Cuda_Test, deleteColumn) {
|
||||
auto matrixHost = Aurora::Matrix::fromRawData(new float[100], 10,10,1);
|
||||
for(int i=0;i<100;++i)
|
||||
{
|
||||
matrixHost[i] = i;
|
||||
}
|
||||
auto matrixDevice = matrixHost.toDeviceMatrix();
|
||||
auto result1 = Aurora::deleteColumn(matrixHost, 26);
|
||||
auto result2 = Aurora::deleteColumn(matrixDevice, 26).toHostMatrix();
|
||||
EXPECT_FLOAT_AE(result1.getDimSize(0),result2.getDimSize(0));
|
||||
EXPECT_FLOAT_AE(result1.getDimSize(1),result2.getDimSize(1));
|
||||
EXPECT_FLOAT_AE(result1.getDataSize(),result2.getDataSize());
|
||||
for(int i=0;i<result1.getDataSize();++i)
|
||||
{
|
||||
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user