- Timestamp:
- 12/05/15 18:31:38 (9 years ago)
- Location:
- cpp/frams
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/simil_test.cpp
r451 r455 71 71 72 72 // prepare output parameters from .gen file 73 vector<Geno *> *pvGenos = newvector<Geno *>();74 vector<char *> *pvNames = newvector<char *>();73 vector<Geno *> pvGenos = vector<Geno *>(); 74 vector<char *> pvNames = vector<char *>(); 75 75 76 76 // check if there is a switch … … 138 138 if ((pNextGenotype != NULL) && (pNextGenotype->isValid())) 139 139 { 140 pvGenos ->push_back(pNextGenotype);140 pvGenos.push_back(pNextGenotype); 141 141 char *szNewName = new char [ loaded->name.len() + 1]; 142 142 strcpy(szNewName, loaded->name.c_str()); 143 pvNames ->push_back(szNewName);143 pvNames.push_back(szNewName); 144 144 } 145 145 else … … 157 157 158 158 // create the empty array of similarities 159 aaSimil = new pDouble [pvGenos ->size()];160 for (unsigned int k = 0; k < pvGenos ->size(); k++)161 { 162 aaSimil[k] = new double [pvGenos ->size()];163 for (unsigned int l = 0; l < pvGenos ->size(); l++)159 aaSimil = new pDouble [pvGenos.size()]; 160 for (unsigned int k = 0; k < pvGenos.size(); k++) 161 { 162 aaSimil[k] = new double [pvGenos.size()]; 163 for (unsigned int l = 0; l < pvGenos.size(); l++) 164 164 aaSimil[k][l] = 0.0; 165 165 } 166 166 167 167 // compute and remember similarities 168 for (unsigned int i = 0; i < pvGenos ->size(); i++)169 { 170 for (unsigned int j = 0; j < pvGenos ->size(); j++)171 { 172 dSimilarity = M.EvaluateDistance(pvGenos ->operator[](i), pvGenos->operator[](j));168 for (unsigned int i = 0; i < pvGenos.size(); i++) 169 { 170 for (unsigned int j = 0; j < pvGenos.size(); j++) 171 { 172 dSimilarity = M.EvaluateDistance(pvGenos.operator[](i), pvGenos.operator[](j)); 173 173 aaSimil[i][j] = dSimilarity; 174 174 } … … 179 179 // if "-names" switch was given, 180 180 // print the number of genotypes and their names 181 printf("%li\n", pvGenos ->size());182 for (unsigned int iGen = 0; iGen < pvNames ->size(); iGen++)183 { 184 printf("%s\n", pvNames ->at(iGen));181 printf("%li\n", pvGenos.size()); 182 for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++) 183 { 184 printf("%s\n", pvNames.at(iGen)); 185 185 } 186 186 } 187 187 188 188 // print out the matrix of similarities 189 for (unsigned int i = 0; i < pvGenos ->size(); i++)190 { 191 for (unsigned int j = 0; j < pvGenos ->size(); j++)189 for (unsigned int i = 0; i < pvGenos.size(); i++) 190 { 191 for (unsigned int j = 0; j < pvGenos.size(); j++) 192 192 { 193 193 printf("%.2lf\t", aaSimil[i][j]); … … 197 197 198 198 // delete vectors and arrays 199 for (unsigned int i = 0; i < pvGenos ->size(); i++)200 { 201 delete pvGenos ->operator[](i);202 delete [] pvNames ->operator[](i);199 for (unsigned int i = 0; i < pvGenos.size(); i++) 200 { 201 delete pvGenos.operator[](i); 202 delete [] pvNames.operator[](i); 203 203 delete [] aaSimil[i]; 204 204 } 205 205 206 delete pvGenos;207 delete pvNames;208 206 delete [] aaSimil; 209 207 -
cpp/frams/model/similarity/SVD/matrix_tools.cpp
r389 r455 15 15 double *Create(int nSize) 16 16 { 17 double *matrix = (double *)malloc(nSize * sizeof(double));17 double *matrix = new double[nSize]; 18 18 19 19 for (int i = 0; i < nSize; i++) … … 40 40 41 41 if (delSize != 0) 42 free(toDel);42 delete[] toDel; 43 43 return c; 44 44 } … … 71 71 72 72 if (delSize != 0) 73 free(toDel);73 delete[] toDel; 74 74 75 75 return m_Power; … … 170 170 B = Multiply(B, Z, nSize, nSize, nSize, B, nSize); 171 171 172 free(Ones);173 free(Eye);174 free(Z);175 free(D);172 delete[] Ones; 173 delete[] Eye; 174 delete[] Z; 175 delete[] D; 176 176 } 177 177 … … 186 186 double *W = Transpose(Vt, nSize, nSize); 187 187 188 free(B);189 free(Vt);188 delete[] B; 189 delete[] Vt; 190 190 191 191 for (int i = 0; i < nSize; i++) … … 202 202 sqS = Power(S, nSize, nSize, 0.5, S, nSize); 203 203 dCoordinates = Multiply(W, sqS, nSize, nSize, nSize, W, nSize); 204 free(sqS);204 delete[] sqS; 205 205 206 206 for (int i = 0; i < nSize; i++) … … 222 222 } 223 223 224 free(Eigenvalues);225 free(dCoordinates);226 } 224 delete[] Eigenvalues; 225 delete[] dCoordinates; 226 }
Note: See TracChangeset
for help on using the changeset viewer.