Changeset 4420071 in tol
- Timestamp:
- Nov 9, 2009, 6:10:04 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- d2965a2
- Parents:
- 4dabb45
- Location:
- tol
- Files:
-
- 2 edited
-
bbasic/tol_hash_map.h (modified) (2 diffs)
-
btol/matrix_type/matgra.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tol/bbasic/tol_hash_map.h
r4dabb45 r4420071 110 110 }; 111 111 112 struct hash_double 113 { 114 size_t operator()(const double& s) const 115 { 116 size_t aux= *((size_t*)&s); 117 return(aux); 118 } 119 }; 120 112 121 //-------------------------------------------------------------------- 113 122 //this template struct allow define generic typedef of hash_map … … 183 192 size_t, 184 193 _T 194 >sparse_; 195 }; 196 197 template<class _T> 198 struct hash_map_by_double 199 { 200 //dense hash_map indexed by double 201 typedef dense_hash_map 202 < 203 double, 204 _T, 205 hash_double, 206 std::equal_to<double> 207 >dense_; 208 //sparse hash_map indexed by double 209 typedef sparse_hash_map 210 < 211 double, 212 _T, 213 hash_double, 214 std::equal_to<double> 185 215 >sparse_; 186 216 }; -
tol/btol/matrix_type/matgra.cpp
r4dabb45 r4420071 6713 6713 } 6714 6714 } 6715 } 6716 } 6717 6718 6719 //-------------------------------------------------------------------- 6720 DeclareContensClass(BMat, BMatTemporary, BMatReplace); 6721 DefExtOpr(1, BMatReplace, "MatReplace", 3, 3, "Matrix Matrix Matrix", 6722 "(Matrix data, Matrix old, Matrix new)", 6723 I2("Replaces in arbitrary matrix 'data' all occurrences of cell " 6724 "given in column matrix 'old' by corresponding cell in column " 6725 "matrix 'new', having obviously the same dimensions that 'old'.\n" 6726 "CAUTION!: 'old' cannot have repeated cells\n", 6727 "Reemplaza en la matriz arbitraria 'data' todas las ocurrencias " 6728 "de las celdas de la matriz columna 'old' por la celda " 6729 "correspondiente de la matriz columna 'new', que lógicamente " 6730 "debe tener las mismas dimensiones que 'old'.\n" 6731 "¡CUIDADO!: 'old' no debe tener celdas repetidas\n"), 6732 BOperClassify::MatrixAlgebra_); 6733 //-------------------------------------------------------------------- 6734 void BMatReplace::CalcContens() 6735 //-------------------------------------------------------------------- 6736 { 6737 int k; 6738 DMat& A = dMat(Arg(1)); 6739 DMat& old_ = dMat(Arg(2)); 6740 DMat& new_ = dMat(Arg(3)); 6741 int m = old_.Rows(); 6742 if((new_.Rows()!=m)|(old_.Columns()!=1)|(new_.Columns()!=1)) 6743 { 6744 Error(I2("Arguments 'old' and 'new' must be column matrices with " 6745 "the same number of rows.", 6746 "Los argumentos 'old' y 'mew' deben ser matrices columna " 6747 "con el mismo numero de filas.")+ 6748 "\n old:("+old_.Rows()+"x"+old_.Columns()+"); "+ 6749 "\n new:("+new_.Rows()+"x"+new_.Columns()+"); "); 6750 return; 6751 } 6752 hash_map_by_double<double>::sparse_ hashMap; 6753 hash_map_by_double<double>::sparse_::const_iterator fc; 6754 const double* x = old_.Data().Buffer(); 6755 const double* y = new_.Data().Buffer(); 6756 for(k=0; k<m; k++, x++, y++) 6757 { 6758 const double& xk = *x; 6759 fc = hashMap.find(xk); 6760 if(fc!=hashMap.end()) 6761 { 6762 Error(I2("Argument 'old' cannot have repeated cells.", 6763 "El argumento 'old' no puede tener celdas repetidas.")+ 6764 "\n old["+(k+1)+"] = "+xk+"; "); 6765 return; 6766 } 6767 hashMap[xk] = *y; 6768 } 6769 int rows = A.Rows(); 6770 int cols = A.Columns(); 6771 contens_.Alloc(rows, cols); 6772 const BArray<double>& data = A.Data(); 6773 int s = data.Size(); 6774 const double* a = data.Buffer(); 6775 double* c = (double*)(contens_.GetData().GetBuffer()); 6776 for(k=0; k<s; k++, a++, c++) 6777 { 6778 fc = hashMap.find(*a); 6779 if(fc!=hashMap.end()) 6780 { 6781 *c = fc->second; 6782 } 6783 else 6784 { 6785 *c = *a; 6786 } 6715 6787 } 6716 6788 6717 6789 } 6718 6790 6791
Note: See TracChangeset
for help on using the changeset viewer.
