MyPluralFormsNode* MyPluralFormsParser::relationalExpression() { MyPluralFormsNode* p = multiplicativeExpression(); if (p == NULL) return NULL; MyPluralFormsNodePtr n(p); if (token().type() == MyPluralFormsToken::T_GREATER || token().type() == MyPluralFormsToken::T_LESS || token().type() == MyPluralFormsToken::T_GREATER_OR_EQUAL || token().type() == MyPluralFormsToken::T_LESS_OR_EQUAL) { MyPluralFormsNodePtr qn(new MyPluralFormsNode(token())); if (!nextToken()) { return NULL; } p = multiplicativeExpression(); if (p == NULL) { return NULL; } qn->setNode(1, p); qn->setNode(0, n.release()); return qn.release(); } return n.release(); }
static F* take_square_matrix(K x_, I* n, int* triangular, S* err) { K x = convert_FF(x_); if (!likely(x && (*n = qnw(x)))) { *n = 0; if (!*err) *err = "type"; } F* a = alloc_FF(n, *n, err); repeat (j, *n) if (qn(qK(x, j)) != *n) { *n = 0; if (!*err) *err = "length"; } if (triangular) { int upper = 1, lower = 1; repeat (j, *n) repeat (i, *n) if ((a[j + i * *n] = qF(qK(x, j), i))) if (i < j) // non-zero below diagonal, so not upper upper = 0; else if (i > j) // non-zero above diagonal, so not lower lower = 0; *triangular = upper ? 1 : lower ? -1 : 0; } else
MyPluralFormsNode* MyPluralFormsParser::equalityExpression() { MyPluralFormsNode* p = relationalExpression(); if (p == NULL) return NULL; MyPluralFormsNodePtr n(p); if (token().type() == MyPluralFormsToken::T_EQUAL || token().type() == MyPluralFormsToken::T_NOT_EQUAL) { MyPluralFormsNodePtr qn(new MyPluralFormsNode(token())); if (!nextToken()) { return NULL; } p = relationalExpression(); if (p == NULL) { return NULL; } qn->setNode(1, p); qn->setNode(0, n.release()); return qn.release(); } return n.release(); }
MyPluralFormsNode* MyPluralFormsParser::expression() { MyPluralFormsNode* p = logicalOrExpression(); if (p == NULL) return NULL; MyPluralFormsNodePtr n(p); if (token().type() == MyPluralFormsToken::T_QUESTION) { MyPluralFormsNodePtr qn(new MyPluralFormsNode(token())); if (!nextToken()) { return 0; } p = expression(); if (p == 0) { return 0; } qn->setNode(1, p); if (token().type() != MyPluralFormsToken::T_COLON) { return 0; } if (!nextToken()) { return 0; } p = expression(); if (p == 0) { return 0; } qn->setNode(2, p); qn->setNode(0, n.release()); return qn.release(); } return n.release(); }
MyPluralFormsNode* MyPluralFormsParser::multiplicativeExpression() { MyPluralFormsNode* p = pmExpression(); if (p == NULL) return NULL; MyPluralFormsNodePtr n(p); if (token().type() == MyPluralFormsToken::T_REMINDER) { MyPluralFormsNodePtr qn(new MyPluralFormsNode(token())); if (!nextToken()) { return NULL; } p = pmExpression(); if (p == NULL) { return NULL; } qn->setNode(1, p); qn->setNode(0, n.release()); return qn.release(); } return n.release(); }
bool MomentumEstimator::putSpecial(xmlNodePtr cur, ParticleSet& elns, bool rootNode) { OhmmsAttributeSet pAttrib; string hdf5_flag="yes"; pAttrib.add(hdf5_flag,"hdf5"); pAttrib.add(M,"samples"); pAttrib.put(cur); hdf5_out = (hdf5_flag=="yes"); // app_log()<<" MomentumEstimator::putSpecial "<<endl; xmlNodePtr kids=cur->children; while (kids!=NULL) { string cname((const char*)(kids->name)); // app_log()<<" MomentumEstimator::cname : "<<cname<<endl; if (cname=="kpoints") { string ctype("manual"); OhmmsAttributeSet pAttrib; pAttrib.add(ctype,"mode"); pAttrib.add(kgrid,"grid"); pAttrib.put(kids); #if OHMMS_DIM==3 int numqtwists(6*kgrid+3); std::vector<int> qk(0); mappedQtonofK.resize(numqtwists,qk); compQ.resize(numqtwists); RealType qn(4.0*M_PI*M_PI*std::pow(Lattice.Volume,-2.0/3.0)); mappedQnorms.resize(numqtwists,qn*0.5/RealType(M)); if (twist[0]==0) mappedQnorms[kgrid]=qn/RealType(M); if (twist[1]==0) mappedQnorms[3*kgrid+1]=qn/RealType(M); if (twist[2]==0) mappedQnorms[5*kgrid+2]=qn/RealType(M); // app_log()<<" Jnorm="<<qn<<endl; Q.resize(numqtwists); for (int i=-kgrid; i<(kgrid+1); i++) { PosType kpt; kpt[0]=i-twist[0]; kpt[1]=i-twist[1]; kpt[2]=i-twist[2]; kpt=Lattice.k_cart(kpt); Q[i+kgrid]=abs(kpt[0]); Q[i+kgrid+(2*kgrid+1)]=abs(kpt[1]); Q[i+kgrid+(4*kgrid+2)]=abs(kpt[2]); } app_log()<<" Using all k-space points with (nx^2+ny^2+nz^2)^0.5 < "<< kgrid <<" for Momentum Distribution."<<endl; app_log()<<" My twist is:"<<twist[0]<<" "<<twist[1]<<" "<<twist[2]<<endl; int indx(0); int kgrid_squared=kgrid*kgrid; for (int i=-kgrid; i<(kgrid+1); i++) { for (int j=-kgrid; j<(kgrid+1); j++) { for (int k=-kgrid; k<(kgrid+1); k++) { if (i*i+j*j+k*k<=kgrid_squared) //if (std::sqrt(i*i+j*j+k*k)<=kgrid) { PosType kpt; kpt[0]=i-twist[0]; kpt[1]=j-twist[1]; kpt[2]=k-twist[2]; //convert to Cartesian: note that 2Pi is multiplied kpt=Lattice.k_cart(kpt); kPoints.push_back(kpt); mappedQtonofK[i+kgrid].push_back(indx); mappedQtonofK[j+kgrid+(2*kgrid+1)].push_back(indx); mappedQtonofK[k+kgrid+(4*kgrid+2)].push_back(indx); indx++; } } } } #endif #if OHMMS_DIM==2 int numqtwists(4*kgrid+2); std::vector<int> qk(0); mappedQtonofK.resize(numqtwists,qk); compQ.resize(numqtwists); RealType qn(2.0*M_PI/std::sqrt(Lattice.Volume)); mappedQnorms.resize(numqtwists,qn*0.5/RealType(M)); if (twist[0]==0) mappedQnorms[kgrid]=qn/RealType(M); if (twist[1]==0) mappedQnorms[3*kgrid+1]=qn/RealType(M); // app_log()<<" Jnorm="<<qn<<endl; Q.resize(numqtwists); for (int i=-kgrid; i<(kgrid+1); i++) { PosType kpt; kpt[0]=i-twist[0]; kpt[1]=i-twist[1]; kpt=Lattice.k_cart(kpt); Q[i+kgrid]=abs(kpt[0]); Q[i+kgrid+(2*kgrid+1)]=abs(kpt[1]); } app_log()<<" Using all k-space points with (nx^2+ny^2)^0.5 < "<< kgrid <<" for Momentum Distribution."<<endl; app_log()<<" My twist is:"<<twist[0]<<" "<<twist[1]<<endl; int indx(0); int kgrid_squared=kgrid*kgrid; for (int i=-kgrid; i<(kgrid+1); i++) { for (int j=-kgrid; j<(kgrid+1); j++) { if (i*i+j*j<=kgrid_squared) //if (std::sqrt(i*i+j*j+k*k)<=kgrid) { PosType kpt; kpt[0]=i-twist[0]; kpt[1]=j-twist[1]; //convert to Cartesian: note that 2Pi is multiplied kpt=Lattice.k_cart(kpt); kPoints.push_back(kpt); mappedQtonofK[i+kgrid].push_back(indx); mappedQtonofK[j+kgrid+(2*kgrid+1)].push_back(indx); indx++; } } } #endif } kids=kids->next; } if (rootNode) { std::stringstream sstr; sstr<<"Kpoints"; for(int i(0); i<OHMMS_DIM; i++) sstr<<"_"<<round(100.0*twist[i]); sstr<<".dat"; ofstream fout(sstr.str().c_str()); fout.setf(ios::scientific, ios::floatfield); fout << "# mag_k "; for(int i(0); i<OHMMS_DIM; i++) fout << "k_"<<i<<" "; fout <<endl; for (int i=0; i<kPoints.size(); i++) { float khere(std::sqrt(dot(kPoints[i],kPoints[i]))); fout<<khere; for(int j(0); j<OHMMS_DIM; j++) fout<<" "<<kPoints[i][j]; fout<<endl; } fout.close(); sstr.str(""); sstr<<"Qpoints"; for(int i(0); i<OHMMS_DIM; i++) sstr<<"_"<<round(100.0*twist[i]); sstr<<".dat"; ofstream qout(sstr.str().c_str()); qout.setf(ios::scientific, ios::floatfield); qout << "# mag_q" << endl; for (int i=0; i<Q.size(); i++) { qout<<Q[i]<<endl; } qout.close(); } nofK.resize(kPoints.size()); norm_nofK=1.0/RealType(M); return true; }
int main() { double w,x,y,z; double ha, angle(M_PI/180.0*60.0); ha = 0.5*angle; w = cos(ha); x = 0.0; y = sin(ha); z = 0.0; creek::Quaternion q0(w,x,y,z); std::cout << q0.w() << ", " << q0.x() << ", " << q0.y() << ", " << q0.z() << std::endl; split(); // q1 -> q0 creek::Quaternion q1(1,0,0,0); creek::Quaternion qs; qs = q1.slerp(0.9, q0); std::cout << qs.w() << ", " << qs.x() << ", " << qs.y() << ", " << qs.z() << std::endl; split(); // Quaternion -> Rotation Matrix (3x3) creek::Matrix3 mat; mat = qs.toRotationMatrix(); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { std::cout << " " << mat(i,j); } std::cout << std::endl; } split(); // Rotation Matrix -> Quaternion creek::Quaternion qm(mat); std::cout << qm.w() << ", " << qm.x() << ", " << qm.y() << ", " << qm.z() << std::endl; split(); // check convert Quaternion <-> Rotation Matrix mat = qm.toRotationMatrix(); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { std::cout << " " << mat(i,j); } std::cout << std::endl; } split(); // 逆クオータニオン creek::Quaternion q_inv = qm.inverse(); // 共役クオータニオン creek::Quaternion q_con = qm.conjugate(); // 回転ベクトルの長さ creek::Quaternion::Scalar norm = qm.norm(); // 正規化 creek::Quaternion qn(2,1,3,4); //qn.normalize(); std::cout << qn.w() << ", " << qn.x() << ", " << qn.y() << ", " << qn.z() << std::endl; creek::Quaternion q_norm = qn.normalized(); std::cout << q_norm.w() << ", " << q_norm.x() << ", " << q_norm.y() << ", " << q_norm.z() << std::endl; split(); // template float <-> double #ifdef USE_CNOID_MODEL Eigen::Quaternion<float> qf(1,2,3,4); #elif defined USE_HRP_MODEL creek_tvmet::Quaternion<float> qf(1,2,3,4); #endif creek::Quaternion qfd(qf); std::cout << qfd.w() << ", " << qfd.x() << ", " << qfd.y() << ", " << qfd.z() << std::endl; #ifdef USE_HRP_MODEL split(); qn.normalize(); qf.normalize(); std::cout << qn.w() << ", " << qn.x() << ", " << qn.y() << ", " << qn.z() << std::endl; std::cout << qf.w() << ", " << qf.x() << ", " << qf.y() << ", " << qf.z() << std::endl; qn = qf.slerp(0.5, qn); std::cout << qn.w() << ", " << qn.x() << ", " << qn.y() << ", " << qn.z() << std::endl; #endif split(); creek::Vector3 vec; vec << 0,1,0; creek::AngleAxis aa(0.6, vec); creek::Quaternion qaa(aa); std::cout << qaa.w() << ", " << qaa.x() << ", " << qaa.y() << ", " << qaa.z() << std::endl; split(); aa = qaa; //aa = mat; std::cout << aa.angle() << std::endl; std::cout << aa.axis()(0) << ", " << aa.axis()(1) << ", " << aa.axis()(2) << std::endl; split(); mat = aa.toRotationMatrix(); std::cout << mat << std::endl; split(); creek::AngleAxis aa2(0.4, creek::Vector3::UnitX()); std::cout << aa2.angle() << std::endl; std::cout << aa2.axis()(0) << ", " << aa2.axis()(1) << ", " << aa2.axis()(2) << std::endl; creek::Vector3 veca, vecb; veca << 1,2,3; vecb << 2,3,4; double dot = veca.dot(vecb); std::cout << dot << std::endl; creek::Vector3 cross; cross = veca.cross(vecb); //cross = veca.normalized(); std::cout << cross << std::endl; std::cout << creek::Vector3::UnitY() << std::endl; split(); creek::Position pos; pos.translation() = creek::Vector3::Zero(); pos.linear() = creek::Matrix3::Identity(); std::cout << pos.translation() << std::endl << pos.linear() << std::endl; return 0; }
/// Computes the normalized quaternion of q QUAT QUAT::normalize(const QUAT& q) { QUAT qn(q); qn.normalize(); return qn; }
// ----------------------------------------------------------------------- // Construct a fully qualified table name. // ----------------------------------------------------------------------- Lng32 AddTableName( const hs_table_type type , const char *table , const char *schema , const char *catalog ) { HSGlobalsClass *hs_globals = GetHSContext(); NAString catName, schName, objName; NAString extName; NAString defaultCat, defaultSch; NAString userLocation; Lng32 retcode = 0; hs_globals->tableType = type; HSLogMan *LM = HSLogMan::Instance(); // SET MPLOC is converted to CQD (setting values for default // attributes MP_SYSTEM, MP_VOLUME, MP_SUBVOLUME). It does not // update the global MPLOC value stored in SqlParser_MPLOC. The // following updates the global MPLOC value to be consistent with // the default attribute values set by SET MPLOC/CQD. ActiveSchemaDB()->getDefaults().getSqlParser_NADefaults(); if (type == GUARDIAN_TABLE) { if (*table == '$') { // Qualify with system name. extName = SqlParser_MPLOC.getSystemName(); extName += "."; extName += table; } else extName = table; hs_globals->tableFormat = SQLMP; } else { // When CQD DEFAULT_SCHEMA_ACCESS_ONLY is on, // users cannot update stats on tables not in the default/public schemas. if ( schema && ActiveSchemaDB()->getDefaults().getToken(DEFAULT_SCHEMA_ACCESS_ONLY)==DF_ON ) { SchemaName objSchName; NAString curSchName(schema); NAString curCatName; objSchName.setSchemaName(curSchName); if (catalog) { curCatName = catalog; objSchName.setCatalogName(curCatName); } else curCatName = ActiveSchemaDB()->getDefaultSchema().getCatalogName(); // If the schema is neither default nor public, // issue inaccessible error. if (!objSchName.matchDefaultPublicSchema()) { NAString dataObj(curCatName); if (!dataObj.isNull()) dataObj += "."; dataObj += curSchName + "."; dataObj += table; HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, dataObj.data()); retcode = -1; HSHandleError(retcode); } } if (catalog) catName = catalog; else { // LCOV_EXCL_START :nsk if (SqlParser_NAMETYPE == DF_NSK) { catName = SqlParser_MPLOC.getSysDotVol(); hs_globals->tableType = GUARDIAN_TABLE; hs_globals->tableFormat = SQLMP; } else // LCOV_EXCL_STOP catName = ActiveSchemaDB()->getDefaultSchema().getCatalogName(); } if (schema) schName = schema; else { // LCOV_EXCL_START :nsk if (SqlParser_NAMETYPE == DF_NSK) { schName = SqlParser_MPLOC.getSubvolName(); hs_globals->tableFormat = SQLMP; } else // LCOV_EXCL_STOP schName = ActiveSchemaDB()->getDefaultSchema().getSchemaName(); } objName = table; extName = catName + "." + schName + "." + objName; } // LCOV_EXCL_START :nsk if (hs_globals->tableFormat == SQLMP) { ComMPLoc loc(extName, ComMPLoc::FILE); if (loc.getFormat() == ComMPLoc::INVALID) { HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } catName = loc.getSysDotVol(); schName = loc.getSubvolName(); objName = loc.getFileName(); } // LCOV_EXCL_STOP hs_globals->objDef = NULL; // Search in volatile schema first. If not found, search in regular cat/sch. if ((CmpCommon::context()->sqlSession()->volatileSchemaInUse()) && (type != GUARDIAN_TABLE) && (! catalog)) { // search using the volatile schema name. NAString &volCatName = CmpCommon::context()->sqlSession()->volatileCatalogName(); NAString &volSchName = CmpCommon::context()->sqlSession()->volatileSchemaName(); NAString volObjName = table; ComObjectName volIntName(volCatName, volSchName, volObjName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (NOT volIntName.isValid()) { LM->Log("***[ERROR] Unable to create an ObjectClass"); HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } if (LM->LogNeeded()) { LM->Log("Searching in volatile schema, since catalog not specified.\n"); sprintf(LM->msg, "Checking volatile name (volIntName) %s.%s.%s\n", volIntName.getCatalogNamePart().getInternalName().data(), volIntName.getSchemaNamePart().getInternalName().data(), volIntName.getObjectNamePart().getInternalName().data()); LM->Log(LM->msg); } hs_globals->objDef = HSTableDef::create(STMTHEAP, volIntName, hs_globals->tableType, hs_globals->nameSpace); if (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO)) { // now look into the regular schema delete hs_globals->objDef; hs_globals->objDef = NULL; } else { // if schema name was specified, validate that it is the // current username. if (schema) { QualifiedName qn(volObjName, schName); if (NOT CmpCommon::context()->sqlSession()->validateVolatileQualifiedName(qn)) { // table was found in the volatile schema but it is // not a valid volatile name. // Look for it in regular schema. // error info was moved to CmpCommon::diags. Clear it. CmpCommon::diags()->clear(); delete hs_globals->objDef; hs_globals->objDef = NULL; } } } } if (hs_globals->objDef == NULL) { ComObjectName intName(catName, schName, objName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (NOT intName.isValid()) { LM->Log("***[ERROR] Unable to create an ObjectClass"); HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } hs_globals->objDef = HSTableDef::create(STMTHEAP, intName, hs_globals->tableType, hs_globals->nameSpace); // try public schema if an object is not qualified and not found if ((NOT schema) && (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO))) { NAString pubSch = ActiveSchemaDB()->getDefaults().getValue(PUBLIC_SCHEMA_NAME); ComSchemaName pubSchema(pubSch); if (NOT pubSchema.getSchemaNamePart().isEmpty()) { NAString pubSchName = pubSchema.getSchemaNamePart().getInternalName(); NAString pubCatName = (pubSchema.getCatalogNamePart().isEmpty() ? catName:pubSchema.getCatalogNamePart().getInternalName()); ComObjectName pubIntName(pubCatName, pubSchName, objName, COM_UNKNOWN_NAME, ComAnsiNamePart::INTERNAL_FORMAT); if (pubIntName.isValid()) { HSTableDef *pubObjDef = HSTableDef::create(STMTHEAP, pubIntName, hs_globals->tableType, hs_globals->nameSpace); if (pubObjDef->objExists(HSTableDef::MAX_INFO)) { hs_globals->objDef = pubObjDef; } } } } if (NOT hs_globals->objDef->objExists(HSTableDef::MAX_INFO)) { HSFuncMergeDiags(-UERR_OBJECT_INACCESSIBLE, extName); retcode = -1; HSHandleError(retcode); } } //10-040123-2660 We only support tables. We do not allow views. // Tables can be metadata tables. if ((hs_globals->objDef->getObjectType() != COM_BASE_TABLE_OBJECT) && (hs_globals->objDef->getObjectType() != COM_MV_OBJECT)) { HSFuncMergeDiags(-UERR_INVALID_OBJECT, extName); retcode = -1; HSHandleError(retcode); } retcode = hs_globals->objDef->getColumnNames(); HSFuncExecQuery("CONTROL QUERY DEFAULT DISPLAY_DIVISION_BY_COLUMNS RESET"); HSHandleError(retcode); hs_globals->tableFormat = hs_globals->objDef->getObjectFormat(); *hs_globals->catSch = hs_globals->objDef->getPrimaryLoc(HSTableDef::EXTERNAL_FORMAT); *hs_globals->user_table = hs_globals->objDef->getObjectFullName(); hs_globals->tableFormat = hs_globals->objDef->getObjectFormat(); hs_globals->isHbaseTable = HSGlobalsClass::isHbaseCat(catName); if (hs_globals->tableFormat == SQLMX) { // Determine the schema version for this MX table. if (LM->LogNeeded()) { sprintf(LM->msg, "\nCHECK SCHEMA VERSION FOR TABLE: %s\n", hs_globals->user_table->data()); LM->Log(LM->msg); } HSGlobalsClass::schemaVersion = getTableSchemaVersion(hs_globals->user_table->data()); // LCOV_EXCL_START :rfi if (HSGlobalsClass::schemaVersion == COM_VERS_UNKNOWN) { HSFuncMergeDiags(-UERR_INTERNAL_ERROR, "GET_SCHEMA_VERSION"); return -1; } // LCOV_EXCL_STOP if (HSGlobalsClass::schemaVersion >= COM_VERS_2300) HSGlobalsClass::autoInterval = CmpCommon::getDefaultLong(USTAT_AUTOMATION_INTERVAL); if (LM->LogNeeded()) { sprintf(LM->msg, "\nUpdateStats: TABLE: %s; SCHEMA VERSION: %d; AUTOMATION INTERVAL: %d\n", hs_globals->user_table->data(), HSGlobalsClass::schemaVersion, HSGlobalsClass::autoInterval); LM->Log(LM->msg); } const char* period = strchr(hs_globals->catSch->data(), '.'); NAString catName(hs_globals->catSch->data(), period - hs_globals->catSch->data()); NABoolean isHbaseOrHive = HSGlobalsClass::isHbaseCat(catName) || HSGlobalsClass::isHiveCat(catName); *hs_globals->hstogram_table = getHistogramsTableLocation(hs_globals->catSch->data(), FALSE); if (isHbaseOrHive) hs_globals->hstogram_table->append(".").append(HBASE_HIST_NAME); else hs_globals->hstogram_table->append(".HISTOGRAMS"); *hs_globals->hsintval_table = getHistogramsTableLocation(hs_globals->catSch->data(), FALSE); if (isHbaseOrHive) hs_globals->hsintval_table->append(".").append(HBASE_HISTINT_NAME); else hs_globals->hsintval_table->append(".HISTOGRAM_INTERVALS"); } else { // LCOV_EXCL_START :nsk *hs_globals->hstogram_table = hs_globals->objDef->getCatalogLoc(HSTableDef::EXTERNAL_FORMAT); hs_globals->hstogram_table->append(".HISTOGRM"); *hs_globals->hsintval_table = hs_globals->objDef->getCatalogLoc(HSTableDef::EXTERNAL_FORMAT); hs_globals->hsintval_table->append(".HISTINTS"); // RESET CQDS: HSFuncExecQuery("CONTROL QUERY DEFAULT DETAILED_STATISTICS RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT ALLOW_DP2_ROW_SAMPLING RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT POS RESET"); HSFuncExecQuery("CONTROL QUERY DEFAULT POS_NUM_OF_PARTNS RESET"); // LCOV_EXCL_STOP } return 0; }