bool SLoaderThread::IsLoadingFile(UsedFile *pFile) { CSAccess cs(&m_Incoming.m_MessageCS); CSAccess cs2(&m_Outgoing.m_MessageCS); GPOS pos; ASSERT(!IsInThisThread()); if(!g_pServerMgr) return LTFALSE; // Check all our messages. for(pos=m_Incoming.m_Messages; pos; ) { if(m_Incoming.m_Messages.GetNext(pos)->m_Data[1].m_pData == pFile) return LTTRUE; } for(pos=m_Outgoing.m_Messages; pos; ) { if(m_Outgoing.m_Messages.GetNext(pos)->m_Data[1].m_pData == pFile) return LTTRUE; } return LTFALSE; }
// ------------------------------------------------------------------ // Name : getCharacterPosition // ------------------------------------------------------------------ int Font::getCharacterPosition(CoordsScreen cs, string sText) { assert(m_pTex != NULL); CoordsScreen cs2(0,m_uFontHeight); int iLength = sText.length(); for (int i = 0; i < iLength; i++) { if (sText[i] == '\n') { if (cs.y <= cs2.y) { // clicked on previous line return i; } cs2.x = 0; cs2.y += m_uFontHeight; continue; } CharDescriptor * charDesc = findCharDescriptor(sText[i]); if (charDesc == NULL) { continue; } int adv = charDesc->xadvance / 2; cs2.x += adv; if (cs.x <= cs2.x && cs.y <= cs2.y) { return i; } cs2.x += charDesc->xadvance - adv; if (cs.x <= cs2.x && cs.y <= cs2.y) { return i+1; } } return iLength; }
void contractor_join::prune(contractor_status & cs1) { DREAL_LOG_DEBUG << "contractor_join::prune"; // duplicate cs1 contractor_status cs2(cs1); // run m_c1 m_c1.prune(cs1); // run m_c2 on b1 m_c2.prune(cs2); cs1.join(cs2); }
void CAsyncApiWorker::ProcessJob(CAsyncApiJob* job) { r3d_assert(curJob_ == NULL); curJob_ = job; // exec it #ifdef _DEBUG r3dOutToLog("CAsyncApiWorker %d executing %s\n", idx_, job->desc); #endif try { job->ResultCode = job->Exec(); } catch(const char* msg) { r3dOutToLog("!!!! CAsyncApiWorker %d job crashed: %s\n", idx_, msg); job->ResultCode = 99; } #ifdef _DEBUG r3dOutToLog("CAsyncApiWorker %d finished %s\n", idx_, job->desc); #endif // if job is failed, remove all future jobs for that customerid if(job->ResultCode != 0 && job->CustomerID) { r3dOutToLog("!!!! CAsyncApiWorker %d job %s failed\n", idx_, job->desc); r3dCSHolder cs3(csJobs_); for(std::list<CAsyncApiJob*>::iterator it = jobs_.begin(); it != jobs_.end(); ) { if((*it)->CustomerID == job->CustomerID) { r3dOutToLog("!!! CAsyncApiWorker %d removed future job %s\n", idx_, (*it)->desc); it = jobs_.erase(it); continue; } ++it; } } // place it to finish queue { r3dCSHolder cs2(csJobs_); curJob_ = NULL; finished_.push_back(job); } }
template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTime) { typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar; typedef typename ComplexSchur<MatrixType>::ComplexMatrixType ComplexMatrixType; // Test basic functionality: T is triangular and A = U T U* for(int counter = 0; counter < g_repeat; ++counter) { MatrixType A = MatrixType::Random(size, size); ComplexSchur<MatrixType> schurOfA(A); VERIFY_IS_EQUAL(schurOfA.info(), Success); ComplexMatrixType U = schurOfA.matrixU(); ComplexMatrixType T = schurOfA.matrixT(); for(int row = 1; row < size; ++row) { for(int col = 0; col < row; ++col) { VERIFY(T(row,col) == (typename MatrixType::Scalar)0); } } VERIFY_IS_APPROX(A.template cast<ComplexScalar>(), U * T * U.adjoint()); } // Test asserts when not initialized ComplexSchur<MatrixType> csUninitialized; VERIFY_RAISES_ASSERT(csUninitialized.matrixT()); VERIFY_RAISES_ASSERT(csUninitialized.matrixU()); VERIFY_RAISES_ASSERT(csUninitialized.info()); // Test whether compute() and constructor returns same result MatrixType A = MatrixType::Random(size, size); ComplexSchur<MatrixType> cs1; cs1.compute(A); ComplexSchur<MatrixType> cs2(A); VERIFY_IS_EQUAL(cs1.info(), Success); VERIFY_IS_EQUAL(cs2.info(), Success); VERIFY_IS_EQUAL(cs1.matrixT(), cs2.matrixT()); VERIFY_IS_EQUAL(cs1.matrixU(), cs2.matrixU()); // Test computation of only T, not U ComplexSchur<MatrixType> csOnlyT(A, false); VERIFY_IS_EQUAL(csOnlyT.info(), Success); VERIFY_IS_EQUAL(cs1.matrixT(), csOnlyT.matrixT()); VERIFY_RAISES_ASSERT(csOnlyT.matrixU()); if (size > 1) { // Test matrix with NaN A(0,0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN(); ComplexSchur<MatrixType> csNaN(A); VERIFY_IS_EQUAL(csNaN.info(), NoConvergence); } }
// Calculates the transformation matrix between two coordinate systems void mtransf(DMatrix csys1, DMatrix csys2, DMatrix &mat) { DMatrix cs1(3,3), cs2(3,3); double size1, size2; int i, j, ito, ifrom, idot; // normalization for (i=1; i<=3; i++) { size1 = 0; size2 = 0; for (j=1; j<=3; j++) { size1 += pow(csys1(i,j),2); size2 += pow(csys2(i,j),2); } size1 = sqrt(size1); size2 = sqrt(size2); for (j=1; j<=3; j++) { cs1(i,j) = csys1(i,j) / size1; cs2(i,j) = csys2(i,j) / size2; } } // transformation for (ito=1; ito<=3; ito++) { for (ifrom=1; ifrom<=3; ifrom++) { mat(ito,ifrom) = 0; for (idot=1; idot<=3; idot++) mat(ito,ifrom) += cs2(ito,idot) * cs1(ifrom,idot); if (fabs(mat(ito,ifrom))<=1e-16) mat(ito,ifrom) = 0; } } }
int main (void) { //std::string c_blk("black"); //std::string c_mag("magenta"); //printf("\033[0m%s\033[0m\n",c_blk.c_str()); //printf("%s\033[0m\n",c_mag.c_str()); //printf ("\033[%im%s, \033[1mbold %s\033[0m\n", // 0, "black", "black"); //printf ("\033[%im%s, \033[1mbold %s\033[0m\n", // 16, "red", "red"); //printf ("\033[31m%s \033[1m%s \n","red", "bold"); //std::string str("\033[31mred \033[1m bold"); /*std::string str("some text"); std::cout << red << str << std::endl; std::cout << green << str << std::endl; std::cout << "\033[0;" << 32 << "mHello!\033[0m" << std::endl; std::cout << "\033[0;" << 33 << "mHello World!\033[0m" << std::endl; std::cout << "\033[0;" << 34 << "mHello World Hello!\033[0m" << std::endl; std::cout << "\033[0;" << 35 << "mHello World Hello World!\033[0m" << std::endl; */ std::string s("some new text"); std::cout << "correct lenght = " << s.length() << std::endl; colorstring cs("some new text","red"); colorstring cs2("some new text","yellow"); std::cout << cs.str << std::endl; std::cout << cs2.str << std::endl; // std::cout << "length = " << cs2.str.length() << std::endl; // std::cout << "length = " << cs2.length() << std::endl; exit (0); }
latticeInfo setLatticeInfo( ) { uint status; char* modelName; latticeInfo info; info.model = D2Q9; // Read model name. Use D2Q9 as default status = lookUpStringEntry( "properties/latticeProperties", "LBModel", &modelName, "D2Q9" ); if(status) {} if( strcmp(modelName, "D2Q9") == 0 ) { info.model = D2Q9; } else { if( strcmp(modelName, "D3Q15") == 0 ) { info.model = D3Q15; } else { char msg[100]; sprintf(msg, "Unrecognized model %s", modelName); errorMsg( msg ); } } // Assign properties info.cs2 = cs2( info.model ); info.Q = latticeQ( info.model ); info.d = latticeD( info.model ); info.vel = latticeVelocities( info.model ); info.reverse = latticeReverseDir( info.model ); info.omega = latticeWeights( info.model ); info.weights = ppWeights( info.model ); info.M = MRTMatrix( info.model ); info.invM = MRTInvMatrix( info.model ); return info; }
/* * Non-inlined part of myGetc(). */ char BufferedFileInput::myGetcNonInlinedPart() { Buffer& theBuffer = _buffers[_which]; int64_t index = theBuffer._index; // if there was an unget if (index < 0) { assert(index == -1); index = 0; return theBuffer._fromUnget; } // assert that the scanner has indeed finished the current buffer assert(index == theBuffer._sizeTotal); // if eofReached, return; if ( index < _bufferSize) { #ifndef NDEBUG _debugOnlyNoMoreCalls = true; #endif return EOF; } // signal the loader // Put in a scope so that the mutex is not held too long. { // lock ScopedMutexLock cs(theBuffer._mutex); // signal theBuffer._loaded = false; if (theBuffer._loaderIsWaiting) { theBuffer._eventBlockingLoader.signal(); } } // switch to the next buffer _which = 1 - _which; Buffer& nextBuffer = _buffers[_which]; // lock the next buffer ScopedMutexLock cs2(nextBuffer._mutex); // wait till the buffer is LOADED if (!nextBuffer._loaded) { try { nextBuffer._scannerIsWaiting = true; Event::ErrorChecker ec = bind(&queryAndScannerValid, Query::getValidQueryPtr(_query), &_state); bool signalled = nextBuffer._eventBlockingScanner.wait(nextBuffer._mutex, ec); nextBuffer._scannerIsWaiting = false; if (!signalled) { LOG4CXX_DEBUG(logger, "BufferedFileInput::myGetc() eventBlockingScanner.wait() returned false!"); return EOF; } } catch (Exception& e) { LOG4CXX_DEBUG(logger, "BufferedFileInput::myGetc() exception in eventBlockingScanner.wait()."); return EOF; } } // whether error has occurred in the loader if (theBuffer._readFileError) { throw SYSTEM_EXCEPTION(SCIDB_SE_IO, SCIDB_LE_PREAD_ERROR) << _bufferSize << "(offset)" << "(rc)" << ::strerror(theBuffer._readFileError) << theBuffer._readFileError; } // call myGetc() on the new buffer return myGetc(); }
void svd_qr_shift(MatrixType & vcl_u, MatrixType & vcl_v, CPU_VectorType & q, CPU_VectorType & e) { typedef typename MatrixType::value_type ScalarType; typedef typename viennacl::result_of::cpu_value_type<ScalarType>::type CPU_ScalarType; vcl_size_t n = q.size(); int m = static_cast<int>(vcl_u.size1()); detail::transpose(vcl_u); detail::transpose(vcl_v); std::vector<CPU_ScalarType> signs_v(n, 1); std::vector<CPU_ScalarType> cs1(n), ss1(n), cs2(n), ss2(n); viennacl::vector<CPU_ScalarType> tmp1(n, viennacl::traits::context(vcl_u)), tmp2(n, viennacl::traits::context(vcl_u)); bool goto_test_conv = false; for (int k = static_cast<int>(n) - 1; k >= 0; k--) { // std::cout << "K = " << k << std::endl; vcl_size_t iter = 0; for (iter = 0; iter < detail::ITER_MAX; iter++) { // test for split int l; for (l = k; l >= 0; l--) { goto_test_conv = false; if (std::fabs(e[vcl_size_t(l)]) <= detail::EPS) { // set it goto_test_conv = true; break; } if (std::fabs(q[vcl_size_t(l) - 1]) <= detail::EPS) { // goto break; } } if (!goto_test_conv) { CPU_ScalarType c = 0.0; CPU_ScalarType s = 1.0; //int l1 = l - 1; //int l2 = k; for (int i = l; i <= k; i++) { CPU_ScalarType f = s * e[vcl_size_t(i)]; e[vcl_size_t(i)] = c * e[vcl_size_t(i)]; if (std::fabs(f) <= detail::EPS) { //l2 = i - 1; break; } CPU_ScalarType g = q[vcl_size_t(i)]; CPU_ScalarType h = detail::pythag(f, g); q[vcl_size_t(i)] = h; c = g / h; s = -f / h; cs1[vcl_size_t(i)] = c; ss1[vcl_size_t(i)] = s; } // std::cout << "Hitted!" << l1 << " " << l2 << "\n"; // for (int i = l; i <= l2; i++) // { // for (int j = 0; j < m; j++) // { // CPU_ScalarType y = u(j, l1); // CPU_ScalarType z = u(j, i); // u(j, l1) = y * cs1[i] + z * ss1[i]; // u(j, i) = -y * ss1[i] + z * cs1[i]; // } // } } CPU_ScalarType z = q[vcl_size_t(k)]; if (l == k) { if (z < 0) { q[vcl_size_t(k)] = -z; signs_v[vcl_size_t(k)] *= -1; } break; } if (iter >= detail::ITER_MAX - 1) break; CPU_ScalarType x = q[vcl_size_t(l)]; CPU_ScalarType y = q[vcl_size_t(k) - 1]; CPU_ScalarType g = e[vcl_size_t(k) - 1]; CPU_ScalarType h = e[vcl_size_t(k)]; CPU_ScalarType f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2 * h * y); g = detail::pythag<CPU_ScalarType>(f, 1); if (f < 0) { f = ((x - z) * (x + z) + h * (y / (f - g) - h)) / x; } else { f = ((x - z) * (x + z) + h * (y / (f + g) - h)) / x; } CPU_ScalarType c = 1; CPU_ScalarType s = 1; for (vcl_size_t i = static_cast<vcl_size_t>(l) + 1; i <= static_cast<vcl_size_t>(k); i++) { g = e[i]; y = q[i]; h = s * g; g = c * g; CPU_ScalarType z2 = detail::pythag(f, h); e[i - 1] = z2; c = f / z2; s = h / z2; f = x * c + g * s; g = -x * s + g * c; h = y * s; y = y * c; cs1[i] = c; ss1[i] = s; z2 = detail::pythag(f, h); q[i - 1] = z2; c = f / z2; s = h / z2; f = c * g + s * y; x = -s * g + c * y; cs2[i] = c; ss2[i] = s; } { viennacl::copy(cs1, tmp1); viennacl::copy(ss1, tmp2); givens_prev(vcl_v, tmp1, tmp2, static_cast<int>(n), l, k); } { viennacl::copy(cs2, tmp1); viennacl::copy(ss2, tmp2); givens_prev(vcl_u, tmp1, tmp2, m, l, k); } e[vcl_size_t(l)] = 0.0; e[vcl_size_t(k)] = f; q[vcl_size_t(k)] = x; } } viennacl::copy(signs_v, tmp1); change_signs(vcl_v, tmp1, static_cast<int>(n)); // transpose singular matrices again detail::transpose(vcl_u); detail::transpose(vcl_v); }
int LSQR(const MatrixType& A, const RhsType& B, SolType& X, krylov_iter_params_t params = krylov_iter_params_t(), const inplace_precond_t<SolType>& R = inplace_id_precond_t<SolType>()) { typedef typename utility::typer_t<MatrixType>::value_type value_t; typedef typename utility::typer_t<MatrixType>::index_type index_t; typedef MatrixType matrix_type; typedef RhsType rhs_type; // Also serves as "long" vector type. typedef SolType sol_type; // Also serves as "short" vector type. typedef utility::print_t<rhs_type> rhs_print_t; typedef utility::print_t<sol_type> sol_print_t; typedef utility::elem_extender_t< typename internal::scalar_cont_typer_t<rhs_type>::type > scalar_cont_type; bool log_lev1 = params.am_i_printing && params.log_level >= 1; bool log_lev2 = params.am_i_printing && params.log_level >= 2; /** Throughout, we will use m, n, k to denote the problem dimensions */ index_t m = base::Height(A); index_t n = base::Width(A); index_t k = base::Width(B); /** Set the parameter values accordingly */ const value_t eps = 32*std::numeric_limits<value_t>::epsilon(); if (params.tolerance<eps) params.tolerance=eps; else if (params.tolerance>=1.0) params.tolerance=(1-eps); else {} /* nothing */ /** Initialize everything */ // We set the grid and rank for beta, and all other scalar containers // just copy from him to get that to be set right (not for the values). rhs_type U(B); scalar_cont_type beta(internal::scalar_cont_typer_t<rhs_type>::build_compatible(k, 1, U)); scalar_cont_type i_beta(beta); base::ColumnNrm2(U, beta); for (index_t i=0; i<k; ++i) i_beta[i] = 1 / beta[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, i_beta, U); rhs_print_t::apply(U, "U Init", params.am_i_printing, params.debug_level); sol_type V(X); // No need to really copy, just want sizes&comm correct. base::Gemm(elem::ADJOINT, elem::NORMAL, 1.0, A, U, V); R.apply_adjoint(V); scalar_cont_type alpha(beta), i_alpha(beta); base::ColumnNrm2(V, alpha); for (index_t i=0; i<k; ++i) i_alpha[i] = 1 / alpha[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, i_alpha, V); sol_type Z(V); R.apply(Z); sol_print_t::apply(V, "V Init", params.am_i_printing, params.debug_level); /* Create W=Z and X=0 */ base::Zero(X); sol_type W(Z); scalar_cont_type phibar(beta), rhobar(alpha), nrm_r(beta); // /!\ Actually copied for init scalar_cont_type nrm_a(beta), cnd_a(beta), sq_d(beta), nrm_ar_0(beta); base::Zero(nrm_a); base::Zero(cnd_a); base::Zero(sq_d); elem::Hadamard(alpha, beta, nrm_ar_0); /** Return from here */ for (index_t i=0; i<k; ++i) if (nrm_ar_0[i]==0) return 0; scalar_cont_type nrm_x(beta), sq_x(beta), z(beta), cs2(beta), sn2(beta); elem::Zero(nrm_x); elem::Zero(sq_x); elem::Zero(z); elem::Zero(sn2); for (index_t i=0; i<k; ++i) cs2[i] = -1.0; int max_n_stag = 3; std::vector<int> stag(k, 0); /* Reset the iteration limit if none was specified */ if (0>params.iter_lim) params.iter_lim = std::max(20, 2*std::min(m,n)); /* More varaibles */ sol_type AU(X); scalar_cont_type minus_beta(beta), rho(beta); scalar_cont_type cs(beta), sn(beta), theta(beta), phi(beta); scalar_cont_type phi_by_rho(beta), minus_theta_by_rho(beta), nrm_ar(beta); scalar_cont_type nrm_w(beta), sq_w(beta), gamma(beta); scalar_cont_type delta(beta), gambar(beta), rhs(beta), zbar(beta); /** Main iteration loop */ for (index_t itn=0; itn<params.iter_lim; ++itn) { /** 1. Update u and beta */ elem::Scal(-1.0, alpha); // Can safely overwrite based on subseq ops. base::DiagonalScale(elem::RIGHT, elem::NORMAL, alpha, U); base::Gemm(elem::NORMAL, elem::NORMAL, 1.0, A, Z, 1.0, U); base::ColumnNrm2(U, beta); for (index_t i=0; i<k; ++i) i_beta[i] = 1 / beta[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, i_beta, U); /** 2. Estimate norm of A */ for (index_t i=0; i<k; ++i) { double a = nrm_a[i], b = alpha[i], c = beta[i]; nrm_a[i] = sqrt(a*a + b*b + c*c); } /** 3. Update v */ for (index_t i=0; i<k; ++i) minus_beta[i] = -beta[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, minus_beta, V); base::Gemm(elem::ADJOINT, elem::NORMAL, 1.0, A, U, AU); R.apply_adjoint(AU); base::Axpy(1.0, AU, V); base::ColumnNrm2(V, alpha); for (index_t i=0; i<k; ++i) i_alpha[i] = 1 / alpha[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, i_alpha, V); Z = V; R.apply(Z); /** 4. Define some variables */ for (index_t i=0; i<k; ++i) { rho[i] = sqrt((rhobar[i]*rhobar[i]) + (beta[i]*beta[i])); cs[i] = rhobar[i]/rho[i]; sn[i] = beta[i]/rho[i]; theta[i] = sn[i]*alpha[i]; rhobar[i] = -cs[i]*alpha[i]; phi[i] = cs[i]*phibar[i]; phibar[i] = sn[i]*phibar[i]; } /** 5. Update X and W */ for (index_t i=0; i<k; ++i) phi_by_rho[i] = phi[i]/rho[i]; base::Axpy(phi_by_rho, W, X); sol_print_t::apply(X, "X", params.am_i_printing, params.debug_level); for (index_t i=0; i<k; ++i) minus_theta_by_rho[i] = -theta[i]/rho[i]; base::DiagonalScale(elem::RIGHT, elem::NORMAL, minus_theta_by_rho, W); base::Axpy(1.0, Z, W); sol_print_t::apply(W, "W", params.am_i_printing, params.debug_level); /** 6. Estimate norm(r) */ nrm_r = phibar; /** 7. estimate of norm(A'*r) */ index_t cond_s1 = 0, cond_s2 = 0; for (index_t i=0; i<k; ++i) { nrm_ar[i] = std::abs(phibar[i]*alpha[i]*cs[i]); if (log_lev2) params.log_stream << "LSQR: Iteration " << i << "/" << itn << ": " << nrm_ar[i] << std::endl; if (nrm_ar[i]<(params.tolerance*nrm_ar_0[i])) cond_s1++; if (nrm_ar[i]<(eps*nrm_a[i]*nrm_r[i])) cond_s2++; } /** 8. check convergence */ if (cond_s1 == k) { if (log_lev1) params.log_stream << "LSQR: Convergence (S1)!" << std::endl; return -2; } if (cond_s2 == k) { if (log_lev1) params.log_stream << "LSQR: Convergence (S2)!" << std::endl; return -3; } /** 9. estimate of cond(A) */ base::ColumnNrm2(W, nrm_w); for (index_t i=0; i<k; ++i) { sq_w[i] = nrm_w[i]*nrm_w[i]; sq_d[i] += sq_w[i]/(rho[i]*rho[i]); cnd_a[i] = nrm_a[i]*sqrt(sq_d[i]); /** 10. check condition number */ if (cnd_a[i]>(1.0/eps)) { if (log_lev1) params.log_stream << "LSQR: Stopping (S3)!" << std::endl; return -4; } } /** 11. check stagnation */ for (index_t i=0; i<k; ++i) { if (std::abs(phi[i]/rho[i])*nrm_w[i] < (eps*nrm_x[i])) stag[i]++; else stag[i] = 0; if (stag[i] >= max_n_stag) { if (log_lev1) params.log_stream << "LSQR: Stagnation." << std::endl; return -5; } } /** 12. estimate of norm(X) */ for (index_t i=0; i<k; ++i) { delta[i] = sn2[i]*rho[i]; gambar[i] = -cs2[i]*rho[i]; rhs[i] = phi[i] - delta[i]*z[i]; zbar[i] = rhs[i]/gambar[i]; nrm_x[i] = sqrt(sq_x[i] + (zbar[i]*zbar[i])); gamma[i] = sqrt((gambar[i]*gambar[i]) + (theta[i]*theta[i])); cs2[i] = gambar[i]/gamma[i]; sn2[i] = theta[i]/gamma[i]; z[i] = rhs[i]/gamma[i]; sq_x[i] += z[i]*z[i]; } } if (log_lev1) params.log_stream << "LSQR: No convergence within iteration limit." << std::endl; return -6; }
// Return true iff S1 is a prefix of S2 static bool is_prefix(const MString& m1, const MString& m2) { XmString s1 = m1.xmstring(); XmString s2 = m2.xmstring(); XmStringContext c1; XmStringContext c2; XmStringInitContext(&c1, s1); XmStringInitContext(&c2, s2); XmStringComponentType t1 = XmSTRING_COMPONENT_UNKNOWN; XmStringComponentType t2 = XmSTRING_COMPONENT_UNKNOWN; while (t1 != XmSTRING_COMPONENT_END && t2 != XmSTRING_COMPONENT_END) { char *s_text1 = 0; XmStringCharSet s_cs1 = 0; XmStringDirection d1 = XmSTRING_DIRECTION_DEFAULT; XmStringComponentType u1 = XmSTRING_COMPONENT_UNKNOWN; unsigned short ul1 = 0; unsigned char *s_uv1 = 0; t1 = XmStringGetNextComponent(c1, &s_text1, &s_cs1, &d1, &u1, &ul1, &s_uv1); char *s_text2 = 0; XmStringCharSet s_cs2 = 0; XmStringDirection d2 = XmSTRING_DIRECTION_DEFAULT; XmStringComponentType u2 = XmSTRING_COMPONENT_UNKNOWN; unsigned short ul2 = 0; unsigned char *s_uv2 = 0; t2 = XmStringGetNextComponent(c2, &s_text2, &s_cs2, &d2, &u2, &ul2, &s_uv2); // Upon EOF in LessTif 0.82, XmStringGetNextComponent() // returns XmSTRING_COMPONENT_UNKNOWN instead of // XmSTRING_COMPONENT_END. Work around this. if (t1 == XmSTRING_COMPONENT_UNKNOWN && s_uv1 == 0) t1 = XmSTRING_COMPONENT_END; if (t2 == XmSTRING_COMPONENT_UNKNOWN && s_uv2 == 0) t2 = XmSTRING_COMPONENT_END; // Place string values in strings string text1(s_text1 == 0 ? "" : s_text1); string text2(s_text2 == 0 ? "" : s_text2); string cs1(s_cs1 == 0 ? "" : s_cs1); string cs2(s_cs2 == 0 ? "" : s_cs2); string uv1; string uv2; if (s_uv1 != 0) uv1 = string((char *)s_uv1, ul1); if (s_uv2 != 0) uv2 = string((char *)s_uv2, ul2); // Free unused memory XtFree(s_text1); XtFree(s_text2); XtFree(s_cs1); XtFree(s_cs2); XtFree((char *)s_uv1); XtFree((char *)s_uv2); if (t1 != t2) { goto done; // Differing tags } switch (t1) { case XmSTRING_COMPONENT_CHARSET: { if (cs1.empty()) // In LessTif 0.82, XmStringGetNextComponent() cs1 = text1; // swaps CS and TEXT. Work around this. if (cs2.empty()) cs2 = text2; if (cs1 != cs2) goto done; // Differing character sets break; } case XmSTRING_COMPONENT_TEXT: #if XmVersion >= 1002 case XmSTRING_COMPONENT_LOCALE_TEXT: #endif #if XmVersion >= 2000 case XmSTRING_COMPONENT_WIDECHAR_TEXT: #endif { if (text1.empty()) // In LessTif 0.82, XmStringGetNextComponent() text1 = cs1; // swaps CS and TEXT. Work around this. if (text2.empty()) text2 = cs2; if (!text2.contains(text1, 0)) goto done; XmStringComponentType next2 = XmStringPeekNextComponent(c2); // In LessTif 0.82, XmStringPeekNextComponent() returns // XmSTRING_COMPONENT_UNKNOWN instead of // XmSTRING_COMPONENT_END. Work around this. if (next2 != XmSTRING_COMPONENT_END && next2 != XmSTRING_COMPONENT_UNKNOWN) goto done; break; } case XmSTRING_COMPONENT_DIRECTION: { if (d1 != d2) goto done; break; } case XmSTRING_COMPONENT_SEPARATOR: case XmSTRING_COMPONENT_END: { // These are the same by definition break; } case XmSTRING_COMPONENT_UNKNOWN: { if (uv1 != uv2) goto done; // Differing unknown tags break; } default: { break; // Skip everything else } } } done: XmStringFreeContext(c2); XmStringFreeContext(c1); return t1 == XmSTRING_COMPONENT_END; }
int main() { Point p1(-253.357, -123.36); Point p2(-190.03, 216.606); Point p3(-343.349, 286.6); Point p4(141.604, 279.934); Point p5(276.591, -46.7012); Point p6(251.593, -263.347); Point p7(-3.38184, -343.339); Point p8(-380.012, -173.355); Point p9(-98.3726, 39.957); Point p10(133.271, 124.949); Point p11(289.923, 301.598); Point p12(421.577, 23.292); Point p13(79.9434, -93.3633); Point p14(-40.0449, 366.592); Point p15(311.587, 374.924); Point p16(431.576, 214.94); Point p17(426.576, -131.693); Point p18(-265.023, -285.011); Point p19(369.915, 89.9521); Point p20(368.249, -15.0376); Point p21(484.904, 18.2925); Point p22(-411.675, 283.267); Point p23(-250.024, 124.949); Point p24(-80.041, -78.3647); Point p25(-360.014, 31.6245); Point p26(-305.019, 356.593); // built Delaunay triangulation PS.insert(p1); PS.insert(p2); PS.insert(p3); PS.insert(p4); PS.insert(p5); PS.insert(p6); PS.insert(p7); PS.insert(p8); PS.insert(p9); PS.insert(p10); PS.insert(p11); PS.insert(p12); PS.insert(p13); PS.insert(p14); PS.insert(p15); PS.insert(p16); PS.insert(p17); PS.insert(p18); PS.insert(p19); PS.insert(p20); PS.insert(p21); PS.insert(p22); PS.insert(p23); PS.insert(p24); PS.insert(p25); PS.insert(p26); std::list<Vertex_handle> LV; bool correct = true; // circle emptiness check Circle cs1(Point(-23.3799, 108.284), 1124.78); check_empty checker(cs1); CGAL::range_search(PS,cs1,std::back_inserter(LV),checker,true); if (checker.get_result()) { std::cout << "circle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "circle was empty !\n"; Circle cs2(Point(-255.024, -100.029), 23551); check_empty checker2(cs2); CGAL::range_search(PS,cs2,std::back_inserter(LV),checker2,true); if (checker2.get_result()) std::cout << "circle not empty !\n"; else { std::cout << "circle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } // triangle check Triangle t1(Point(-21.7134, -123.36), Point(84.9429, 74.9536), Point(209.931, -161.69)); Triangle t2(Point(-61.7095, 164.945), Point(-88.3735, 101.618), Point(49.9463, 101.618)); check_empty_triangle tchecker1(t1); CGAL::range_search(PS,t1.vertex(0),t1.vertex(1),t1.vertex(2),std::back_inserter(LV),tchecker1,true); if (tchecker1.get_result()) std::cout << "triangle not empty !\n"; else { std::cout << "triangle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } check_empty_triangle tchecker2(t2); CGAL::range_search(PS,t2.vertex(0),t2.vertex(1),t2.vertex(2),std::back_inserter(LV),tchecker2,true); if (tchecker2.get_result()) { std::cout << "triangle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "triangle was empty !\n"; // rectangle check Rectangle_2 r1(-290.021, -175.022, -125.037, -35.0356); Rectangle_2 r2(-48.3774, 136.614, -23.3799, 251.603); check_empty_rectangle rchecker1(r1); CGAL::range_search(PS,r1.vertex(0),r1.vertex(1),r1.vertex(2),r1.vertex(3),std::back_inserter(LV),rchecker1,true); if (rchecker1.get_result()) std::cout << "rectangle not empty !\n"; else { std::cout << "rectangle was empty !\n"; std::cout << "this is an error !\n"; correct=false; } check_empty_rectangle rchecker2(r2); CGAL::range_search(PS,r2.vertex(0),r2.vertex(1),r2.vertex(2),r2.vertex(3),std::back_inserter(LV),rchecker2,true); if (rchecker2.get_result()) { std::cout << "rectangle not empty !\n"; std::cout << "this is an error !\n"; correct=false; } else std::cout << "rectangle was empty !\n"; if (correct) return 0; return 1; }
template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTime) { typedef typename ComplexSchur<MatrixType>::ComplexScalar ComplexScalar; typedef typename ComplexSchur<MatrixType>::ComplexMatrixType ComplexMatrixType; // Test basic functionality: T is triangular and A = U T U* for(int counter = 0; counter < g_repeat; ++counter) { MatrixType A = MatrixType::Random(size, size); ComplexSchur<MatrixType> schurOfA(A); VERIFY_IS_EQUAL(schurOfA.info(), Success); ComplexMatrixType U = schurOfA.matrixU(); ComplexMatrixType T = schurOfA.matrixT(); for(int row = 1; row < size; ++row) { for(int col = 0; col < row; ++col) { VERIFY(T(row,col) == (typename MatrixType::Scalar)0); } } VERIFY_IS_APPROX(A.template cast<ComplexScalar>(), U * T * U.adjoint()); } // Test asserts when not initialized ComplexSchur<MatrixType> csUninitialized; VERIFY_RAISES_ASSERT(csUninitialized.matrixT()); VERIFY_RAISES_ASSERT(csUninitialized.matrixU()); VERIFY_RAISES_ASSERT(csUninitialized.info()); // Test whether compute() and constructor returns same result MatrixType A = MatrixType::Random(size, size); ComplexSchur<MatrixType> cs1; cs1.compute(A); ComplexSchur<MatrixType> cs2(A); VERIFY_IS_EQUAL(cs1.info(), Success); VERIFY_IS_EQUAL(cs2.info(), Success); VERIFY_IS_EQUAL(cs1.matrixT(), cs2.matrixT()); VERIFY_IS_EQUAL(cs1.matrixU(), cs2.matrixU()); // Test maximum number of iterations ComplexSchur<MatrixType> cs3; cs3.setMaxIterations(ComplexSchur<MatrixType>::m_maxIterationsPerRow * size).compute(A); VERIFY_IS_EQUAL(cs3.info(), Success); VERIFY_IS_EQUAL(cs3.matrixT(), cs1.matrixT()); VERIFY_IS_EQUAL(cs3.matrixU(), cs1.matrixU()); cs3.setMaxIterations(1).compute(A); VERIFY_IS_EQUAL(cs3.info(), size > 1 ? NoConvergence : Success); VERIFY_IS_EQUAL(cs3.getMaxIterations(), 1); MatrixType Atriangular = A; Atriangular.template triangularView<StrictlyLower>().setZero(); cs3.setMaxIterations(1).compute(Atriangular); // triangular matrices do not need any iterations VERIFY_IS_EQUAL(cs3.info(), Success); VERIFY_IS_EQUAL(cs3.matrixT(), Atriangular.template cast<ComplexScalar>()); VERIFY_IS_EQUAL(cs3.matrixU(), ComplexMatrixType::Identity(size, size)); // Test computation of only T, not U ComplexSchur<MatrixType> csOnlyT(A, false); VERIFY_IS_EQUAL(csOnlyT.info(), Success); VERIFY_IS_EQUAL(cs1.matrixT(), csOnlyT.matrixT()); VERIFY_RAISES_ASSERT(csOnlyT.matrixU()); if (size > 1 && size < 20) { // Test matrix with NaN A(0,0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN(); ComplexSchur<MatrixType> csNaN(A); VERIFY_IS_EQUAL(csNaN.info(), NoConvergence); } }
zSHORT OPERATION CompareCell( ZColorItem *pColorItem, zLONG lColumn, zCPCHAR cpcValue, zBOOL bTestBoth ) { if ( (pColorItem->m_lClrFlags & zALWAYS_EQUAL) && lColumn == pColorItem->m_lColumn ) { return( 0 ); } if ( bTestBoth && // check long value as well as string value lColumn && // match any column lColumn != pColorItem->m_lColumn ) { return( -1 ); // not equal } zSHORT nRC; if ( (pColorItem->m_lClrFlags & zNZ) == zNZ || // null or zero (pColorItem->m_lClrFlags & zNN) == zNN ) // not null/zero { zPCHAR pch = (zPCHAR) cpcValue; while ( pch && *pch && (*pch == '0' || *pch == '.' || isspace( *pch )) ) pch++; if ( pch && *pch ) { if ( (pColorItem->m_lClrFlags & zNZ) == zNZ ) // null or zero return( -1 ); // it is N0T null or zero else // if ( (pColorItem->m_lClrFlags & zNN) == zNN ) // not null/zero return( 0 ); // it is not null/zero } else { if ( (pColorItem->m_lClrFlags & zNZ) == zNZ ) // null or zero return( 0 ); // it is null or zero else // if ( (pColorItem->m_lClrFlags & zNN) == zNN ) // not null/zero return( -1 ); } } else if ( pColorItem->m_lClrFlags & zNUMERIC_COMPARE ) // vs. string compare { double d1 = atof( cpcValue ); double d2 = atof( pColorItem->m_csValue ); d1 -= d2; if ( d1 < 0 ) nRC = -1; else if ( d1 == 0 ) nRC = 0; else if ( d1 > 0 ) nRC = 1; } else if ( pColorItem->m_lClrFlags & 0x000f0000 ) // contains, starts with (NOT) { CString cs1( pColorItem->m_csValue ); CString cs2( cpcValue ); cs1.MakeUpper( ); cs2.MakeUpper( ); int nFind = cs2.Find( cs1 ); nRC = -1; if ( nFind >= 0 ) { if ( (pColorItem->m_lClrFlags & zIN) == zIN ) // in (contains) nRC = 0; else if ( nFind == 0 ) { if ( (pColorItem->m_lClrFlags & zSW) == zSW ) // starts with nRC = 0; } else { if ( (pColorItem->m_lClrFlags & zNS) == zNS ) // does not start with nRC = 0; } } else if ( (pColorItem->m_lClrFlags & zNI) == zNI || // not in (does not contain) (pColorItem->m_lClrFlags & zNS) == zNS ) // does not start with { nRC = 0; } return( nRC ); } else { if ( (pColorItem->m_lClrFlags & zIGNORE_CASE) == zIGNORE_CASE ) nRC = zstricmp( cpcValue, pColorItem->m_csValue ); else nRC = zstrcmp( cpcValue, pColorItem->m_csValue ); } switch ( pColorItem->m_lClrFlags & 0x0fff0000 ) { case zLT: // less than if ( nRC < 0 ) nRC = 0; else nRC = -1; break; case zLE: // less than or equal if ( nRC <= 0 ) nRC = 0; else nRC = -1; break; case zGE: // greater than or equal if ( nRC >= 0 ) nRC = 0; else nRC = -1; break; case zGT: // greater than if ( nRC > 0 ) nRC = 0; else nRC = -1; break; case zNE: // not equal if ( nRC ) nRC = 0; else nRC = -1; break; default: case zEQ: // equal (default) break; } return( nRC ); }