Beispiel #1
0
/***************************************************************************
 * @brief GSkymap_wcs_construct
 ***************************************************************************/
void TestGSky::test_GSkymap_wcs_construct(void)
{
    // Set precision
    double eps = 1.0e-5;

    // Test void constructor
    test_try("Test void constructor");
    try {
        GSkymap map;
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test non-Healpix constructors
    test_try("Test non-Healpix constructors");
    try {
        GSkymap map1("CAR", "GAL", 0.0, 0.0, 1.0, 1.0, 100, 100);
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test CAR projection
    test_try("Test CAR projection");
    try {
        GSkymap map1("CAR", "GAL", 138.817, 37.293, 0.521, 0.931, 100, 100);
        GSkyDir dir;
        for (int l = -180; l < 180; ++l) {
            for (int b = -90; b < 90; ++b) {
                dir.lb_deg(double(l),double(b));
                GSkyPixel pixel    = map1.dir2pix(dir);
                GSkyDir   dir_back = map1.pix2dir(pixel);
                double    dist     = dir.dist_deg(dir_back);
                if (dist > eps) {
                    throw exception_failure("Sky direction differs: dir="+dir.print()+" pixel="+pixel.print()+" dir_back"+ dir_back.print()+" dist="+gammalib::str(dist)+" deg");
                }
            }
        }
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Exit test
    return;

}
Beispiel #2
0
void basicTests() {
	int n1 = 10; IdMap map1(n1); string s;

	Utest::assertEqual(map1.firstId(), 0, "initial map not empty");
	cout << "writing empty idMap: " << map1.toString(s) << endl;

	map1.addPair(1234);
	Utest::assertEqual(map1.getId(1234),1,"wrong id for first item");
	cout << "writing one idMap: " << map1.toString(s) << endl;

	Utest::assertEqual(map1.toString(s), "{ (1234,1) }",
		"mismatch on adding first item");

	map1.addPair(2345); map1.addPair(3456);
	Utest::assertEqual(map1.getId(2345),2,"wrong id for second item");
	Utest::assertEqual(map1.getId(3456),3,"wrong id for third item");
	Utest::assertEqual(map1.toString(s), "{ (1234,1) (2345,2) (3456,3) }",
		"mismatch after adding third item");
	cout << "writing 3 idMap: " << map1.toString(s) << endl;

	map1.dropPair(2345);
	Utest::assertEqual(map1.toString(s), "{ (1234,1) (3456,3) }",
		"mismatch after releasing second id");

	map1.addPair(4567);
	Utest::assertEqual(map1.toString(s), "{ (1234,1) (3456,3) (4567,4) }",
		"mismatch on adding after releasing id");

	map1.clear();
	Utest::assertEqual(map1.toString(s), "{ }", "mismatch after clearing map");
}
Beispiel #3
0
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;
}
Beispiel #4
0
PERF_TEST_P( TestRemap, Remap,
             Combine(
                Values( szVGA, sz1080p ),
                Values( CV_16UC1, CV_16SC1, CV_32FC1 ),
                Values( CV_16SC2, CV_32FC1, CV_32FC2 ),
                InterType::all()
             )
)
{
    Size sz;
    int src_type, map1_type, inter_type;

    sz         = get<0>(GetParam());
    src_type   = get<1>(GetParam());
    map1_type  = get<2>(GetParam());
    inter_type = get<3>(GetParam());

    Mat src(sz, src_type), dst(sz, src_type), map1(sz, map1_type), map2;
    if (map1_type == CV_32FC1)
        map2.create(sz, CV_32FC1);
    else if (inter_type != INTER_NEAREST && map1_type == CV_16SC2)
    {
        map2.create(sz, CV_16UC1);
        map2 = Scalar::all(0);
    }

    RNG rng;
    rng.fill(src, RNG::UNIFORM, 0, 256);

    for (int j = 0; j < map1.rows; ++j)
        for (int i = 0; i < map1.cols; ++i)
            switch (map1_type)
            {
                case CV_32FC1:
                    map1.at<float>(j, i) = static_cast<float>(src.cols - i - 1);
                    map2.at<float>(j, i) = static_cast<float>(j);
                    break;
                case CV_32FC2:
                    map1.at<Vec2f>(j, i)[0] = static_cast<float>(src.cols - i - 1);
                    map1.at<Vec2f>(j, i)[1] = static_cast<float>(j);
                    break;
                case CV_16SC2:
                    map1.at<Vec2s>(j, i)[0] = static_cast<short>(src.cols - i - 1);
                    map1.at<Vec2s>(j, i)[1] = static_cast<short>(j);
                    break;
                default:
                    CV_Assert(0);
            }


    declare.in(src, WARMUP_RNG).out(dst).time(20);

    int runs = (sz.width <= 640) ? 3 : 1;
    TEST_CYCLE_MULTIRUN(runs) remap(src, dst, map1, map2, inter_type);

    SANITY_CHECK(dst);
}
Beispiel #5
0
void polyval (header *hd)
{	header *st=hd,*hd1,*result;
	int r,c;
	hd1=nextof(hd);
	equal_params_2(&hd,&hd1);
	getmatrix(hd,&r,&c,&polynom);
	if (r!=1) wrong_arg();
	degree=c-1;
	if (degree<0) wrong_arg();
	if (isinterval(hd)) result=map1i(ipeval,hd1);
	else result=map1(peval,cpeval,hd1);
	moveresult(st,result);
}
Beispiel #6
0
void ddval (header *hd)
{	header *st=hd,*hdd,*hd1,*result;
	int r,c,cd;
	hdd=nextof(st);
	hd1=nextof(hdd);
	equal_params_3(&hd,&hdd,&hd1); if (error) return;
	getmatrix(hd,&r,&c,&divx); if (r!=1 || c<1) wrong_arg();
	getmatrix(hdd,&r,&cd,&divdif); if (r!=1 || c!=cd) wrong_arg();
	degree=c-1;
	if (isinterval(hd)) result=map1i(iddeval,hd1);
	else result=map1(rddeval,cddeval,hd1);
	if (error) return;
	moveresult(st,result);
}
Beispiel #7
0
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]);
		}
	}
}
Beispiel #8
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));
    }
}
// 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 DataAccess::rasters(){
    Ilwis::IRasterCoverage map1(makeInputPath("n000302.mpr"));

    DOCOMPARE(map1->coord2value(Ilwis::Coordinate(112109.75,128832.51)), 71.0, "accesing raster through coordinate");

    DOCOMPARE(map1->pix2value(Ilwis::Pixel(564, 623)), 169.0, "accessing raster through pixel");

    map1.prepare(makeInputPath("kenya_2009ndvi_cor_22.mpr"));

    DOCOMPARE(map1->pix2value(Ilwis::Pixel(416,501)), 0.232, "accessing raster through georef submap");

    map1.prepare(makeInputPath("tmb1.mpr"));

    DOCOMPARE(map1->coord2value(Ilwis::Coordinate(800827.47,8083453.21)), 40.0,"accessing raster through tiepoint georef");

    map1.prepare(makeInputPath("average_monthly_temperature.mpl"));

    DOCOMPARE(map1->pix2value(Ilwis::Pixel(898,277,3)), 24.20,"Accessing pixels in a maplist");

    map1.prepare(makeInputPath("cc43.mpr"));
    QColor clr = map1->datadef().domain<>()->impliedValue(map1->pix2value(Ilwis::Pixel(136,199))).value<QColor>();
    DOCOMPARE(clr, QColor(46,47,51), "accessing color values");
}
Beispiel #11
0
int main(int argc, char* args[]) {
	init();

	//Stage objects
	Tileset tileset("src/assets/img/tileset.png", 6, 3);
	Map map1("map1");

	// Get level dimensions
	levelWidth = tileset.getTileWidth() * map1.getMapWidth();
	levelHeight = tileset.getTileHeight() * map1.getMapHeight();

	Player player1(gRenderer, "src/assets/img/player1_sheet.png", 5, 5, 3, 4);
	//Wall wall(192, 96, 96, 576);

	// General event handler stuff
	bool quit = false;
	bool paused = false;
	SDL_Event e;

	// Game Loop
	while (!quit) {

		//framerate control
		stabilizeFramerate();

		// Poll Events
		while (SDL_PollEvent(&e) != 0) {
			switch (e.type) {
			// check for quit
			case SDL_QUIT:
				quit = true;
				break;
			case SDL_KEYDOWN:
				switch(e.key.keysym.sym) {
				// check for pause
				case SDLK_ESCAPE:
					if (!paused) {
						paused = true;
					} else {
						paused = false;
					}
					break;
				}
				break;
			// checking for window focus
			case SDL_WINDOWEVENT:
				switch(e.window.event) {
				case SDL_WINDOWEVENT_FOCUS_LOST:
					paused = true;
					break;
				}
				break;
			}
		}

		if (!paused) {

			keystate = SDL_GetKeyboardState(NULL);
			player1.update(delta, keystate, map1);


			cameraRect.x = player1.getOriginX() - SCREEN_WIDTH/2;
			cameraRect.y = player1.getOriginY() - SCREEN_HEIGHT/2;

			if (cameraRect.x < 0) {
				cameraRect.x = 0;
			}

			if (cameraRect.y < 0) {
				cameraRect.y = 0;
			}

			if (cameraRect.x + cameraRect.w >= levelWidth) {
				cameraRect.x = levelWidth - SCREEN_WIDTH;
			}

			if (cameraRect.y + cameraRect.h >= levelHeight) {
				cameraRect.y = levelHeight - SCREEN_HEIGHT;
			}

			// Clear stage
			SDL_RenderClear(gRenderer);

			// Make stuff happen!
			map1.drawTiles(tileset);
			map1.drawWalls();
			player1.draw(gRenderer, cameraRect);
			// Update stage
			SDL_RenderPresent(gRenderer);
		}
	}

	done();
	return 0;
}
Beispiel #12
0
static void GLAPIENTRY
_mesa_Map1d( GLenum target, GLdouble u1, GLdouble u2, GLint stride,
             GLint order, const GLdouble *points )
{
   map1(target, (GLfloat) u1, (GLfloat) u2, stride, order, points, GL_DOUBLE);
}
Beispiel #13
0
static void GLAPIENTRY
_mesa_Map1f( GLenum target, GLfloat u1, GLfloat u2, GLint stride,
             GLint order, const GLfloat *points )
{
   map1(target, u1, u2, stride, order, points, GL_FLOAT);
}
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;
}
Beispiel #15
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);           
}
Beispiel #16
0
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 generateMap(string id) {
    srand(1);

    int n, l, m, s;
    READ(cin, n);
    READ(cin, l);
    READ(cin, m);
    READ(cin, s);

    vector<string> aname(n * l);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            READ_FRAG(cin, j, aname[i * l + j]);
        }
        READ_DONE();
    }

    int newL, newM, newS, tagNumber;
    READ(cin, newL);
    READ(cin, newM);
    READ(cin, newS);
    READ(cin, tagNumber);

    vector<string> nodeNameList;
    vector<string> nodeTagList;
    for (int j = 0; j < newM; j++) {
        string nodeName;
        READ_FRAG(cin, 0, nodeName);
        nodeNameList.push_back(nodeName);
        for (int i = 0; i < tagNumber; i++) {
            string nodeTag;
            READ_FRAG(cin, i+1, nodeTag);
            nodeTagList.push_back(nodeTag);
        }
        READ_DONE();
    }

    fixOldData(n, l, m, s, aname);
    fixNewData(n, newL, newM, newS, tagNumber, nodeNameList, nodeTagList);

    if (!validate(n, l, m, s)) {
        DIAG("ERROR: existing mapping failed validation" << endl);
        throw "Validation failure";
    }

    if (!validate(n, newL, newM, newS) || !validate(newM, nodeNameList, tagNumber, nodeTagList)) {
        DIAG("ERROR: new mapping failed validation" << endl);
        throw "Validation failure";
    }

    if (!IsInRow(nodeNameList, _NULL_NODE_NAME)) {
        nodeNameList.insert(nodeNameList.begin(), _NULL_NODE_NAME);
        for (int i = 0; i < tagNumber; i++) {
            nodeTagList.insert(nodeTagList.begin(), "");
        }
    }

    Mapping map0(n, l, m, s);
    map0.InitMapping(aname);

    vector<int> TagPrice(tagNumber,0);
    for (int i = 0; i < tagNumber; i++) {
        TagPrice[i] = 10;  // default to 10 for now
    }

    stack<int> addedNode;
    for (int j = 1; j <= newM; ++j ) {
        if (!IsInRow(map0.nodeNameList, nodeNameList[j])) {
            addedNode.push(j);
        }
    }
    // Deleted nodes map to zero, used for computing lower bound
    vector<int> oldNode2NewZero(map0.M + 1, 0);
    // Deleted nodes map to added nodes if possible
    // Used for initialize a search for RI
    vector<int> oldNode2NewMatch(map0.M + 1, 0);
    string currentNode;
    bool nodeFound;
    for (int i = 1; i <= map0.M; i++) {
        currentNode = map0.nodeNameList[i];
        nodeFound = 0;
        for (int j = 0; j <= newM; ++j ) {
            if (!currentNode.compare(nodeNameList[j])) {
                nodeFound = 1;
                oldNode2NewMatch[i] = j;
                oldNode2NewZero[i] = j;
                break;
            }
        }
        if (!nodeFound) {
            if (!addedNode.empty() ) {
                oldNode2NewMatch[i] = addedNode.top();
                addedNode.pop();
            }
        }
    }

    Mapping map1(map0.N, newL, newM, newS);
    map1.nodeNameList.swap(nodeNameList);
    map1.nodeTagList.swap(nodeTagList);
    map1.Rebalance(map0, oldNode2NewMatch, TagPrice);
    map1.nodeTagNumber = tagNumber;
    int LowerBound = map1.RebalanceLowerBound(map0, oldNode2NewZero, TagPrice);

    if (map1.imbalance)
        DIAG("WARNING : Output mapping has imbalance of " << map1.imbalance << "\n\n");

    DIAG("\nRebalance completed.\nNode number : " << map0.M << " ---> " << map1.M);
    DIAG("\nMove count (index/non-index) : " << map1.MoveCount(map0, 1) << " / ");
    DIAG(map1.MoveCount(map0, 0) << "\tLower bound : " << LowerBound);
    DIAG("\n\nSame tags replication :\nPrice : \t");

    vector<int> sameTagCount;
    map1.CheckTags(sameTagCount);
    for (int i = 0; i < map1.nodeTagNumber; i++) {
        DIAG(TagPrice[i] << '\t');
    }
    DIAG("\nCount : \t");
    for (int i = 0; i < map1.nodeTagNumber; i++) {
        DIAG(sameTagCount[i] << '\t');
    }
    DIAG(endl);

    ostringstream mapout;
    map1.PrintAname(mapout);
    WRITE(cout, mapout.str() << endl);
}
Beispiel #18
0
int
main(int argc, char** argv) {
    int l_speculation_start;
    utility::thread_number_range threads( 
            task_scheduler_init::default_num_threads,
            task_scheduler_init::default_num_threads()  // run only the default number of threads if none specified
    );

    utility::parse_cli_arguments(argc,argv,
            utility::cli_argument_pack()
            //"-h" option for for displaying help is present implicitly
            .positional_arg(threads,"n-of-threads","number of threads to use; a range of the form low[:high], where low and optional high are non-negative integers or 'auto' for the TBB default.")
            // .positional_arg(InputFileName,"input-file","input file name")
            // .positional_arg(OutputFileName,"output-file","output file name")
            .positional_arg(radius_fraction, "radius-fraction","size of radius at which to start speculating")
            .positional_arg(nPasses, "number-of-epochs","number of examples used in learning phase")
            .arg(cancel_test, "cancel-test", "test for cancel signal while finding BMU")
            .arg(extra_debug, "debug", "additional output")
            .arg(dont_speculate,"nospeculate","don't speculate in SOM map teaching")
         );

    readInputData();
    max_radius = (xMax < yMax) ? yMax / 2 : xMax / 2;
    // need this value for the 1x1 timing below
    radius_decay_rate = -(log(1.0/(double)max_radius) / (double)nPasses);
    find_data_ranges(my_teaching, max_range, min_range );
    if(extra_debug) {
        printf( "Data range: ");
        remark_SOM_element(min_range);
        printf( " to ");
        remark_SOM_element(max_range);
        printf( "\n");
    }

    // find how much time is taken for the single function_node case.
    // adjust nPasses so the 1x1 time is somewhere around serial_time_adjust seconds.
   // make sure the example test runs for at least 0.5 second.
    for(;;) {
        task_scheduler_init init(1);
        SOMap map1(xMax,yMax);
        speculation_start = nPasses + 1;  // Don't speculate

        xranges = 1;
        yranges = 1;
        map1.initialize(InitializeGradient, max_range, min_range);
        tick_count t0 = tick_count::now();
        graph_teach(map1, my_teaching);
        tick_count t1 = tick_count::now();
        double nSeconds = (t1-t0).seconds();
        if(nSeconds < 0.5) {
            xMax *= 2;
            yMax *= 2;
            continue;
        }
        double size_adjust = sqrt(serial_time_adjust / nSeconds);
        xMax = (int)((double)xMax * size_adjust);
        yMax = (int)((double)yMax * size_adjust);
        max_radius = (xMax < yMax) ? yMax / 2 : xMax / 2;
        radius_decay_rate = log((double)max_radius) / (double)nPasses;

        if(extra_debug) {
            printf("original 1x1 case ran in %g seconds\n", nSeconds);
            printf("   Size of table == %d x %d\n", xMax, yMax);
            printf("   radius_decay_rate == %g\n", radius_decay_rate);
        }
        break;
    }

    // the "max_radius" starts at 1/2*radius_fraction the table size.  To start the speculation when the radius is
    // 1 / n * the table size, the constant in the log below should be n / 2.  so 2 == 1/4, 3 == 1/6th,
    // et c.
    if(dont_speculate) {
        l_speculation_start = nPasses + 1;
        if ( extra_debug )printf("speculation will not be done\n");
    }
    else {
        if(radius_fraction < 1.0 ) {
            if ( extra_debug )printf("Warning: radius_fraction should be >= 1.  Setting to 1.\n");
            radius_fraction = 1.0;
        }
        l_speculation_start = (int)((double)nPasses * log(radius_fraction) / log((double)nPasses)); 
        if ( extra_debug )printf( "We will start speculation at iteration %d\n", l_speculation_start );
    }
    double single_time;  // for speedup calculations
    for(int p = threads.first; p <= threads.last; ++p) {
        task_scheduler_init init(p);
        if ( extra_debug )printf( " -------------- Running with %d threads. ------------\n", p);
       // run the SOM build for a series of subranges
        for(xranges = 1; xranges <= xRangeMax; ++xranges) {
            for(yranges = xranges; yranges <= yRangeMax; ++yranges) {
                if(xranges == 1 && yranges == 1) {
                    // don't pointlessly speculate if we're only running one subrange.
                    speculation_start = nPasses + 1;
                }
                else {
                    speculation_start = l_speculation_start;
                }
                SOMap map1(xMax, yMax);
                map1.initialize(InitializeGradient, max_range, min_range);
    
                if(extra_debug) printf( "Start learning for [%d,%d] ----------- \n", xranges,yranges);
                tick_count t0 = tick_count::now();
                graph_teach(map1, my_teaching);
                tick_count t1 = tick_count::now();
                
                if ( extra_debug )printf( "Done learning for [%d,%d], which took %g seconds ", xranges,yranges, (t1-t0).seconds());
                if(xranges == 1 && yranges == 1) single_time = (t1-t0).seconds();
                if ( extra_debug )printf( ": speedup == %g\n", single_time / (t1-t0).seconds());
    
            }  // yranges
        }  // xranges
    }  // #threads p
    printf("done\n");
    return 0;
}
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);
}
Beispiel #20
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;

}