void NMenuCtrl::OnMouseMove(NPoint point ) { udword idx = GetItemIdxUnderPt(point); TRACE("HighLighted idx %d\n", idx); if (idx!=m_dwItemHighLightedIdx) { m_bEntered = true; //Change highLighted item m_dwItemHighLightedIdx = idx; if (m_dwItemHighLightedIdx!=-1) { NMEItemDesc* pitem = &m_carrayItems[m_dwItemHighLightedIdx]; //Open Popup Menu if (pitem->ppopUpMenu) { //TRACE("Opening Popup idx %d\n", m_dwItemHighLightedIdx); //Hide old popup if (m_pcurPopupMenu) m_pcurPopupMenu->ShowMenu(false, null); //Show new popup Menu NPoint pT(pitem->rcItem.right, pitem->rcItem.top); NPoint pTF(pT); ClientToScreen(pTF); //Clipping... NRect rcPopup; pitem->ppopUpMenu->CalcMenuSize(rcPopup); NRect rcApp = GetGUISubSystem()->GetMainWnd()->GetWindowRect(); if (pTF.x + rcPopup.Width() > rcApp.right) { pT.x=pitem->rcItem.left-rcPopup.Width(); pTF=pT; ClientToScreen(pTF); } if (pTF.y + rcPopup.Height() > rcApp.bottom) { pTF.y=rcApp.Height()-rcPopup.Height(); } //TRACE("%d %d\n", pTF.x, pTF.y); //Display Popup pitem->ppopUpMenu->TrackPopupMenu(pTF, this); m_pcurPopupMenu = pitem->ppopUpMenu; } } //Repaint Update(); } }
osg::Matrixd CameraModel::projection(float znear, float zfar) const { // See http://strawlab.org/2011/11/05/augmented-reality-with-OpenGL/ if (!intrinsic_valid) {throw "invalid intrinsic";} float depth = zfar - znear; float q = -(zfar + znear) / depth; float qn = -2 * (zfar * znear) / depth; float x0=0; float y0=0; osg::Matrixd p; float width=_width; float height=_height; if (_y_up) { p=osg::Matrixf( 2*_K00/ width, -2*_K01/ width, (-2*_K02+ width+2*x0)/ width, 0, 0, -2*_K11/height, (-2*_K12+height+2*y0)/height, 0, 0, 0, q, qn, 0, 0, -1, 0); } else { p=osg::Matrixf( 2*_K00/ width, -2*_K01/ width, (-2*_K02+ width+2*x0)/ width, 0, 0, 2*_K11/height, ( 2*_K12-height+2*y0)/height, 0, 0, 0, q, qn, 0, 0, -1, 0); } osg::Matrixd pT; for (int i=0; i<4; i++) { for (int j=0; j<4; j++) { pT(i,j) = p(j,i); } } return pT; }
double LinearModel::getPValue() { vector_t var = getVar(); bool okay = var[testParameter] < 1e-20 || !realnum(var[testParameter]) ? false : all_valid; if (all_valid) { double se = sqrt(var[testParameter]); double Z = coef[testParameter] / se; return pT(Z,Y.size()-np); } else return 1; }
int parse(Task ** task) { int parseStatus; resetParserError(); if (task == NULL) { parserErrorNo = PE_NULL_POINTER; return PS_ERROR; } if (isWaitLex()) if (gl()) return PS_ERROR; *task = pT(); if (*task != NULL) parseStatus = PS_OK; else if (parserErrorNo == PE_NONE) { if (cur_l->type == LEX_EOL) parseStatus = PS_EOL; else if (cur_l->type == LEX_EOF) parseStatus = PS_EOF; } else parseStatus = PS_ERROR; if (parseStatus == PS_ERROR && cur_l->type != LEX_EOL && cur_l->type != LEX_EOF) { do if (glhard()) break; while (cur_l->type != LEX_EOL && cur_l->type != LEX_EOF); } cl(); return parseStatus; }
Foam::SolverPerformance<Type> Foam::PBiCICG<Type, DType, LUType>::solve(Field<Type>& psi) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); // --- Setup class containing solver performance data SolverPerformance<Type> solverPerf ( preconditionerName + typeName, this->fieldName_ ); register label nCells = psi.size(); Type* __restrict__ psiPtr = psi.begin(); Field<Type> pA(nCells); Type* __restrict__ pAPtr = pA.begin(); Field<Type> pT(nCells, pTraits<Type>::zero); Type* __restrict__ pTPtr = pT.begin(); Field<Type> wA(nCells); Type* __restrict__ wAPtr = wA.begin(); Field<Type> wT(nCells); Type* __restrict__ wTPtr = wT.begin(); Type wArT = solverPerf.great_*pTraits<Type>::one; Type wArTold = wArT; // --- Calculate A.psi and T.psi this->matrix_.Amul(wA, psi); this->matrix_.Tmul(wT, psi); // --- Calculate initial residual and transpose residual fields Field<Type> rA(this->matrix_.source() - wA); Field<Type> rT(this->matrix_.source() - wT); Type* __restrict__ rAPtr = rA.begin(); Type* __restrict__ rTPtr = rT.begin(); // --- Calculate normalisation factor Type normFactor = this->normFactor(psi, wA, pA); if (LduMatrix<Type, DType, LUType>::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // --- Calculate normalised residual norm solverPerf.initialResidual() = cmptDivide(gSumCmptMag(rA), normFactor); solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged if (!solverPerf.checkConvergence(this->tolerance_, this->relTol_)) { // --- Select and construct the preconditioner autoPtr<typename LduMatrix<Type, DType, LUType>::preconditioner> preconPtr = LduMatrix<Type, DType, LUType>::preconditioner::New ( *this, this->controlDict_ ); // --- Solver iteration do { // --- Store previous wArT wArTold = wArT; // --- Precondition residuals preconPtr->precondition(wA, rA); preconPtr->preconditionT(wT, rT); // --- Update search directions: wArT = gSumCmptProd(wA, rT); if (solverPerf.nIterations() == 0) { for (register label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell]; pTPtr[cell] = wTPtr[cell]; } } else { Type beta = cmptDivide ( wArT, stabilise(wArTold, solverPerf.vsmall_) ); for (register label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell] + cmptMultiply(beta, pAPtr[cell]); pTPtr[cell] = wTPtr[cell] + cmptMultiply(beta, pTPtr[cell]); } } // --- Update preconditioned residuals this->matrix_.Amul(wA, pA); this->matrix_.Tmul(wT, pT); Type wApT = gSumCmptProd(wA, pT); // --- Test for singularity if ( solverPerf.checkSingularity ( cmptDivide(cmptMag(wApT), normFactor) ) ) { break; } // --- Update solution and residual: Type alpha = cmptDivide ( wArT, stabilise(wApT, solverPerf.vsmall_) ); for (register label cell=0; cell<nCells; cell++) { psiPtr[cell] += cmptMultiply(alpha, pAPtr[cell]); rAPtr[cell] -= cmptMultiply(alpha, wAPtr[cell]); rTPtr[cell] -= cmptMultiply(alpha, wTPtr[cell]); } solverPerf.finalResidual() = cmptDivide(gSumCmptMag(rA), normFactor); } while ( solverPerf.nIterations()++ < this->maxIter_ && !(solverPerf.checkConvergence(this->tolerance_, this->relTol_)) ); } return solverPerf; }
inline void LU( DistMatrix<F>& A, DistMatrix<int,VC,STAR>& p ) { #ifndef RELEASE CallStackEntry entry("LU"); if( A.Grid() != p.Grid() ) throw std::logic_error("{A,p} must be distributed over the same grid"); if( p.Viewing() && (std::min(A.Height(),A.Width()) != p.Height() || p.Width() != 1) ) throw std::logic_error ("p must be a vector of the same height as the min dimension of A."); #endif const Grid& g = A.Grid(); if( !p.Viewing() ) p.ResizeTo( std::min(A.Height(),A.Width()), 1 ); // Matrix views DistMatrix<F> ATL(g), ATR(g), A00(g), A01(g), A02(g), AB(g), ABL(g), ABR(g), A10(g), A11(g), A12(g), A20(g), A21(g), A22(g); DistMatrix<int,VC,STAR> pT(g), p0(g), pB(g), p1(g), p2(g); // Temporary distributions DistMatrix<F, STAR,STAR> A11_STAR_STAR(g); DistMatrix<F, MC, STAR> A21_MC_STAR(g); DistMatrix<F, STAR,VR > A12_STAR_VR(g); DistMatrix<F, STAR,MR > A12_STAR_MR(g); DistMatrix<int,STAR,STAR> p1_STAR_STAR(g); // Pivot composition std::vector<int> image, preimage; // Start the algorithm PartitionDownDiagonal ( A, ATL, ATR, ABL, ABR, 0 ); PartitionDown ( p, pT, pB, 0 ); while( ATL.Height() < A.Height() && ATL.Width() < A.Width() ) { RepartitionDownDiagonal ( ATL, /**/ ATR, A00, /**/ A01, A02, /*************/ /******************/ /**/ A10, /**/ A11, A12, ABL, /**/ ABR, A20, /**/ A21, A22 ); RepartitionDown ( pT, p0, /**/ /**/ p1, pB, p2 ); View1x2( AB, ABL, ABR ); const int pivotOffset = A01.Height(); A12_STAR_VR.AlignWith( A22 ); A12_STAR_MR.AlignWith( A22 ); A21_MC_STAR.AlignWith( A22 ); A11_STAR_STAR.ResizeTo( A11.Height(), A11.Width() ); p1_STAR_STAR.ResizeTo( p1.Height(), 1 ); //--------------------------------------------------------------------// A21_MC_STAR = A21; A11_STAR_STAR = A11; lu::Panel( A11_STAR_STAR, A21_MC_STAR, p1_STAR_STAR, pivotOffset ); ComposePivots( p1_STAR_STAR, pivotOffset, image, preimage ); ApplyRowPivots( AB, image, preimage ); // Perhaps we should give up perfectly distributing this operation since // it's total contribution is only O(n^2) A12_STAR_VR = A12; LocalTrsm ( LEFT, LOWER, NORMAL, UNIT, F(1), A11_STAR_STAR, A12_STAR_VR ); A12_STAR_MR = A12_STAR_VR; LocalGemm( NORMAL, NORMAL, F(-1), A21_MC_STAR, A12_STAR_MR, F(1), A22 ); A11 = A11_STAR_STAR; A12 = A12_STAR_MR; A21 = A21_MC_STAR; p1 = p1_STAR_STAR; //--------------------------------------------------------------------// A12_STAR_VR.FreeAlignments(); A12_STAR_MR.FreeAlignments(); A21_MC_STAR.FreeAlignments(); SlidePartitionDownDiagonal ( ATL, /**/ ATR, A00, A01, /**/ A02, /**/ A10, A11, /**/ A12, /*************/ /******************/ ABL, /**/ ABR, A20, A21, /**/ A22 ); SlidePartitionDown ( pT, p0, p1, /**/ /**/ pB, p2 ); } }
Foam::lduSolverPerformance Foam::PBiCG::solve ( scalarField& x, const scalarField& b, const direction cmpt ) const { // --- Setup class containing solver performance data lduSolverPerformance solverPerf ( lduMatrix::preconditioner::getName(dict()) + typeName, fieldName() ); register label nCells = x.size(); scalar* __restrict__ xPtr = x.begin(); scalarField pA(nCells); scalar* __restrict__ pAPtr = pA.begin(); scalarField pT(nCells, 0.0); scalar* __restrict__ pTPtr = pT.begin(); scalarField wA(nCells); scalar* __restrict__ wAPtr = wA.begin(); scalarField wT(nCells); scalar* __restrict__ wTPtr = wT.begin(); scalar wArT = matrix_.great_; scalar wArTold = wArT; // Calculate A.x and T.x matrix_.Amul(wA, x, coupleBouCoeffs_, interfaces_, cmpt); matrix_.Tmul(wT, x, coupleIntCoeffs_, interfaces_, cmpt); // Calculate initial residual and transpose residual fields scalarField rA(b - wA); scalarField rT(b - wT); scalar* __restrict__ rAPtr = rA.begin(); scalar* __restrict__ rTPtr = rT.begin(); // Calculate normalisation factor scalar normFactor = this->normFactor(x, b, wA, pA, cmpt); if (lduMatrix::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // Calculate normalised residual norm solverPerf.initialResidual() = gSumMag(rA)/normFactor; solverPerf.finalResidual() = solverPerf.initialResidual(); // Check convergence, solve if not converged if (!stop(solverPerf)) { // Select and construct the preconditioner autoPtr<lduPreconditioner> preconPtr; preconPtr = lduPreconditioner::New ( matrix_, coupleBouCoeffs_, coupleIntCoeffs_, interfaces_, dict() ); // Solver iteration do { // Store previous wArT wArTold = wArT; // Precondition residuals preconPtr->precondition(wA, rA, cmpt); preconPtr->preconditionT(wT, rT, cmpt); // Update search directions: wArT = gSumProd(wA, rT); if (solverPerf.nIterations() == 0) { for (register label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell]; pTPtr[cell] = wTPtr[cell]; } } else { scalar beta = wArT/wArTold; for (register label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell] + beta*pAPtr[cell]; pTPtr[cell] = wTPtr[cell] + beta*pTPtr[cell]; } } // Update preconditioned residuals matrix_.Amul(wA, pA, coupleBouCoeffs_, interfaces_, cmpt); matrix_.Tmul(wT, pT, coupleIntCoeffs_, interfaces_, cmpt); scalar wApT = gSumProd(wA, pT); // Test for singularity if (solverPerf.checkSingularity(mag(wApT)/normFactor)) break; // Update solution and residual: scalar alpha = wArT/wApT; for (register label cell=0; cell<nCells; cell++) { xPtr[cell] += alpha*pAPtr[cell]; rAPtr[cell] -= alpha*wAPtr[cell]; rTPtr[cell] -= alpha*wTPtr[cell]; } solverPerf.finalResidual() = gSumMag(rA)/normFactor; solverPerf.nIterations()++; } while (!stop(solverPerf)); } return solverPerf; }
inline void internal::PanelLU ( DistMatrix<F, STAR,STAR>& A, DistMatrix<F, MC, STAR>& B, DistMatrix<int,STAR,STAR>& p, int pivotOffset ) { #ifndef RELEASE PushCallStack("internal::PanelLU"); if( A.Grid() != p.Grid() || p.Grid() != B.Grid() ) throw std::logic_error ("Matrices must be distributed over the same grid"); if( A.Width() != B.Width() ) throw std::logic_error("A and B must be the same width"); if( A.Height() != p.Height() || p.Width() != 1 ) throw std::logic_error("p must be a vector that conforms with A"); #endif const Grid& g = A.Grid(); const int r = g.Height(); const int colShift = B.ColShift(); const int colAlignment = B.ColAlignment(); // Matrix views DistMatrix<F,STAR,STAR> ATL(g), ATR(g), A00(g), a01(g), A02(g), ABL(g), ABR(g), a10(g), alpha11(g), a12(g), A20(g), a21(g), A22(g); DistMatrix<F,MC,STAR> BL(g), BR(g), B0(g), b1(g), B2(g); DistMatrix<int,STAR,STAR> pT(g), p0(g), pB(g), psi1(g), p2(g); const int width = A.Width(); const int numBytes = (width+1)*sizeof(F)+sizeof(int); std::vector<byte> sendData(numBytes); std::vector<byte> recvData(numBytes); // Extract pointers to send and recv data F* sendBufFloat = (F*) &sendData[0]; F* recvBufFloat = (F*) &recvData[0]; int* sendBufInt = (int*) &sendData[(width+1)*sizeof(F)]; int* recvBufInt = (int*) &recvData[(width+1)*sizeof(F)]; // Start the algorithm PushBlocksizeStack( 1 ); PartitionDownDiagonal ( A, ATL, ATR, ABL, ABR, 0 ); PartitionRight( B, BL, BR, 0 ); PartitionDown ( p, pT, pB, 0 ); while( ATL.Height() < A.Height() ) { RepartitionDownDiagonal ( ATL, /**/ ATR, A00, /**/ a01, A02, /*************/ /**********************/ /**/ a10, /**/ alpha11, a12, ABL, /**/ ABR, A20, /**/ a21, A22 ); RepartitionRight ( BL, /**/ BR, B0, /**/ b1, B2 ); RepartitionDown ( pT, p0, /**/ /****/ psi1, pB, p2 ); //--------------------------------------------------------------------// // Store the index/value of the pivot candidate in A F pivotValue = alpha11.GetLocalEntry(0,0); int pivotIndex = a01.Height(); for( int i=0; i<a21.Height(); ++i ) { F value = a21.GetLocalEntry(i,0); if( FastAbs(value) > FastAbs(pivotValue) ) { pivotValue = value; pivotIndex = a01.Height() + i + 1; } } // Update the pivot candidate to include local data from B for( int i=0; i<B.LocalHeight(); ++i ) { F value = b1.GetLocalEntry(i,0); if( FastAbs(value) > FastAbs(pivotValue) ) { pivotValue = value; pivotIndex = A.Height() + colShift + i*r; } } // Fill the send buffer with: // [ pivotValue | pivotRow | pivotIndex ] if( pivotIndex < A.Height() ) { sendBufFloat[0] = A.GetLocalEntry(pivotIndex,a10.Width()); const int ALDim = A.LocalLDim(); const F* ABuffer = A.LocalBuffer(pivotIndex,0); for( int j=0; j<width; ++j ) sendBufFloat[j+1] = ABuffer[j*ALDim]; } else { const int localIndex = ((pivotIndex-A.Height())-colShift)/r; sendBufFloat[0] = b1.GetLocalEntry(localIndex,0); const int BLDim = B.LocalLDim(); const F* BBuffer = B.LocalBuffer(localIndex,0); for( int j=0; j<width; ++j ) sendBufFloat[j+1] = BBuffer[j*BLDim]; } *sendBufInt = pivotIndex; // Communicate to establish the pivot information mpi::AllReduce ( &sendData[0], &recvData[0], numBytes, PivotOp<F>(), g.ColComm() ); // Update the pivot vector const int maxIndex = *recvBufInt; p.SetLocalEntry(a01.Height(),0,maxIndex+pivotOffset); // Copy the current row into the pivot row if( maxIndex < A.Height() ) { const int ALDim = A.LocalLDim(); F* ASetBuffer = A.LocalBuffer(maxIndex,0); const F* AGetBuffer = A.LocalBuffer(A00.Height(),0); for( int j=0; j<width; ++j ) ASetBuffer[j*ALDim] = AGetBuffer[j*ALDim]; } else { const int ownerRank = (colAlignment+(maxIndex-A.Height())) % r; if( g.Row() == ownerRank ) { const int localIndex = ((maxIndex-A.Height())-colShift) / r; const int ALDim = A.LocalLDim(); const int BLDim = B.LocalLDim(); F* BBuffer = B.LocalBuffer(localIndex,0); const F* ABuffer = A.LocalBuffer(A00.Height(),0); for( int j=0; j<width; ++j ) BBuffer[j*BLDim] = ABuffer[j*ALDim]; } } // Copy the pivot row into the current row { F* ABuffer = A.LocalBuffer(A00.Height(),0); const int ALDim = A.LocalLDim(); for( int j=0; j<width; ++j ) ABuffer[j*ALDim] = recvBufFloat[j+1]; } // Now we can perform the update of the current panel F alpha = alpha11.GetLocalEntry(0,0); if( alpha == (F)0 ) throw SingularMatrixException(); F alpha11Inv = ((F)1) / alpha; Scal( alpha11Inv, a21.LocalMatrix() ); Scal( alpha11Inv, b1.LocalMatrix() ); Geru( (F)-1, a21.LocalMatrix(), a12.LocalMatrix(), A22.LocalMatrix() ); Geru( (F)-1, b1.LocalMatrix(), a12.LocalMatrix(), B2.LocalMatrix() ); //--------------------------------------------------------------------// SlidePartitionDownDiagonal ( ATL, /**/ ATR, A00, a01, /**/ A02, /**/ a10, alpha11, /**/ a12, /*************/ /**********************/ ABL, /**/ ABR, A20, a21, /**/ A22 ); SlidePartitionRight ( BL, /**/ BR, B0, b1, /**/ B2 ); SlidePartitionDown ( pT, p0, psi1, /**/ /****/ pB, p2 ); } PopBlocksizeStack(); #ifndef RELEASE PopCallStack(); #endif }
Foam::solverPerformance Foam::PBiCG::solve ( scalarField& psi, const scalarField& source, const direction cmpt ) const { // --- Setup class containing solver performance data solverPerformance solverPerf ( lduMatrix::preconditioner::getName(controlDict_) + typeName, fieldName_ ); label nCells = psi.size(); scalar* __restrict__ psiPtr = psi.begin(); scalarField pA(nCells); scalar* __restrict__ pAPtr = pA.begin(); scalarField pT(nCells, 0.0); scalar* __restrict__ pTPtr = pT.begin(); scalarField wA(nCells); scalar* __restrict__ wAPtr = wA.begin(); scalarField wT(nCells); scalar* __restrict__ wTPtr = wT.begin(); scalar wArT = solverPerf.great_; scalar wArTold = wArT; // --- Calculate A.psi and T.psi matrix_.Amul(wA, psi, interfaceBouCoeffs_, interfaces_, cmpt); matrix_.Tmul(wT, psi, interfaceIntCoeffs_, interfaces_, cmpt); // --- Calculate initial residual and transpose residual fields scalarField rA(source - wA); scalarField rT(source - wT); scalar* __restrict__ rAPtr = rA.begin(); scalar* __restrict__ rTPtr = rT.begin(); // --- Calculate normalisation factor scalar normFactor = this->normFactor(psi, source, wA, pA); if (lduMatrix::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // --- Calculate normalised residual norm solverPerf.initialResidual() = gSumMag(rA, matrix().mesh().comm()) /normFactor; solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged if ( minIter_ > 0 || !solverPerf.checkConvergence(tolerance_, relTol_) ) { // --- Select and construct the preconditioner autoPtr<lduMatrix::preconditioner> preconPtr = lduMatrix::preconditioner::New ( *this, controlDict_ ); // --- Solver iteration do { // --- Store previous wArT wArTold = wArT; // --- Precondition residuals preconPtr->precondition(wA, rA, cmpt); preconPtr->preconditionT(wT, rT, cmpt); // --- Update search directions: wArT = gSumProd(wA, rT, matrix().mesh().comm()); if (solverPerf.nIterations() == 0) { for (label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell]; pTPtr[cell] = wTPtr[cell]; } } else { scalar beta = wArT/wArTold; for (label cell=0; cell<nCells; cell++) { pAPtr[cell] = wAPtr[cell] + beta*pAPtr[cell]; pTPtr[cell] = wTPtr[cell] + beta*pTPtr[cell]; } } // --- Update preconditioned residuals matrix_.Amul(wA, pA, interfaceBouCoeffs_, interfaces_, cmpt); matrix_.Tmul(wT, pT, interfaceIntCoeffs_, interfaces_, cmpt); scalar wApT = gSumProd(wA, pT, matrix().mesh().comm()); // --- Test for singularity if (solverPerf.checkSingularity(mag(wApT)/normFactor)) { break; } // --- Update solution and residual: scalar alpha = wArT/wApT; for (label cell=0; cell<nCells; cell++) { psiPtr[cell] += alpha*pAPtr[cell]; rAPtr[cell] -= alpha*wAPtr[cell]; rTPtr[cell] -= alpha*wTPtr[cell]; } solverPerf.finalResidual() = gSumMag(rA, matrix().mesh().comm()) /normFactor; } while ( ( solverPerf.nIterations()++ < maxIter_ && !solverPerf.checkConvergence(tolerance_, relTol_) ) || solverPerf.nIterations() < minIter_ ); } return solverPerf; }
AOSContext::ReturnCode AOSOutput_Template::execute(AOSContext& context) { //a_See if extension for mime type set for the template(s) AString ext; if (context.getOutputParams().emitContentFromPath(AOS_BaseModules_Constants::MIME_EXTENSION, ext)) { m_Services.useConfiguration().setMimeTypeFromExt(ext, context); } else { //a_Set content type based on request URL extension m_Services.useConfiguration().setMimeTypeFromExt(context.useRequestUrl().getExtension(), context); } // Iterate parameters and build the template const AXmlElement::CONTAINER& container = context.getOutputParams().getContentContainer(); for (AXmlElement::CONTAINER::const_iterator cit = container.begin(); cit != container.end(); ++cit) { //a_Check "if" condition AString ifElement; if ((*cit)->getAttributes().get(ASW("if",2), ifElement)) { if (ifElement.getSize() > 0) { //a_Check condition, if not met continue with next template if (!context.useModel().exists(ifElement)) { if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) context.useEventVisitor().startEvent(ARope("Skipping conditional file template IF ")+ifElement, AEventVisitor::EL_DEBUG); continue; } } } //a_Check "ifnot" condition ifElement.clear(); if ((*cit)->getAttributes().get(ASW("ifnot",5), ifElement)) { if (ifElement.getSize() > 0) { //a_Check condition, if not met continue with next template if (context.useModel().exists(ifElement)) { if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) context.useEventVisitor().startEvent(ARope("Skipping conditional file template IFNOT ")+ifElement, AEventVisitor::EL_DEBUG); continue; } } } // // Now we check if this is inlined or filename // AString str(1024, 512); if ((*cit)->getName().equals(AOS_BaseModules_Constants::TEMPLATE)) { if (context.useEventVisitor().isLoggingDebug()) { context.useEventVisitor().startEvent(getClass() + ": Creating new inline template", AEventVisitor::EL_DEBUG); } // Create a new template AAutoPtr<ATemplate> pTemplate(m_Services.createTemplate(), true); // Add inline template str.clear(); (*cit)->emitContent(str); AFile_AString strfile(str); pTemplate->clear(); pTemplate->fromAFile(strfile); pTemplate->process(context.useLuaTemplateContext(), context.useOutputBuffer()); } else if ((*cit)->getName().equals(AOS_BaseModules_Constants::FILENAME)) { // Add filename based template AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory()); str.clear(); (*cit)->emitContent(str); filename.join(str, false); if (context.useEventVisitor().isLoggingDebug()) { context.useEventVisitor().startEvent(getClass()+": Fetching/parsing template for: "+filename, AEventVisitor::EL_DEBUG); } AAutoPtr<ATemplate> pT(NULL, false); if (ACacheInterface::NOT_FOUND == m_Services.useCacheManager().getTemplate(context, filename, pT)) { //a_Not found add error and continue if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN)) context.useEventVisitor().startEvent(ARope(getClass())+ASWNL(": Unable to find a template file: ")+filename+ASWNL(", ignoring and continuing"), AEventVisitor::EL_WARN); continue; } //a_Parse template if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG)) { context.useEventVisitor().startEvent(getClass()+"Processing template file: "+filename, AEventVisitor::EL_DEBUG); } AASSERT(this, pT.isNotNull()); pT->process(context.useLuaTemplateContext(), context.useOutputBuffer()); } } return AOSContext::RETURN_OK; }
Foam::SolverPerformance<Type> Foam::PBiCCCG<Type, DType, LUType>::solve ( gpuField<Type>& psi ) const { word preconditionerName(this->controlDict_.lookup("preconditioner")); // --- Setup class containing solver performance data SolverPerformance<Type> solverPerf ( preconditionerName + typeName, this->fieldName_ ); register label nCells = psi.size(); gpuField<Type> pA(nCells); gpuField<Type> pT(nCells, pTraits<Type>::zero); gpuField<Type> wA(nCells); gpuField<Type> wT(nCells); scalar wArT = 1e15; //this->matrix_.great_; scalar wArTold = wArT; // --- Calculate A.psi and T.psi this->matrix_.Amul(wA, psi); this->matrix_.Tmul(wT, psi); // --- Calculate initial residual and transpose residual fields gpuField<Type> rA(this->matrix_.source() - wA); gpuField<Type> rT(this->matrix_.source() - wT); // --- Calculate normalisation factor Type normFactor = this->normFactor(psi, wA, pA); if (LduMatrix<Type, DType, LUType>::debug >= 2) { Info<< " Normalisation factor = " << normFactor << endl; } // --- Calculate normalised residual norm solverPerf.initialResidual() = cmptDivide(gSumCmptMag(rA), normFactor); solverPerf.finalResidual() = solverPerf.initialResidual(); // --- Check convergence, solve if not converged if ( this->minIter_ > 0 || !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) { // --- Select and construct the preconditioner autoPtr<typename LduMatrix<Type, DType, LUType>::preconditioner> preconPtr = LduMatrix<Type, DType, LUType>::preconditioner::New ( *this, this->controlDict_ ); // --- Solver iteration do { // --- Store previous wArT wArTold = wArT; // --- Precondition residuals preconPtr->precondition(wA, rA); preconPtr->preconditionT(wT, rT); // --- Update search directions: wArT = gSumProd(wA, rT); if (solverPerf.nIterations() == 0) { thrust::copy(wA.begin(),wA.end(),pA.begin()); thrust::copy(wT.begin(),wT.end(),pT.begin()); } else { scalar beta = wArT/wArTold; thrust::transform ( wA.begin(), wA.end(), thrust::make_transform_iterator ( pA.begin(), multiplyOperatorSFFunctor<scalar,Type,Type>(beta) ), pA.begin(), addOperatorFunctor<Type,Type,Type>() ); thrust::transform ( wT.begin(), wT.end(), thrust::make_transform_iterator ( pT.begin(), multiplyOperatorSFFunctor<scalar,Type,Type>(beta) ), pT.begin(), addOperatorFunctor<Type,Type,Type>() ); } // --- Update preconditioned residuals this->matrix_.Amul(wA, pA); this->matrix_.Tmul(wT, pT); scalar wApT = gSumProd(wA, pT); // --- Test for singularity if ( solverPerf.checkSingularity ( cmptDivide(pTraits<Type>::one*mag(wApT), normFactor) ) ) { break; } // --- Update solution and residual: scalar alpha = wArT/wApT; thrust::transform ( psi.begin(), psi.end(), thrust::make_transform_iterator ( pA.begin(), multiplyOperatorSFFunctor<scalar,Type,Type>(alpha) ), psi.begin(), addOperatorFunctor<Type,Type,Type>() ); thrust::transform ( rA.begin(), rA.end(), thrust::make_transform_iterator ( wA.begin(), multiplyOperatorSFFunctor<scalar,Type,Type>(alpha) ), rA.begin(), subtractOperatorFunctor<Type,Type,Type>() ); thrust::transform ( rT.begin(), rT.end(), thrust::make_transform_iterator ( wT.begin(), multiplyOperatorSFFunctor<scalar,Type,Type>(alpha) ), rT.begin(), subtractOperatorFunctor<Type,Type,Type>() ); solverPerf.finalResidual() = cmptDivide(gSumCmptMag(rA), normFactor); } while ( ( solverPerf.nIterations()++ < this->maxIter_ && !solverPerf.checkConvergence(this->tolerance_, this->relTol_) ) || solverPerf.nIterations() < this->minIter_ ); } return solverPerf; }
void LinearModel::displayResults(ofstream & OUT, Locus * loc) { vector_t var; if ( all_valid ) var = getVar(); else { var.clear(); var.resize(np,0); } for (int p=1; p<np; p++) // skip intercept { bool okay = var[p] < 1e-20 || !realnum(var[p]) ? false : all_valid; double se = 0; double Z = 0; double pvalue = 1; if (okay) { se = sqrt(var[p]); Z = coef[p] / se; pvalue = pT(Z,Y.size()-np); } // If filtering p-values if ( (!par::pfilter) || pvalue <= par::pfvalue ) { // Skip covariates? if ( par::no_show_covar && p != testParameter ) continue; OUT << setw(4) << loc->chr << " " << setw(par::pp_maxsnp) << loc->name << " " << setw(10) << loc->bp << " " << setw(4) << loc->allele1 << " " << setw(10) << label[p] << " " << setw(8) << Y.size() << " "; if (okay) { OUT << setw(10) << coef[p] << " "; if (par::display_ci) OUT << setw(8) << se << " " << setw(8) << coef[p] - par::ci_zt * se << " " << setw(8) << coef[p] + par::ci_zt * se << " "; OUT << setw(12) << Z << " " << setw(12) << pvalue; } else { OUT << setw(10) << "NA" << " "; if (par::display_ci) OUT << setw(8) << "NA" << " " << setw(8) << "NA" << " " << setw(8) << "NA" << " "; OUT << setw(12) << "NA" << " " << setw(12) << "NA"; } OUT << "\n"; } } }