Commit 01268aa3 authored by Oded Green's avatar Oded Green

Using std::vector instead of allocating memory myself

parent 801f118f
...@@ -87,7 +87,7 @@ private: ...@@ -87,7 +87,7 @@ private:
void iterateCombinations(Mat inputData,Mat outputData); void iterateCombinations(Mat inputData,Mat outputData);
void computeOneCombination(int comb_id, Mat inputData , Mat outputData, void computeOneCombination(int comb_id, Mat inputData , Mat outputData,
Mat outputVector,int* finalMatPosR, int* finalMatPosC); Mat outputVector,std::vector<int> finalMatPosR, std::vector<int> finalMatPosC);
inline void complexSubtract(std::complex<float>& src, std::complex<float>& dst){dst-=src;} inline void complexSubtract(std::complex<float>& src, std::complex<float>& dst){dst-=src;}
inline void complexAdd(std::complex<float>& src, std::complex<float>& dst){dst+=src;} inline void complexAdd(std::complex<float>& src, std::complex<float>& dst){dst+=src;}
...@@ -103,7 +103,8 @@ private: ...@@ -103,7 +103,8 @@ private:
int pc; int pc;
int threads; int threads;
Combination* combinationsTable; // Combination* combinationsTable;
std::vector<Combination> combinationsTable;
}; };
...@@ -120,12 +121,12 @@ EstimateCovariance::EstimateCovariance(int pr_, int pc_){ ...@@ -120,12 +121,12 @@ EstimateCovariance::EstimateCovariance(int pr_, int pc_){
} }
EstimateCovariance::~EstimateCovariance(){ EstimateCovariance::~EstimateCovariance(){
delete[] combinationsTable;
} }
void EstimateCovariance::initInternalDataStructures(){ void EstimateCovariance::initInternalDataStructures(){
int combCount = combinationCount(); int combCount = combinationCount();
combinationsTable = new Combination[combCount]; combinationsTable.resize(combCount);
buildCombinationsTable(); buildCombinationsTable();
} }
...@@ -203,26 +204,27 @@ void EstimateCovariance::iterateCombinations(Mat inputData,Mat outputData) ...@@ -203,26 +204,27 @@ void EstimateCovariance::iterateCombinations(Mat inputData,Mat outputData)
combs=combsPerCPU-1; combs=combsPerCPU-1;
startComb=remainder*combsPerCPU+(thread_id-remainder)*(combsPerCPU-1); startComb=remainder*combsPerCPU+(thread_id-remainder)*(combsPerCPU-1);
} }
// stopComb=startComb+combs;
Mat outputVector(pr*pc,1, DataType<std::complex<float> >::type); Mat outputVector(pr*pc,1, DataType<std::complex<float> >::type);
int* finalMatPosR = new int[pr*pc]; std::vector<int> finalMatPosR(pr*pc,0);
int* finalMatPosC = new int[pr*pc]; std::vector<int> finalMatPosC(pr*pc,0);
for (idx=0; idx<combs; idx++){ for (idx=0; idx<combs; idx++){
outputVector.setTo(Scalar(0,0)); outputVector.setTo(Scalar(0,0));
memset(finalMatPosR,0,pr*pc*sizeof(int)); for (unsigned x=0; x<finalMatPosR.size(); x++)
memset(finalMatPosC,0,pr*pc*sizeof(int)); finalMatPosR[x]=0;
for (unsigned x=0; x<finalMatPosC.size(); x++)
finalMatPosC[x]=0;
computeOneCombination(startComb++, inputData, outputData, computeOneCombination(startComb++, inputData, outputData,
outputVector,finalMatPosR, finalMatPosC); outputVector,finalMatPosR, finalMatPosC);
} }
delete[] finalMatPosR;
delete[] finalMatPosC;
} }
} }
void EstimateCovariance::computeOneCombination(int comb_id,Mat inputData, Mat outputData, void EstimateCovariance::computeOneCombination(int comb_id,Mat inputData, Mat outputData,
Mat outputVector,int* finalMatPosR, int* finalMatPosC) Mat outputVector,std::vector<int> finalMatPosR, std::vector<int> finalMatPosC)
{ {
Combination* comb = &combinationsTable[comb_id]; Combination* comb = &combinationsTable[comb_id];
int type2 = comb->type2; int type2 = comb->type2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment