bool FilterManager::uninstallFilter(Filter *filter) { DPTR_D(FilterManager); QMap<AVPlayer*, QList<Filter*> > map1(d.vfilter_player_map); // NB: copy it for iteration because called code may modify map -- which caused crashes QMap<AVPlayer*, QList<Filter*> >::iterator it = map1.begin(); while (it != map1.end()) { if (uninstallVideoFilter(filter, it.key())) return true; ++it; } QMap<AVPlayer *, QList<Filter *> > map2(d.afilter_player_map); // copy to avoid crashes when called-code modifies map it = map2.begin(); while (it != map2.end()) { if (uninstallAudioFilter(filter, it.key())) return true; ++it; } QMap<AVOutput*, QList<Filter*> > map3(d.filter_out_map); // copy to avoid crashes QMap<AVOutput*, QList<Filter*> >::iterator it2 = map3.begin(); while (it2 != map3.end()) { if (uninstallFilter(filter, it2.key())) return true; ++it2; } return false; }
void test_map_exchanges (void) { std::cerr << "************* EXCHANGES: MAPS*************\n"; knowledge::KnowledgeBase knowledge; std::vector <std::string> keys; containers::Map map ("first_map", knowledge); containers::Map map2 ("second_map", knowledge); std::cerr << "Creating two maps...\n"; map.set ("a", "key1 contents"); map.set ("b", "key2 contents"); map.set ("c", "key3 contents"); map2.set ("d", "key4 contents"); map2.set ("e", "key5 contents"); map2.set ("f", "key6 contents"); map2.set ("g", "key7 contents"); std::cerr << "Contents of map before exchange...\n"; knowledge.print (); std::cerr << "Exchanging...\n"; map.exchange (map2); if (!map.exists ("a") && !map.exists ("b") && !map.exists ("c") && !map2.exists ("d") && !map2.exists ("e") && !map2.exists ("f") && !map2.exists ("g") && map["d"] == "key4 contents" && map["e"] == "key5 contents" && map["f"] == "key6 contents" && map2["a"] == "key1 contents" && map2["b"] == "key2 contents" && map2["c"] == "key3 contents") { std::cerr << "SUCCESS. maps were exchanged.\n"; } else { std::cerr << "FAIL. maps were not exchanged properly.\n"; } knowledge.print (); map.exchange (map2, false, false); if (map2.exists ("a") && map2.exists ("b") && map2.exists ("c") && map.exists ("d") && map.exists ("e") && map.exists ("f") && map.exists ("g") && map2["d"] == "key4 contents" && map2["e"] == "key5 contents" && map2["f"] == "key6 contents" && map["a"] == "key1 contents" && map["b"] == "key2 contents" && map["c"] == "key3 contents") { std::cerr << "SUCCESS. maps were exchanged.\n"; } else { std::cerr << "FAIL. maps were not exchanged properly.\n"; } knowledge.print (); }
void MapAlignmentAlgorithmPoseClustering::align(const MSExperiment<> & map, TransformationDescription & trafo) { ConsensusMap map_scene; MSExperiment<> map2(map); MapConversion::convert(1, map2, map_scene, max_num_peaks_considered_); // copy MSExperiment here, since it is sorted internally by intensity align(map_scene, trafo); }
static void GLAPIENTRY _mesa_Map2f( GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points) { map2(target, u1, u2, ustride, uorder, v1, v2, vstride, vorder, points, GL_FLOAT); }
static void GLAPIENTRY _mesa_Map2d( GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points ) { map2(target, (GLfloat) u1, (GLfloat) u2, ustride, uorder, (GLfloat) v1, (GLfloat) v2, vstride, vorder, points, GL_DOUBLE); }
void test6(void) { CS225::Map map1 = complete_binary_tree(3); std::cout << "---ORIGINAL----\n" << map1 << "-------\n" << std::endl; CS225::Map map2(map1); std::cout << "---COPY----\n" << map2 << "-------\n" << std::endl; std::cout << "---MODIFY COPY----\n"; map2[11]=11; std::cout << "---ORIGINAL----\n" << map1 << "-------\n" << std::endl; std::cout << "---COPY----\n" << map2 << "-------\n" << std::endl; }
int main (void) { int i; int a[N], b[N]; for (i=0;i<N;i++) a[i] = i; map2(a,b,N); for (i=0;i<N;i++) printf("%d\n",b[i]); return 0; }
void test4(void) { CS225::Map map1 = complete_binary_tree(3); std::cout << "---ORIGINAL----\n" << map1 << "-------\n" << std::endl; CS225::Map map2(map1); std::cout << "---COPY----\n" << map2 << "-------\n" << std::endl; CS225::Map::iterator b = map2.begin(), e = map2.end(); for ( ; b!=e; ++b) { std::cout << *b << std::endl; } }
void TestVariant::testQMap() { QVariantMap map; map.insert("string", "teststring"); map.insert("integer", 123); Variant var(map); QVariantMap map2(var.toQMap()); QCOMPARE(map, map2); }
static void test_copy(std::vector<T> const& data) { sib::vector_map<T,T> map1; for(std::size_t ii = 0; ii != data.size(); ++ii) map1.insert(std::pair<T,T>(data[ii],data[ii])); sib::vector_map<T,T> map2(const_cast<sib::vector_map<T,T> const&>(map1)); EXPECT_EQ(map1.size(), map2.size()); typename sib::vector_map<T,T>::const_iterator i1 = map1.begin(); typename sib::vector_map<T,T>::const_iterator i2 = map2.begin(); for(std::size_t ii = 0; ii != data.size(); ++ii) EXPECT_TRUE(*(i1++) == *(i2++)); }
void print_map(int menu) //맵 출력 { int i,j; if(menu==0) map=map1(); else if(menu==1) map=map2(); else if(menu==2) map=map3(); for(i=0;i<SERO;i++) { for(j=0;j<GARO;j++) { printf("%c",map[SERO][GARO]); } } }
int main () { RuntimeCmp <int> reverse_order (RuntimeCmp<int>::reverse); IntSet set1; IntSet set2 (reverse_order); set1 = set2; assert (set1.key_comp () == set2.key_comp ()); assert (set1.value_comp () == set2.value_comp ()); IntMap map1; IntMap map2 (reverse_order); map1 = map2; assert (map1.key_comp () == map2.key_comp ()); return 0; }
BOOST_AUTO_TEST_CASE_TEMPLATE (test_map_copy_constructor_1, parameters, test_map_parameters) { COMMON_MAP_TEST_SETUP; map_type map1 (RANGE (value_data::values1 ())); map_type map2 (RANGE (value_data::values2 ())); map_type map3 (map1); map_type map4 (map2); BOOST_CHECK_EQUAL (map3, map1); BOOST_CHECK_EQUAL (map4, map2); if (implementation::stable_order) { assert_identical_order (map3, keys_of (map1)); assert_identical_order (map4, keys_of (map2)); } }
void map_not_aligned_on_scalar() { typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType; typedef typename MatrixType::Index Index; Index size = 11; Scalar* array1 = internal::aligned_new<Scalar>((size+1)*(size+1)+1); Scalar* array2 = reinterpret_cast<Scalar*>(sizeof(Scalar)/2+std::size_t(array1)); Map<MatrixType,0,OuterStride<> > map2(array2, size, size, OuterStride<>(size+1)); MatrixType m2 = MatrixType::Random(size,size); map2 = m2; VERIFY_IS_EQUAL(m2, map2); typedef Matrix<Scalar,Dynamic,1> VectorType; Map<VectorType> map3(array2, size); MatrixType v3 = VectorType::Random(size); map3 = v3; VERIFY_IS_EQUAL(v3, map3); internal::aligned_delete(array1, (size+1)*(size+1)+1); }
// The abover solution uses stl unordered_map and is relatively slow // do not use hash_map bool isIsomorphic(string s, string t) { if (s.length() != t.length()) return false; if (s.length() == 0) return true; vector<int> map1(128, -1); vector<int> map2(128, -1); for (int i = 0; i < s.length() ; i++) { if (map1[s[i]] == map2[t[i]]) { if (map1[s[i]] == -1) { map1[s[i]] = i; map2[t[i]] = i; } } else return false; } return true; }
void Rastercalc::substract(){ Ilwis::IRasterCoverage map1; DOTEST(map1.prepare(makeInputPath("U_1001A.NTF")),"loading erdas imagine file"); Ilwis::IRasterCoverage cov = 100.0 - map1; DOCOMPARE(cov->pix2value(Ilwis::Pixel(0,0)),-25.0,"Checking pix(269,339) for expression number <operator> raster"); map1.prepare("small.mpl"); Ilwis::IRasterCoverage cov4 = map1 + 100; map1.prepare("n000302_sub_kenya.mpr"); Ilwis::IRasterCoverage map2("kenya_2009ndvi_cor_22.mpr"); Ilwis::IRasterCoverage cov2 = map1 + map2 / 3; DOCOMPARE(cov2->pix2value(Ilwis::Pixel(50,50)),148.18,"Checking pix(50,50) for compound expression"); Ilwis::IRasterCoverage cov3 = sqrt(cov2); DOCOMPARE(cov3->pix2value(Ilwis::Pixel(50,50)),12.173,"Checking pix(50,50) for sqrt"); }
int main() { // Transformation or Data Flow Relation dataFlow(2,2); // [i,j] -> [i,j] dataFlow.name_input_var(1, "i"); dataFlow.name_input_var(2, "j"); Variable_ID i = dataFlow.input_var(1); Variable_ID j = dataFlow.input_var(2); dataFlow.name_output_var(1, "I"); dataFlow.name_output_var(2, "J"); Variable_ID I = dataFlow.output_var(1); Variable_ID J = dataFlow.output_var(2); F_And *root = dataFlow.add_and(); EQ_Handle ieq = root->add_EQ(); ieq.update_coef(i,1); ieq.update_coef(I,-1); EQ_Handle jeq = root->add_EQ(); jeq.update_coef(j,1); jeq.update_coef(J,-1); // dataFlow.prefix_print(); cout << "Data Flow:\t"; dataFlow.print_with_subs(stdout); RelTuple R; R.append(dataFlow); Relation IS(2); IS.name_set_var(1, "i"); IS.name_set_var(2, "j"); Free_Var_Decl n("n"); Variable_ID IS_n = IS.get_local(&n); Variable_ID IS_i = IS.set_var(1); Variable_ID IS_j = IS.set_var(2); F_And *IS_root = IS.add_and(); GEQ_Handle imin = IS_root->add_GEQ(); imin.update_coef(IS_i, 1); imin.update_const(-1); GEQ_Handle imax = IS_root->add_GEQ(); imax.update_coef(IS_n,1); imax.update_coef(IS_i, -1); GEQ_Handle jmin = IS_root->add_GEQ(); jmin.update_coef(IS_j, 1); jmin.update_const(-1); GEQ_Handle jmax = IS_root->add_GEQ(); jmax.update_coef(IS_n,1); jmax.update_coef(IS_j, -1); cout << "IS:\t\t"; IS.print_with_subs(stdout); SetTuple S; S.append(IS); Relation norm(2); norm.name_set_var(1, "i"); norm.name_set_var(2, "j"); i = norm.set_var(1); j = norm.set_var(2); F_And *norm_root = norm.add_and(); EQ_Handle equal = norm_root->add_EQ(); equal.update_const(0); cout << "Relation:\t"; norm.print_with_subs(stdout); // creating MMaps MMap mmtest; // { [t,i] -> [i,j] , "a" } //defining mmtest Relation map(2,2); // making it output 2 vars map.name_input_var(1, "i"); map.name_input_var(2, "j"); Variable_ID t1 = map.input_var(1); Variable_ID i1 = map.input_var(2); map.name_output_var(1, "i"); map.name_output_var(2, "j"); // output var 2 Variable_ID x1 = map.output_var(1); Variable_ID y1 = map.output_var(2); // output var 2 F_And *map_root = map.add_and(); EQ_Handle map_xeq = map_root->add_EQ(); // x=i === x-i = 0 map_xeq.update_coef(x1,1); map_xeq.update_coef(t1,-1); EQ_Handle map_yeq = map_root->add_EQ(); // y=t === y-t = 0 map_yeq.update_coef(y1,1); map_yeq.update_coef(i1,-1); mmtest.mapping = map; mmtest.var = "a"; cout << "Memory Map:\t"; map.print_with_subs(stdout); MMap mmtest2; Relation map2(2,1); // making it output 2 vars map2.name_input_var(1, "i"); map2.name_input_var(2, "j"); t1 = map2.input_var(1); i1 = map2.input_var(2); map2.name_output_var(1, "i"); x1 = map2.output_var(1); F_And *map2_root = map2.add_and(); EQ_Handle map2_xeq = map2_root->add_EQ(); // x=i+j === x-i-j = 0 map2_xeq.update_coef(x1,1); map2_xeq.update_coef(t1,-1); map2_xeq.update_coef(i1,-1); mmtest2.mapping = map2; mmtest2.var = "b"; cout << "Memory Map 2:\t"; map2.print_with_subs(stdout); #if 0 // NO LONGER IMPLEMENTED Tuple<MMap> tests; tests.append(mmtest); tests.append(mmtest2); cout << list(tests,"0"); #endif cout << MMGenerateCode(R,S,norm,0); // CG_funkyStringBuilder x; // MMGenerateCode(&x, R, S, norm, 0)->Dump(); /* Example of output function: for i=2 to N a[i] = a[i-1] + 2 IS : 2 <= i <= N MMap : "a", [i]->[i] Reads : 0, [i]->[i+1] Stmt : "w = r1 + 2" */ Relation IS2(1); IS2.name_set_var(1, "i"); IS_n = IS2.get_local(&n); IS_i = IS2.set_var(1); F_And *IS2_root = IS2.add_and(); imin = IS2_root->add_GEQ(); imin.update_coef(IS_i, 1); imin.update_const(-2); imax = IS2_root->add_GEQ(); imax.update_coef(IS_n,1); imax.update_coef(IS_i, -1); cout << "IS:\t\t"; IS2.print_with_subs(stdout); MMap mmtest3; Relation map3(1,1); // making it output 2 vars map3.name_input_var(1, "i"); i1 = map3.input_var(1); map3.name_output_var(1, "i"); x1 = map3.output_var(1); F_And *map3_root = map3.add_and(); EQ_Handle map3_xeq = map3_root->add_EQ(); // x=i === x-i = 0 map3_xeq.update_coef(x1,1); map3_xeq.update_coef(t1,-1); mmtest3.mapping = map3; mmtest3.var = "a"; cout << "Memory Map 3:\t"; map3.print_with_subs(stdout); PartialRead readTest; Relation df(1,1); df.name_input_var(1, "i"); i1 = df.input_var(1); x1 = df.output_var(1); F_And *df_root = df.add_and(); EQ_Handle df_eq = df_root->add_EQ(); df_eq.update_coef(x1,1); df_eq.update_coef(i1,-1); df_eq.update_const(-1); readTest.from = 1; readTest.dataFlow = df; Read oneReadTest; oneReadTest.partials.append(readTest); Tuple<Read> readTuple; readTuple.append(oneReadTest); cout << "Data Flow:\t"; df.print_with_subs(stdout); String stmtTest = "w = r1 + 2"; stm_info testing; testing.IS = IS2; testing.map = mmtest3; testing.read = readTuple; testing.stm = stmtTest; Tuple<stm_info> example; example.append(testing); cout << output(example); } // Main
int main(int argc, char **argv) { std::cout << "Starting SNAKE 2.0" << std::endl; srand (time(NULL)); graphics::init_shadowmap_rotation_matrices(); graphics::set_window_title(WINDOW_TITLE); graphics::set_window_size(WINDOW_WIDTH, WINDOW_HEIGHT); graphics::init_sdl(); if(graphics::init_gl() == -1) { graphics::destroy(); return -1; } graphics::Light light, light2; light.position = math::vec3f(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, -0.2f); light2.position = math::vec3f(WINDOW_WIDTH / 2 + 200, WINDOW_HEIGHT / 2 - 200, -0.2f); light.color = math::vec3f(0.0f, 1.0f, 1.0f); light2.color = math::vec3f(1.0f, 0.2f, 0.5f); light.range = 3; light2.range = 3; graphics::add_light(&light, 1); graphics::add_light(&light2, 1); io::init(); io::add_keyhandler(key_handler); fps_timer.start(); Map map("levels/1/maps/1.map"); Map map2("levels/1/maps/2.map"); while(!map.set_food_tile(rand() % (map.get_width() - 1), rand() % (map.get_height() - 1), 1)) {}; game.add_map(&map, 1); game.add_map(&map2, 0); portal1.mapx = 13; portal1.mapy = 5; portal2.mapx = 32; portal2.mapy = 17; portal1.parent_map = ↦ portal2.parent_map = &map2; printf("&map2: %p\n", &map2); //map.add_portals(portal1, portal2, 0); //map2.add_portals(portal1, portal2, 0); snake.add_element(); game.add_snake(&snake, 1); game.init(); light_timer.start(); bool quit = false; while(!quit) { cap_timer.start(); while(SDL_PollEvent(&sdl_event) != 0) { io::keyboard_update(sdl_event); if(sdl_event.type == SDL_QUIT) { quit = true; } } int fps_ticks = fps_timer.get_ticks(); float avg_fps = counted_frames / (fps_ticks / 1000.f); if(avg_fps > 2000000) avg_fps = 0; // std::cout << "fps: " << avg_fps << std::endl; if(!quit) { graphics::clear(); quit = !game.update(); // std::cout << "updated!" << std::endl; game.render(); // std::cout << "rendered" << std::endl; graphics::render(); // std::cout << "flipped" << std::endl; } ++counted_frames; int frame_ticks = cap_timer.get_ticks(); if(frame_ticks < TICKS_PER_FRAME) { SDL_Delay(TICKS_PER_FRAME - frame_ticks); } if(light_timer.get_ticks() > 1000) { float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float g = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); float b = static_cast <float> (rand()) / static_cast <float> (RAND_MAX); light.color = math::vec3f(r, g, b); light_timer.start(); } } SDL_Delay(1000); map.destroy(); graphics::destroy(); io::destroy(); return 0; }
bool QuickHelp::init( QString &maxPath ) { map()->clear(); map2()->clear(); QFile commands(maxPath + "/docs/html/Modules/commands.txt"); if (!commands.exists()) { return false; } if (commands.open(QIODevice::ReadOnly)) { QTextStream stream(&commands); while (!stream.atEnd()) { QString line = stream.readLine(); int index = line.indexOf("|"); QString left; QString url; if (index >= 0) { left = line.left(index); url = line.mid(index + 1); } index = left.indexOf(" : "); QString topic; int i; for (i=0; i < left.length(); i++) { QChar c = left[i]; if (c == '_') continue; if (c >= '0' && c <= '9') continue; if (c >= 'a' && c <= 'z') continue; if (c >= 'A' && c <= 'Z') continue; break; } topic = left.left(i); QString desc = left.mid(index + 3); QuickHelp * h = new QuickHelp(); h->_topic = topic; h->sig = left.left(index); h->url = "file:///" + maxPath + url; h->descr = desc; h->isGlobal = false; insert( h ); } commands.close(); } /* QString text, line, topic, url, kind, module, descr, classs, tmp, paramsLine; QStringList lines; QuickHelp *h; QString path = QApplication::applicationDirPath()+"/"; if( monkeyPath.isEmpty() ) monkeyPath = path; QFile file0( path+"keywords.txt" ); if( file0.open( QIODevice::ReadOnly ) ) { QTextStream stream( &file0 ); stream.setCodec( "UTF-8" ); text = stream.readAll(); file0.close(); } else { text = "Strict;SuperStrict;Public;Private;" "Byte;Short;Int;Long;Float;Double;Ptr;String;Object;Mod;Continue;Exit;" "Include;Import;Module;Extern;ModuleInfo;" "New;Self;Super;Eachin;True;False;Null;Not;" "Extends;Abstract;Final;Select;Case;Default;Rem;" "Const;Local;Global;Field;Method;Function;Type;Interface;Implements;" "And;Or;Shl;Shr;End;If;Then;Else;Elseif;Endif;While;Wend;Repeat;Until;Forever;For;To;Step;Next;Return;" "Try;Catch;Throw;" "EndModule;EndExtern;EndFor;EndWhile;EndRem;DebugStop;DebugLog;"; } lines = text.split(';'); for( int i = 0 ; i < lines.size() ; ++i ){ topic = lines.at(i); h = new QuickHelp(); h->_topic = topic; h->descr = topic; h->descrForInsert = topic; h->kind = "keyword"; h->isKeyword = true; if( topic=="Include"||topic=="Import"||topic=="Module"||topic=="Extern"|| topic=="New"||topic=="Eachin"|| topic=="Extends"||//topic=="Abstract"||topic=="Final"|| topic=="Select"||topic=="Case"|| topic=="Const"||topic=="Local"||topic=="Global"||topic=="Field"||topic=="Method"||topic=="Function"||topic=="Type"||topic=="Interface"||topic=="Implements"|| topic=="And"||topic=="Or"|| topic=="Until"||topic=="For"||topic=="To"||topic=="Step"|| topic=="Catch"||topic=="Print" ) { h->descrForInsert += " "; } insert( h ); } QFile file( monkeyPath+"/docs/html/index.txt" ); if( file.open( QIODevice::ReadOnly ) ) { QTextStream stream( &file ); stream.setCodec( "UTF-8" ); text = stream.readAll(); file.close(); lines = text.split('\n'); //global values for highlight for( int i = 0 ; i < lines.count() ; ++i ) { line = lines.at( i ).trimmed(); int j = line.lastIndexOf( ':' ); if( j == -1 ) continue; topic = line.left(j); url = "file:///"+monkeyPath+"/docs/html/"+line.mid(j+1); h = help( topic ); if( !h ) { h = new QuickHelp(); } else if( h->isKeyword ) { h->url = url; continue; } h = new QuickHelp(); h->_topic = topic; h->url = url; h->isGlobal = false; insert( h ); } } //all values with detailed description QFile file2( monkeyPath+"/docs/html/decls.txt" ); if( !file2.open( QIODevice::ReadOnly ) ) return false; QTextStream stream2( &file2 ); stream2.setCodec( "UTF-8" ); text = stream2.readAll(); file2.close(); lines = text.split('\n'); for( int i = 0 ; i < lines.count() ; ++i ) { line = lines.at( i ).trimmed(); line = line.left( line.length()-1 ); int j = line.lastIndexOf( ';' ); if( j == -1 ) continue; topic = url = descr = kind = module = classs = paramsLine = ""; descr = line.left(j); url = line.mid(j+1); h = help( topic ); if( !h ) { h = new QuickHelp(); } else if( h->isKeyword ) { continue; } //kind is {function, method, const, ...} j = descr.indexOf( ' ' ); if( j > 0) { kind = descr.left(j); descr = descr.mid(j+1); } if( kind == "Module") { j = topic.lastIndexOf('.'); if(j > 0) { module = topic.left(j); topic = topic.mid(j+1); } else { module = topic = descr; } } else { j = descr.indexOf( ':' ); int j2 = descr.indexOf( '(' ); if(j < 0 || (j2 > 0 && j2 < j)) j = j2; if(j > 0) { topic = descr.left(j); } else { topic = descr; } j = topic.lastIndexOf( '.' ); if(j > 0) { tmp = topic.left(j); topic = topic.mid(j+1); descr = descr.mid(j+1); j = tmp.lastIndexOf( '.' ); if( j > 0 ) { classs = tmp.mid(j+1); if( url.indexOf( "_"+classs ) > 0) { module = tmp.left(j); } else { classs = ""; module = tmp; } } } //params if exists j2 = descr.indexOf( '(' ); if( j2 > 0) { // ( paramsLine = descr.mid(j2+1); j = paramsLine.lastIndexOf( ')' ); if( j >= 0 ) { paramsLine = paramsLine.left(j); if( paramsLine == "" ) paramsLine = "*"; //has empty brackets } } } h->_topic = topic; h->url = "file:///"+monkeyPath+"/docs/html/"+url; h->descr = descr; h->kind = kind.toLower(); h->module = module; h->classs = classs; h->descrForInsert = topic; if( paramsLine != "" ) { h->params = paramsLine.split( ',' ); } h->isGlobal = (h->kind=="function" || h->kind=="global" || h->kind=="const"); insert( h ); } */ return true; }
void QuickHelp::insert(QuickHelp *help ) { help->ltopic = help->_topic.toLower(); map()->insert( help->ltopic, help ); map2()->insert( help->descr, help ); }
template<typename MatrixType> void map_class_matrix(const MatrixType& m) { typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; Index rows = m.rows(), cols = m.cols(), size = rows*cols; Scalar s1 = internal::random<Scalar>(); // array1 and array2 -> aligned heap allocation Scalar* array1 = internal::aligned_new<Scalar>(size); for(int i = 0; i < size; i++) array1[i] = Scalar(1); Scalar* array2 = internal::aligned_new<Scalar>(size); for(int i = 0; i < size; i++) array2[i] = Scalar(1); // array3unaligned -> unaligned pointer to heap Scalar* array3 = new Scalar[size+1]; for(int i = 0; i < size+1; i++) array3[i] = Scalar(1); Scalar* array3unaligned = internal::UIntPtr(array3)%EIGEN_MAX_ALIGN_BYTES == 0 ? array3+1 : array3; Scalar array4[256]; if(size<=256) for(int i = 0; i < size; i++) array4[i] = Scalar(1); Map<MatrixType> map1(array1, rows, cols); Map<MatrixType, AlignedMax> map2(array2, rows, cols); Map<MatrixType> map3(array3unaligned, rows, cols); Map<MatrixType> map4(array4, rows, cols); VERIFY_IS_EQUAL(map1, MatrixType::Ones(rows,cols)); VERIFY_IS_EQUAL(map2, MatrixType::Ones(rows,cols)); VERIFY_IS_EQUAL(map3, MatrixType::Ones(rows,cols)); map1 = MatrixType::Random(rows,cols); map2 = map1; map3 = map1; MatrixType ma1 = map1; MatrixType ma2 = map2; MatrixType ma3 = map3; VERIFY_IS_EQUAL(map1, map2); VERIFY_IS_EQUAL(map1, map3); VERIFY_IS_EQUAL(ma1, ma2); VERIFY_IS_EQUAL(ma1, ma3); VERIFY_IS_EQUAL(ma1, map3); VERIFY_IS_APPROX(s1*map1, s1*map2); VERIFY_IS_APPROX(s1*ma1, s1*ma2); VERIFY_IS_EQUAL(s1*ma1, s1*ma3); VERIFY_IS_APPROX(s1*map1, s1*map3); map2 *= s1; map3 *= s1; VERIFY_IS_APPROX(s1*map1, map2); VERIFY_IS_APPROX(s1*map1, map3); if(size<=256) { VERIFY_IS_EQUAL(map4, MatrixType::Ones(rows,cols)); map4 = map1; MatrixType ma4 = map4; VERIFY_IS_EQUAL(map1, map4); VERIFY_IS_EQUAL(ma1, map4); VERIFY_IS_EQUAL(ma1, ma4); VERIFY_IS_APPROX(s1*map1, s1*map4); map4 *= s1; VERIFY_IS_APPROX(s1*map1, map4); } internal::aligned_delete(array1, size); internal::aligned_delete(array2, size); delete[] array3; }
QuickHelp* QuickHelp::help2( const QString &descr ) { return map2()->value( descr, 0 ); }
void Start(){ Map map1(25,25); // первое игровое поле Map map2(350,25); // игровое поле врага /*for(int i = 0; i < 4; i++){ printf("Разместите 1-нопалубные корабли введя координаты[X Y]:\n"); metka: int k = 0; int b = 0; scanf("%d %d",&b,&k); if(map1.SetYa(b,k,1,1,1) == 0){ vShip_1[Ship1Init].Init(b,k,1); Ship1Init++; map1.Draw(); } else { printf("Невозможно установить! Повторите: "); goto metka; } } printf("\n0 - вверх, 1 - вправо, 2 - вниз, 3 - влево\n"); for(int i = 0; i < 3; i++){ printf("Разместите 2-хпалубные корабли введя координаты [X Y направление]:\n"); metka1: int k = 0; int b = 0; int n = 0; scanf("%d %d %d",&b,&k,&n); if(map1.SetYa(b,k,2,n,1) == 0){ vShip_2[Ship2Init].Init(b,k,n,1); Ship2Init++; map1.Draw(); } else { printf("Невозможно установить! Повторите: "); goto metka1; } } for(int i = 0; i < 2; i++){ printf("Разместите 3-хпалубные корабли введя координаты [X Y направление]:\n"); metka2: int k = 0; int b = 0; int n = 0; scanf("%d %d %d",&b,&k,&n); if(map1.SetYa(b,k,3,n,1) == 0){ vShip_3[Ship3Init].Init(b,k,n,1); Ship3Init++; map1.Draw(); } else { printf("Невозможно установить! Повторите: "); goto metka2; } } for(int i = 0; i < 1; i++){ printf("Разместите 4-хпалубный корабль введя координаты [X Y направление]:\n"); metka3: int k = 0; int b = 0; int n = 0; scanf("%d %d %d",&b,&k,&n); if(map1.SetYa(b,k,4,n,1) == 0){ vShip_4[Ship4Init].Init(b,k,n,1); Ship3Init++; map1.Draw(); } else { printf("Невозможно установить! Повторите:\n"); goto metka3; } } */ srand(time(NULL)); for(int i = 0; i < 4; i++){ metka4: int k = rand()%10+1; int b = rand()%10+1; if(map2.SetYa(b,k,1,1,3) == 0){ vShip_1[Ship1Init].Init(b,k,2); Ship1Init++; } else { goto metka4; } } for(int i = 0; i < 3; i++){ metka5: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map2.SetYa(b,k,2,n,3) == 0){ vShip_2[Ship2Init].Init(b,k,n,2); Ship2Init++; } else { goto metka5; } } for(int i = 0; i < 2; i++){ metka6: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map2.SetYa(b,k,3,n,3) == 0){ vShip_3[Ship3Init].Init(b,k,n,2); Ship3Init++; } else { goto metka6; } } for(int i = 0; i < 1; i++){ metka7: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map2.SetYa(b,k,4,n,3) == 0){ vShip_4[Ship4Init].Init(b,k,n,2); Ship4Init++; } else { goto metka7; } } //Снять комментарий, если лень расставлять самому srand(time(NULL)); for(int i = 0; i < 4; i++){ metka8: int k = rand()%10+1; int b = rand()%10+1; if(map1.SetYa(b,k,1,1,1) == 0){ vShip_1[Ship1Init].Init(b,k,2); Ship1Init++; } else { goto metka8; } } for(int i = 0; i < 3; i++){ metka9: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map1.SetYa(b,k,2,n,1) == 0){ vShip_2[Ship2Init].Init(b,k,n,2); Ship2Init++; } else { goto metka9; } } for(int i = 0; i < 2; i++){ metka10: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map1.SetYa(b,k,3,n,1) == 0){ vShip_3[Ship3Init].Init(b,k,n,2); Ship3Init++; } else { goto metka10; } } for(int i = 0; i < 1; i++){ metka11: int k = rand()%10+1; int b = rand()%10+1; int n = rand()%4; if(map1.SetYa(b,k,4,n,1) == 0){ vShip_4[Ship4Init].Init(b,k,n,2); Ship4Init++; } else { goto metka11; } } cleardevice(); map2.Draw(); map1.Draw(); War(map1,map2); }
int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("Map_Test")); ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE); size_t table_size = ACE_MAX_ITERATIONS / 2; size_t iterations = ACE_MAX_ITERATIONS; size_t functionality_tests = 1; if (argc > 1) functionality_tests = ACE_OS::atoi (argv[1]); if (argc > 2) table_size = ACE_OS::atoi (argv[2]); if (argc > 3) iterations = ACE_OS::atoi (argv[3]); MAP_MANAGER_ADAPTER map1 (table_size); HASH_MAP_MANAGER_ADAPTER map2 (table_size); ACTIVE_MAP_MANAGER_ADAPTER map3 (table_size); if (functionality_tests) { // Functionality test of the maps. ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nMap Manager functionality test\n"))); functionality_test (map1, iterations); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nHash Map Manager functionality test\n"))); functionality_test (map2, iterations); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nActive Map Manager functionality test\n"))); functionality_test (map3, iterations); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); } // Performance test of the maps. KEY *keys = new KEY[iterations]; // Map Manager performance_test (&insert_test, map1, iterations, keys, table_size, ACE_TEXT ("Map Manager (insert test)")); performance_test (&find_test, map1, iterations, keys, table_size, ACE_TEXT ("Map Manager (find test)")); performance_test (&unbind_test, map1, iterations, keys, table_size, ACE_TEXT ("Map Manager (unbind test)")); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); // Hash Map Manager performance_test (&insert_test, map2, iterations, keys, table_size, ACE_TEXT ("Hash Map Manager (insert test)")); performance_test (&find_test, map2, iterations, keys, table_size, ACE_TEXT ("Hash Map Manager (find test)")); performance_test (&unbind_test, map2, iterations, keys, table_size, ACE_TEXT ("Hash Map Manager (unbind test)")); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n"))); // Active Map Manager performance_test (&insert_test, map3, iterations, keys, table_size, ACE_TEXT ("Active Map Manager (insert test)")); performance_test (&find_test, map3, iterations, keys, table_size, ACE_TEXT ("Active Map Manager (find test)")); performance_test (&unbind_test, map3, iterations, keys, table_size, ACE_TEXT ("Active Map Manager (unbind test)")); delete[] keys; ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE); ACE_END_TEST; return 0; }
void tst_QMap::count() { { MyMap map; MyMap map2( map ); QCOMPARE( map.count(), 0 ); QCOMPARE( map2.count(), 0 ); QCOMPARE( MyClass::count, int(0) ); // detach map2["Hallo"] = MyClass( "Fritz" ); QCOMPARE( map.count(), 0 ); QCOMPARE( map2.count(), 1 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 1 ); #endif } QCOMPARE( MyClass::count, int(0) ); { typedef QMap<QString, MyClass> Map; Map map; QCOMPARE( map.count(), 0); map.insert( "Torben", MyClass("Weis") ); QCOMPARE( map.count(), 1 ); map.insert( "Claudia", MyClass("Sorg") ); QCOMPARE( map.count(), 2 ); map.insert( "Lars", MyClass("Linzbach") ); map.insert( "Matthias", MyClass("Ettrich") ); map.insert( "Sue", MyClass("Paludo") ); map.insert( "Eirik", MyClass("Eng") ); map.insert( "Haavard", MyClass("Nord") ); map.insert( "Arnt", MyClass("Gulbrandsen") ); map.insert( "Paul", MyClass("Tvete") ); QCOMPARE( map.count(), 9 ); map.insert( "Paul", MyClass("Tvete 1") ); map.insert( "Paul", MyClass("Tvete 2") ); map.insert( "Paul", MyClass("Tvete 3") ); map.insert( "Paul", MyClass("Tvete 4") ); map.insert( "Paul", MyClass("Tvete 5") ); map.insert( "Paul", MyClass("Tvete 6") ); QCOMPARE( map.count(), 9 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif Map map2( map ); QVERIFY( map2.count() == 9 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif map2.insert( "Kay", MyClass("Roemer") ); QVERIFY( map2.count() == 10 ); QVERIFY( map.count() == 9 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 19 ); #endif map2 = map; QVERIFY( map.count() == 9 ); QVERIFY( map2.count() == 9 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif map2.insert( "Kay", MyClass("Roemer") ); QVERIFY( map2.count() == 10 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 19 ); #endif map2.clear(); QVERIFY( map.count() == 9 ); QVERIFY( map2.count() == 0 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif map2 = map; QVERIFY( map.count() == 9 ); QVERIFY( map2.count() == 9 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif map2.clear(); QVERIFY( map.count() == 9 ); QVERIFY( map2.count() == 0 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 9 ); #endif map.remove( "Lars" ); QVERIFY( map.count() == 8 ); QVERIFY( map2.count() == 0 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 8 ); #endif map.remove( "Mist" ); QVERIFY( map.count() == 8 ); QVERIFY( map2.count() == 0 ); #ifndef Q_CC_SUN QCOMPARE( MyClass::count, 8 ); #endif } QVERIFY( MyClass::count == 0 ); { typedef QMap<QString,MyClass> Map; Map map; map["Torben"] = MyClass("Weis"); #ifndef Q_CC_SUN QVERIFY( MyClass::count == 1 ); #endif QVERIFY( map.count() == 1 ); (void)map["Torben"].str; (void)map["Lars"].str; #ifndef Q_CC_SUN QVERIFY( MyClass::count == 2 ); #endif QVERIFY( map.count() == 2 ); const Map& cmap = map; (void)cmap["Depp"].str; #ifndef Q_CC_SUN QVERIFY( MyClass::count == 2 ); #endif QVERIFY( map.count() == 2 ); QVERIFY( cmap.count() == 2 ); } QCOMPARE( MyClass::count, 0 ); { for ( int i = 0; i < 100; ++i ) { QMap<int, MyClass> map; for (int j = 0; j < i; ++j) map.insert(j, MyClass(QString::number(j))); } QCOMPARE( MyClass::count, 0 ); } QCOMPARE( MyClass::count, 0 ); }
/*************************************************************************** * @brief GSkymap_healpix_construct ***************************************************************************/ void TestGSky::test_GSkymap_healpix_construct(void) { // Test void constructor test_try("Test void constructor"); try { GSkymap map; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test correct Healpix constructors test_try("Test correct Healpix constructors"); try { GSkymap ring1("GAL", 1, "RING", 1); GSkymap ring2("GAL", 2, "RING", 1); GSkymap ring4("GAL", 4, "RING", 1); GSkymap ring8("GAL", 8, "RING", 1); GSkymap ring16("GAL", 16, "RING", 1); GSkymap ring32("GAL", 32, "RING", 1); GSkymap ring64("GAL", 64, "RING", 1); GSkymap ring128("GAL", 128, "RING", 1); GSkymap ring256("GAL", 256, "RING", 1); GSkymap ring512("GAL", 512, "RING", 1); GSkymap nest1("GAL", 1, "NEST", 1); GSkymap nest2("GAL", 2, "NEST", 1); GSkymap nest4("GAL", 4, "NEST", 1); GSkymap nest8("GAL", 8, "NEST", 1); GSkymap nest16("GAL", 16, "NEST", 1); GSkymap nest32("GAL", 32, "NEST", 1); GSkymap nest64("GAL", 64, "NEST", 1); GSkymap nest128("GAL", 128, "NEST", 1); GSkymap nest256("GAL", 256, "NEST", 1); GSkymap nest512("GAL", 512, "NEST", 1); GSkymap map1("CEL", 1, "RING", 1); GSkymap map2("CEL", 1, "RING", 2); GSkymap map3("EQU", 1, "RING", 1); GSkymap map4("EQU", 1, "NESTED", 1); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test Healpix copy constructor test_try("Test Healpix copy constructor"); try { GSkymap ring1("GAL", 1, "RING", 1); GSkymap ring2 = ring1; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test invalid coordsys in constructor test_try("Test invalid coordsys in constructor"); try { GSkymap map("HOR", 1, "RING", 1); test_try_failure(); } catch (GException::wcs_bad_coords &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test invalid nside in constructor test_try("Test invalid nside in constructor"); try { GSkymap map("GAL", 3, "RING", 1); test_try_failure(); } catch (GException::wcs_hpx_bad_nside &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test invalid ordering in constructor test_try("Test invalid ordering in constructor"); try { GSkymap map("GAL", 2, "SPHERICAL", 1); test_try_failure(); } catch (GException::wcs_hpx_bad_ordering &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test invalid nmaps in constructor test_try("Test invalid nmaps in constructor"); try { GSkymap map("GAL", 2, "NEST", 0); test_try_failure(); } catch (GException::skymap_bad_par &e) { test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Exit test return; }
hypre_CSRMatrix * hypre_GenerateLaplacian9pt( HYPRE_Int nx, HYPRE_Int ny, HYPRE_Int P, HYPRE_Int Q, double *value ) { hypre_CSRMatrix *A; HYPRE_Int *A_i; HYPRE_Int *A_j; double *A_data; HYPRE_Int *global_part; HYPRE_Int ix, iy; HYPRE_Int p, q; HYPRE_Int cnt; HYPRE_Int num_rows; HYPRE_Int row_index; HYPRE_Int nx_size, ny_size; HYPRE_Int *nx_part; HYPRE_Int *ny_part; num_rows = nx*ny; hypre_GeneratePartitioning(nx,P,&nx_part); hypre_GeneratePartitioning(ny,Q,&ny_part); global_part = hypre_CTAlloc(HYPRE_Int,P*Q+1); global_part[0] = 0; cnt = 1; for (iy = 0; iy < Q; iy++) { ny_size = ny_part[iy+1]-ny_part[iy]; for (ix = 0; ix < P; ix++) { nx_size = nx_part[ix+1] - nx_part[ix]; global_part[cnt] = global_part[cnt-1]; global_part[cnt++] += nx_size*ny_size; } } A_i = hypre_CTAlloc(HYPRE_Int,num_rows+1); cnt = 0; A_i[0] = 0; for (q = 0; q < Q; q++) { for (p=0; p < P; p++) { for (iy = ny_part[q]; iy < ny_part[q+1]; iy++) { for (ix = nx_part[p]; ix < nx_part[p+1]; ix++) { cnt++; A_i[cnt] = A_i[cnt-1]; A_i[cnt]++; if (iy > ny_part[q]) { A_i[cnt]++; if (ix > nx_part[p]) { A_i[cnt]++; } else { if (ix) A_i[cnt]++; } if (ix < nx_part[p+1]-1) { A_i[cnt]++; } else { if (ix+1 < nx) A_i[cnt]++; } } else { if (iy) { A_i[cnt]++; if (ix > nx_part[p]) { A_i[cnt]++; } else if (ix) { A_i[cnt]++; } if (ix < nx_part[p+1]-1) { A_i[cnt]++; } else if (ix < nx-1) { A_i[cnt]++; } } } if (ix > nx_part[p]) A_i[cnt]++; else { if (ix) { A_i[cnt]++; } } if (ix+1 < nx_part[p+1]) A_i[cnt]++; else { if (ix+1 < nx) { A_i[cnt]++; } } if (iy+1 < ny_part[q+1]) { A_i[cnt]++; if (ix > nx_part[p]) { A_i[cnt]++; } else { if (ix) A_i[cnt]++; } if (ix < nx_part[p+1]-1) { A_i[cnt]++; } else { if (ix+1 < nx) A_i[cnt]++; } } else { if (iy+1 < ny) { A_i[cnt]++; if (ix > nx_part[p]) { A_i[cnt]++; } else if (ix) { A_i[cnt]++; } if (ix < nx_part[p+1]-1) { A_i[cnt]++; } else if (ix < nx-1) { A_i[cnt]++; } } } } } } } A_j = hypre_CTAlloc(HYPRE_Int, A_i[num_rows]); A_data = hypre_CTAlloc(double, A_i[num_rows]); row_index = 0; cnt = 0; for (q=0; q < Q; q++) { for (p=0; p < P; p++) { for (iy = ny_part[q]; iy < ny_part[q+1]; iy++) { for (ix = nx_part[p]; ix < nx_part[p+1]; ix++) { nx_size = nx_part[p+1]-nx_part[p]; A_j[cnt] = row_index; A_data[cnt++] = value[0]; if (iy > ny_part[q]) { if (ix > nx_part[p]) { A_j[cnt] = row_index-nx_size-1 ; A_data[cnt++] = value[1]; } else { if (ix) { A_j[cnt] = map2(ix-1,iy-1,p-1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } A_j[cnt] = row_index-nx_size; A_data[cnt++] = value[1]; if (ix < nx_part[p+1]-1) { A_j[cnt] = row_index-nx_size+1 ; A_data[cnt++] = value[1]; } else { if (ix+1 < nx) { A_j[cnt] = map2(ix+1,iy-1,p+1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } } else { if (iy) { if (ix > nx_part[p]) { A_j[cnt] = map2(ix-1,iy-1,p,q-1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } else if (ix) { A_j[cnt] = map2(ix-1,iy-1,p-1,q-1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } A_j[cnt] = map2(ix,iy-1,p,q-1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; if (ix < nx_part[p+1]-1) { A_j[cnt] = map2(ix+1,iy-1,p,q-1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } else if (ix+1 < nx) { A_j[cnt] = map2(ix+1,iy-1,p+1,q-1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } } if (ix > nx_part[p]) { A_j[cnt] = row_index-1; A_data[cnt++] = value[1]; } else { if (ix) { A_j[cnt] = map2(ix-1,iy,p-1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } if (ix+1 < nx_part[p+1]) { A_j[cnt] = row_index+1; A_data[cnt++] = value[1]; } else { if (ix+1 < nx) { A_j[cnt] = map2(ix+1,iy,p+1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } if (iy+1 < ny_part[q+1]) { if (ix > nx_part[p]) { A_j[cnt] = row_index+nx_size-1 ; A_data[cnt++] = value[1]; } else { if (ix) { A_j[cnt] = map2(ix-1,iy+1,p-1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } A_j[cnt] = row_index+nx_size; A_data[cnt++] = value[1]; if (ix < nx_part[p+1]-1) { A_j[cnt] = row_index+nx_size+1 ; A_data[cnt++] = value[1]; } else { if (ix+1 < nx) { A_j[cnt] = map2(ix+1,iy+1,p+1,q,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } } else { if (iy+1 < ny) { if (ix > nx_part[p]) { A_j[cnt] = map2(ix-1,iy+1,p,q+1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } else if (ix) { A_j[cnt] = map2(ix-1,iy+1,p-1,q+1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } A_j[cnt] = map2(ix,iy+1,p,q+1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; if (ix < nx_part[p+1]-1) { A_j[cnt] = map2(ix+1,iy+1,p,q+1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } else if (ix < nx-1) { A_j[cnt] = map2(ix+1,iy+1,p+1,q+1,P,Q, nx_part,ny_part,global_part); A_data[cnt++] = value[1]; } } } row_index++; } } } } A = hypre_CSRMatrixCreate(num_rows, num_rows, A_i[num_rows]); hypre_CSRMatrixI(A) = A_i; hypre_CSRMatrixJ(A) = A_j; hypre_CSRMatrixData(A) = A_data; hypre_TFree(nx_part); hypre_TFree(ny_part); hypre_TFree(global_part); return A; }
int BlockMapToMatrixMarketFile( const char *filename, const Epetra_BlockMap & map, const char * mapName, const char *mapDescription, bool writeHeader) { int M = map.NumGlobalElements(); int N = 1; if (map.MaxElementSize()>1) N = 2; // Non-trivial block map, store element sizes in second column FILE * handle = 0; if (map.Comm().MyPID()==0) { // Only PE 0 does this section handle = fopen(filename,"w"); if (!handle) return(-1); MM_typecode matcode; mm_initialize_typecode(&matcode); mm_set_matrix(&matcode); mm_set_array(&matcode); mm_set_integer(&matcode); if (writeHeader==true) { // Only write header if requested (true by default) if (mm_write_banner(handle, matcode)) return(-1); if (mapName!=0) fprintf(handle, "%% \n%% %s\n", mapName); if (mapDescription!=0) fprintf(handle, "%% %s\n%% \n", mapDescription); } } if (writeHeader==true) { // Only write header if requested (true by default) // Make an Epetra_IntVector of length numProc such that all elements are on PE 0 and // the ith element is NumMyElements from the ith PE Epetra_Map map1(-1, 1, 0, map.Comm()); // map with one element on each processor int length = 0; if (map.Comm().MyPID()==0) length = map.Comm().NumProc(); Epetra_Map map2(-1, length, 0, map.Comm()); Epetra_Import lengthImporter(map2, map1); Epetra_IntVector v1(map1); Epetra_IntVector v2(map2); v1[0] = map.NumMyElements(); if (v2.Import(v1, lengthImporter, Insert)) return(-1); if (map.Comm().MyPID()==0) { fprintf(handle, "%s", "%Format Version:\n"); //int version = 1; // We may change the format scheme at a later date. fprintf(handle, "%% %d \n", map.Comm().NumProc()); fprintf(handle, "%s", "%NumProc: Number of processors:\n"); fprintf(handle, "%% %d \n", map.Comm().NumProc()); fprintf(handle, "%s", "%MaxElementSize: Maximum element size:\n"); fprintf(handle, "%% %d \n", map.MaxElementSize()); fprintf(handle, "%s", "%MinElementSize: Minimum element size:\n"); fprintf(handle, "%% %d \n", map.MinElementSize()); fprintf(handle, "%s", "%IndexBase: Index base of map:\n"); fprintf(handle, "%% %d \n", map.IndexBase()); fprintf(handle, "%s", "%NumGlobalElements: Total number of GIDs in map:\n"); fprintf(handle, "%% %d \n", map.NumGlobalElements()); fprintf(handle, "%s", "%NumMyElements: BlockMap lengths per processor:\n"); for ( int i=0; i< v2.MyLength(); i++) fprintf(handle, "%% %d\n", v2[i]); if (mm_write_mtx_array_size(handle, M, N)) return(-1); } } if (BlockMapToHandle(handle, map)) return(-1); // Everybody calls this routine if (map.Comm().MyPID()==0) // Only PE 0 opened a file if (fclose(handle)) return(-1); return(0); }