/* <Parameter> ::= <IDs> : <Qualifier> */ bool SyntaxAnalyzer::Parameter() { if(IDs()) { if(rrr == s_colon) { NextRecord(); if(Qualifier()) { logger.Log("<Parameter> ::= <IDs> : <Qualifier>"); return true; } else { insert(k_int); return true; } } else { insert(s_colon); return true; } } else { // no error return false; } }
/// Creates a slaw that fully describes a Leap Gesture Slaw ToSlaw (Leap::Gesture const& g) const { Slaw out = Slaw::Map ("id", g . id (), "dur", g . duration (), "dursec", g . durationSeconds (), "hands", IDs (g . hands ()), "pntrs", IDs (g . pointables ()), "state", ToSlaw (g . state ())); switch (g . type ()) { case Leap::Gesture::TYPE_SWIPE: return ToSlaw ((Leap::SwipeGesture const&) g, out); case Leap::Gesture::TYPE_CIRCLE: return ToSlaw ((Leap::CircleGesture const&) g, out); case Leap::Gesture::TYPE_SCREEN_TAP: return ToSlaw ((Leap::ScreenTapGesture const&) g, out); case Leap::Gesture::TYPE_KEY_TAP: return ToSlaw ((Leap::KeyTapGesture const&) g, out); default: out = out . MapPut ("type", "invalid"); return out; } }
int main(int argc, char * argv []) { const int n = argc > 1 ? atoi(argv[1]) : 1000000; fprintf(stderr, " -- writing %d particles -- \n", n); assert(n > 16); MPI_Init(&argc, &argv); int rank, nrank; MPI_Comm_rank (MPI_COMM_WORLD, &rank); MPI_Comm_size (MPI_COMM_WORLD, &nrank); const MPI_Comm MPI_WORKING_WORLD = MPI_COMM_WORLD; std::vector<real4> pos(n), vel(n); std::vector<int> IDs(n); for (int i = 0; i < n ; i++) { const float fi = i; pos[i] = (real4){ fi, fi+1.0f, fi-1.0f, -fi-1.0f}; vel[i] = (real4){2.0f*fi, 2.0f*fi+1.0f, 2.0f*fi-1.0f, -2.0f*fi-1.0f}; IDs[i] = 3*i-2; } const float time = 0.125; std::string fileName; fileName.resize(256); MPI_Barrier(MPI_WORKING_WORLD); const double t0 = rtc(); #ifndef _SION_ sprintf(&fileName[0], "%s_%010.4f-%d", "naive_test", time, rank); const size_t nbytes = write_snapshot( &pos[0], &vel[0], &IDs[0], n, fileName, time, rank, nrank, MPI_WORKING_WORLD); #else sprintf(&fileName[0], "%s_%010.4f-%d", "sion_test", time, nrank); const size_t nbytes = sion_write_snapshot( &pos[0], &vel[0], &IDs[0], n, fileName, time, rank, nrank, MPI_WORKING_WORLD); #endif MPI_Barrier(MPI_WORKING_WORLD); const double t1 = rtc(); if (rank == 0) fprintf(stderr, " -- writing took %g sec -- BW= %g MB/s\n", (t1-t0), nbytes/1e6/(t1-t0)); MPI_Finalize(); }
bool syntaxparser::Declaration(){ bool bDeclaration = false; if (displayFlag){ cout << "<Declaration> ::= <Qualifier> <IDs>" << endl; printproduction("<Declaration> ::= <Qualifier> <IDs>"); } cout<<endl; Qualifier(); cout<<endl; IDs(); bDeclaration = true; return bDeclaration; }
/* <IDs Prime> ::= , <IDs> | epsilon */ void SyntaxAnalyzer::IDsPrime() { if(rrr == s_comma) { NextRecord(); IDs(); logger.Log("<IDs Prime> ::= , <IDs>"); } else { logger.Log("<IDs Prime> ::= epsilon"); } }
/* <Declaration> ::= <Qualifier> <IDs> */ bool SyntaxAnalyzer::Declaration() { if(Qualifier()) { IDs(); logger.Log("<Declaration> ::= <Qualifier> <IDs>"); return true; } else { return false; } }
bool syntaxparser::Parameter(){ bool Parameter = false; if (displayFlag){ cout<<"<Parameter> ::= <IDS> : <Qualifier>"<<endl; printproduction("<Parameter> ::= <IDS> : <Qualifier>"); } IDs(); if(lexeme ==":"){ print(); //print the colon Lexer(); //get next token Qualifier(); Parameter = true; }else{ error("Missing ':'"); } return Parameter; }
/* <Read> ::= scan ( <IDs> ); */ bool SyntaxAnalyzer::Read() { if(rrr == k_scan) { NextRecord(); if(rrr == s_openbracketround) { NextRecord(); IDs(); if(rrr == s_closebracketround) { NextRecord(); if(rrr == s_semicolon) { NextRecord(); logger.Log("<Read> ::= scan ( <IDs> );"); return true; } else { insert(s_semicolon); return true; } } else { insert(s_closebracketround); return true; } } else { insert(s_openbracketround); return true; } } else { // no error return false; } }
// Purpose: Tests the production rule for Read bool syntaxparser::Read(){ bool bRead = false; if (lexeme == "read"){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<Read> ::= read ( <IDs> );" << endl; printproduction("<Read> ::= read ( <IDs> );"); } if (lexeme == "("){ print(); cout<<endl; Lexer(); string temp_id; temp_id = lexeme; IDs(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); if (lexeme == ";"){ print(); cout<<endl; project3.gen_inst("PUSHSTD", ""); string addr; addr = project3.get_address(temp_id); project3.gen_inst("POPM", addr); Lexer(); bRead = true; }else error("Missing ';'"); }else error("Missing ')'"); } } return bRead; }
// Purpose: Tests the production rule for IDs bool syntaxparser::IDs(){ bool bIDs = false; if(token == "identifier"){ if(project3.checkDuplicates(lexeme)){ project3.addIdentifier(lexeme); } else error("Already declared variable"); print(); Lexer(); if (displayFlag){ cout << "<IDs> ::= <Identifier>"<<endl; printproduction("<IDs> ::= <Identifier>"); } if (lexeme == ","){ if (displayFlag){ cout << "<IDs> ::= <Identifier>, <IDs>" << endl; printproduction("<IDs> ::= <Identifier>, <IDs>"); } print(); // print out the comma Lexer(); // get the next token to see if ID //print(); // print out the next token, which should be an identifier IDs(); bIDs = true; } bIDs = true; } else error("Missing Identifier"); return bIDs; }
/* <PrimaryPrime> ::= [<IDs>] | epsilon */ void SyntaxAnalyzer::PrimaryPrime() { if(rrr == s_openbracketsquare) { NextRecord(); IDs(); if(rrr == s_closebracketsquare) { NextRecord(); // log logger.Log("<PrimaryPrime> ::= [<IDs>]"); } else { insert(s_closebracketsquare); } } else { logger.Log("<PrimaryPrime> ::= epsilon"); } }
bool syntaxparser::Primary(){ bool Primary = false, flag=true; if(token == "identifier" ){ print(); cout<<endl; //check to see if the lexeme is either true or false if (lexeme == "true") { project3.gen_inst("PUSHI", "1"); } else if (lexeme == "false") { project3.gen_inst("PUSHI", "0"); } else{ string integer_addr; integer_addr = project3.get_address(lexeme); project3.gen_inst("PUSHM",integer_addr); } Lexer(); if(lexeme == "["){ print(); cout<<endl; Lexer(); if(displayFlag){ cout<<"<Primary> ::= <identifier> [ <IDs> ]"<<endl; printproduction("<Primary> ::= <identifier> [ <IDs> ]"); } // pushes the index of that array string index; index = project3.get_address(lexeme); project3.gen_inst("PUSHM", index); IDs(); if(lexeme == "]"){ print(); cout<<endl; Lexer(); Primary = true; flag = false; }else error("Missing ']'"); } if( flag == true){ Primary = true; if(displayFlag){ cout<<"<Primary> ::= <identifier>"<<endl; printproduction("<Primary> ::= <identifier>"); } } }else if(token == "integer"){ print(); cout<<endl; project3.gen_inst("PUSHI", lexeme); Lexer(); Primary = true; if(displayFlag){ cout<<"<Primary> ::= <integer>"<<endl; printproduction("<Primary> ::= <integer>"); } }else if(lexeme == "("){ print(); cout<<endl; Lexer(); if(displayFlag){ cout << "<Primary> ::= ( <Expression> )" << endl; printproduction("<Primary> ::= ( <Expression> )"); } Expression(); if (lexeme == ")"){ print(); cout<<endl; Lexer(); Primary = true; }else error("Missing ')'"); }/*else if(token == "real"){ print(); cout<<endl; Lexer(); Primary = true; if(displayFlag){ cout<<"<Primary> ::= <real>"<<endl; printproduction("<Primary> ::= <real>"); } }*/else if(lexeme == "true"){ project3.gen_inst("PUSHI", "1"); print(); cout<<endl; Lexer(); Primary = true; if(displayFlag){ cout<<"<Primary> ::= <true>"<<endl; printproduction("<Primary> ::= <true>"); } }else if(lexeme == "false"){ project3.gen_inst("PUSHI", "0"); print(); cout<<endl; Lexer(); Primary = true; if(displayFlag){ cout<<"<Primary> ::= <false>"<<endl; printproduction("<Primary> ::= <false>"); } }else error("Missing Primary"); return Primary; }
/*===========================================================================*/ void KMeans::run() { if ( m_input_table.empty() ) { kvsMessageError("Input table data is not assigned."); return; } const size_t ncolumns = m_input_table.columnSize(); const size_t nrows = m_input_table.column(0).size(); for ( size_t i = 1; i < m_input_table.columnSize(); i++ ) { if ( nrows != m_input_table.column(i).size() ) { kvsMessageError("The number of rows is different between each column."); return; } } // Allocate memory for the cluster center. m_cluster_centers = new kvs::ValueArray<kvs::Real32> [ m_nclusters ]; for ( size_t i = 0; i < m_nclusters; i++ ) { m_cluster_centers[i].allocate( ncolumns ); } // Assign initial cluster IDs to each row of the input table randomly. kvs::ValueArray<kvs::UInt32> IDs( nrows ); for ( size_t i = 0; i < nrows; i++ ) IDs[i] = kvs::UInt32( m_nclusters * m_random() ); // Calculate the center of cluster. switch ( m_seeding_method ) { case RandomSeeding: ::InitializeCentersWithRandomSeeding( m_input_table, m_nclusters, IDs, m_cluster_centers ); break; case SmartSeeding: ::InitializeCentersWithSmartSeeding( m_input_table, m_nclusters, IDs, m_cluster_centers ); break; default: ::InitializeCentersWithRandomSeeding( m_input_table, m_nclusters, IDs, m_cluster_centers ); break; } // Cluster center used for convergence test. kvs::ValueArray<kvs::Real32> center_new( ncolumns ); // Clustering. bool converged = false; size_t counter = 0; while ( !converged ) { // Calculate euclidean distance between the center of cluster and the point, and update the IDs. for ( size_t i = 0; i < nrows; i++ ) { size_t id = 0; kvs::Real32 distance = kvs::Value<kvs::Real32>::Max(); for ( size_t j = 0; j < m_nclusters; j++ ) { const kvs::Real32 d = ::GetEuclideanDistance( m_input_table, i, m_cluster_centers[j] ); if ( d < distance ) { distance = d; id = j; } } IDs[i] = id; } // Convergence test. converged = true; for ( size_t i = 0; i < m_nclusters; i++ ) { ::CalculateCenter( m_input_table, i, IDs, ¢er_new ); const kvs::Real32 distance = ::GetEuclideanDistance( m_input_table, m_cluster_centers[i], center_new ); if ( !( distance < m_tolerance ) ) { converged = false; break; } } if ( counter++ > m_max_iterations ) break; // Calculate the center of cluster. if ( !converged ) { for ( size_t i = 0; i < m_nclusters; i++ ) { ::CalculateCenter( m_input_table, i, IDs, &(m_cluster_centers[i]) ); } } } // end of while m_cluster_ids = IDs; }