Speed up of removeDataFromArrays.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "Function2D.h"
|
||||
#include "Matrix.h"
|
||||
#include <cstddef>
|
||||
#include <mkl_cblas.h>
|
||||
#include <vector>
|
||||
|
||||
using namespace Recon;
|
||||
@@ -11,36 +12,41 @@ using namespace Aurora;
|
||||
|
||||
Aurora::Matrix Recon::removeDataFromArrays(const Aurora::Matrix& aOutPutMatrix, const Aurora::Matrix& aRemoveList)
|
||||
{
|
||||
Matrix result = aOutPutMatrix;
|
||||
int minusNum = 0;
|
||||
for(int i=0; i<aRemoveList.getDataSize(); ++i)
|
||||
size_t columnSize = sum(aRemoveList, FunctionDirection::All)[0];
|
||||
size_t rowSize = aOutPutMatrix.getDimSize(0);
|
||||
double* resultData = Aurora::malloc(columnSize * rowSize);
|
||||
Matrix result = Matrix::New(resultData, rowSize, columnSize);
|
||||
std::vector<std::pair<int,size_t>> copyList;
|
||||
size_t length = 0;
|
||||
int end = 0;
|
||||
for(size_t i=0; i<aRemoveList.getDataSize(); ++i)
|
||||
{
|
||||
if(aRemoveList[i] == 0)
|
||||
if(aRemoveList[i] == 1)
|
||||
{
|
||||
result = deleteColumn(result, i - minusNum);
|
||||
++minusNum;
|
||||
}
|
||||
end = i;
|
||||
++length;
|
||||
}
|
||||
|
||||
if(aRemoveList[i] == 0 && length != 0)
|
||||
{
|
||||
copyList.push_back({end - length + 1, length});
|
||||
length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (length != 0)
|
||||
{
|
||||
copyList.push_back({end - length + 1, length});
|
||||
}
|
||||
|
||||
double* start = aOutPutMatrix.getData();
|
||||
#pragma omp parallel for
|
||||
for(size_t i=0; i<copyList.size(); ++i)
|
||||
{
|
||||
size_t copyLength = copyList[i].second * rowSize;
|
||||
cblas_dcopy(copyLength, start + copyList[i].first * rowSize, 1, resultData, 1);
|
||||
resultData += copyLength;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
// size_t columnSize = sum(aRemoveList, FunctionDirection::All)[0];
|
||||
// double* resultData = Aurora::malloc(columnSize * aOutPutMatrix.getDimSize(0));
|
||||
// Matrix result = Matrix::New(resultData, aOutPutMatrix.getDimSize(0), columnSize);
|
||||
// std::vector<std::pair<int,int>> copyList;
|
||||
// size_t length = 0;
|
||||
// for(size_t i=0; i<aRemoveList.getDataSize(); ++i)
|
||||
// {
|
||||
// if(aRemoveList[i] == 1)
|
||||
// {
|
||||
// ++length;
|
||||
// }
|
||||
|
||||
// if(aRemoveList[i] == 0 && length != 0)
|
||||
// {
|
||||
// copyList.push_back({});
|
||||
// length = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user