template<class ArrayT>
Definition at line 83 of file MatNorm2Dist.h. References ILOG_DEBUG, ILOG_ERROR, ILOG_VAR, MatE(), MatMul(), MatNorm2DistSSE(), MatNrCol(), MatNrRow(), MatSumAxis0(), MatSumAxis1(), Impala::Core::Array::Mul(), Impala::Timer::SplitTime(), and Impala::Timer::SplitTimeStr(). Referenced by MatNorm2Dist(), and MatNorm2DistTransposed(). 00084 { 00085 #ifdef SSE_USED 00086 return MatNorm2DistSSE(aT, b); 00087 #endif 00088 ILOG_VAR(Core.Matrix.MatNorm2Dist); 00089 if (MatNrCol(aT) != MatNrRow(b)) { 00090 ILOG_ERROR("MatNorm2DistInternal operands: dimensionality problem"); 00091 } 00092 00093 Timer timer; 00094 00095 // aa = sum(multiply(a,a), axis=0) # aa = sum(a.*a,1) 00096 ArrayT* tempAT = 0; 00097 Mul(tempAT, aT, aT); // elementwise multiplication 00098 ArrayT* aaT = MatSumAxis1(tempAT); 00099 delete tempAT; 00100 00101 ILOG_DEBUG("aaT: " << timer.SplitTimeStr()); 00102 00103 // bb = sum(multiply(b,b), axis=0) # bb = sum(b.*b,1) 00104 ArrayT* tempB = 0; 00105 Mul(tempB, b, b); // elementwise multiplication 00106 ArrayT* bb = MatSumAxis0(tempB); 00107 delete tempB; 00108 00109 ILOG_DEBUG("bb: " << timer.SplitTimeStr()); 00110 00111 // ab = dot(transpose(a),b) # ab = a'*b 00112 //ArrayT* aT = MatTranspose(a); 00113 //ILOG_DEBUG("transpose: " << timer.SplitTimeStr()); 00114 00115 ILOG_DEBUG("aT " << MatNrRow(aT) << " " << MatNrCol(aT)); 00116 ILOG_DEBUG("b " << MatNrRow(b) << " " << MatNrCol(b)); 00117 00118 ArrayT* ab = MatMul(aT, b); 00119 00120 ILOG_DEBUG("matmul: " << timer.SplitTimeStr()); 00121 00122 // return sqrt(abs(transpose(repmat(aa,bb.shape[0],1)) + repmat(bb,aa.shape[0],1) - 2*ab)) 00123 // #d = sqrt(abs(repmat(aa',[1 size(bb,2)]) + repmat(bb,[size(aa,2) 1]) - 2*ab)); 00124 00125 //ILOG_DEBUG("aaT " << MatNrRow(aaT) << " " << MatNrCol(aaT)); 00126 //ILOG_DEBUG("bb " << MatNrRow(bb) << " " << MatNrCol(bb)); 00127 00128 #pragma omp parallel for 00129 for (int i=0 ; i<MatNrRow(aaT) ; i++) 00130 { 00131 Real64 tmp = *MatE(aaT, i, 0); 00132 for (int j=0 ; j<MatNrCol(bb) ; j++) 00133 { 00134 *MatE(ab, i, j) = sqrt(fabs(*MatE(bb, 0, j) + tmp - 2.0 * *MatE(ab, i, j))); 00135 } 00136 } 00137 ILOG_DEBUG("sqrt(abs(aa + bb - 2ab)): " << timer.SplitTimeStr()); 00138 delete bb; 00139 delete aaT; 00140 00141 ILOG_DEBUG("delete: " << timer.SplitTimeStr()); 00142 //WriteRaw(a, "matrix_a.raw", &Util::Database::GetInstance(), 1); 00143 //WriteRaw(b, "matrix_b.raw", &Util::Database::GetInstance(), 1); 00144 //WriteRaw(repAAT, "matrix_c.raw", &Util::Database::GetInstance(), 1); 00145 //ILOG_INFO("cpu-matnorm2dist-total: " << timer.SplitTime()); 00146 ILOG_DEBUG(timer.SplitTime() << " (cpu-matnorm2dist-total)"); 00147 return ab; 00148 }
Here is the call graph for this function:
|