int ZoltanLibClass::
color(Teuchos::ParameterList& zoltanParamList,
      std::vector<int>& properties)
{
  zoltanParamList_ = zoltanParamList;
  // Distance 2 coloring by default.
  if (!zoltanParamList_.isParameter("COLORING_PROBLEM"))
    zoltanParamList_.set("COLORING_PROBLEM", "DISTANCE-2");

  precompute();

  //Generate Load Balance
  int  num_gid_entries = 1;

  // Use ColMap to have directly answers for columns !
  properties.resize(num_obj_);

  // TODO64 - This only works if the global IDs fit in an int.

  ZOLTAN_ID_TYPE *gids=NULL;

  if (sizeof(ZOLTAN_ID_TYPE) != sizeof(int)){
    gids = new ZOLTAN_ID_TYPE [num_obj_];
    if (num_obj_ && ! gids){
      throw Isorropia::Exception("Out of memory in ZoltanLibClass::color()");
      return -1;
    }

    int *intIds = queryObject_->RowMap().MyGlobalElements();
    for (int i=0; i < num_obj_; i++){
      gids[i] = (ZOLTAN_ID_TYPE)intIds[i];
    }
  }
  else{
    gids = (ZOLTAN_ID_PTR)queryObject_->RowMap().MyGlobalElements();
  }

  int err = zz_->Color(num_gid_entries, num_obj_, gids, &properties[0]);

  if (sizeof(ZOLTAN_ID_TYPE) != sizeof(int)){
    delete [] gids;
  }

  if (err != ZOLTAN_OK){
    throw Isorropia::Exception("Error computing coloring with Zoltan");
    return -1;
  }

  postcompute();
  return (0);
}
Ejemplo n.º 2
0
int main()
{
	long long int n;
	//int t;
	precompute();
	//scanf("%d",&t);	
	//while(t--)
	//{
		scanf("%lld",&n);
		printf("%lld\n",A[n]+B[n]);
	//}

	return 0;
} 
Ejemplo n.º 3
0
    // Multipairing
    void do_multi(int m){
        int i = 0;
        lpoly list[m];
        lpoly *tmp_list;

        // prevalues

        element_t gg[m];
        element_ptr ggg[m];
        element_t hh[m];
        for(i = 0; i < m; i++){
            element_init_G2(gg[i], pairing);
            element_random(gg[i]);
            ggg[i] = malloc(sizeof(element_ptr));
            element_init(ggg[i], gg[i]->field);
            element_set(ggg[i], gg[i]);

            element_init_G1(hh[i], pairing);
            element_random(hh[i]);
        }


        // precomputation
        gettimeofday(&tvBegin, NULL);

        for(i = 0; i < m; i++){
            tmp_list = lpoly_init();
            precompute(tmp_list, pairing->r, hh[i], gg[i]);
            list[i] = *tmp_list;
        }

        gettimeofday(&tvEnd, NULL);
        timeval_subtract(&tvEnd, &tvBegin, 1000);

        // compute
        gettimeofday(&tvBegin, NULL);
        compute_millers(temp2, list, ggg, m, pairing);
        gettimeofday(&tvEnd, NULL);
        timeval_subtract(&tvEnd, &tvBegin, 1000);

        gettimeofday(&tvBegin, NULL);
        element_prod_pairing(temp1, hh, gg, m);
        gettimeofday(&tvEnd, NULL);
        timeval_subtract(&tvEnd, &tvBegin, 1000);

        for(i = 0; i < m; i++){
            lpoly_free2(list[i]);
        }
    }
Ejemplo n.º 4
0
Camera::Camera(const Mat4f &transform, const Vec2u &res)
: _tonemapOp("gamma"),
  _transform(transform),
  _res(res)
{
    _colorBufferSettings.setType(OutputColor);

    _pos    = _transform*Vec3f(0.0f, 0.0f, 2.0f);
    _lookAt = _transform*Vec3f(0.0f, 0.0f, -1.0f);
    _up     = _transform*Vec3f(0.0f, 1.0f, 0.0f);

    _transform.setRight(-_transform.right());

    precompute();
}
Ejemplo n.º 5
0
int main(int argc, char** args)
{
	precompute();

	int numTestCases;
	scanf("%d\n", &numTestCases);
	int n;
	while(numTestCases-->0)
	{
		scanf("%d\n", &n);
		factorial(n);
	}

	return 0;
}
Ejemplo n.º 6
0
void gcm_init(gcm* g,int nk,char *key,char *iv)
{ /* assumes iv is 96 bits/12 bytes. AES key can be 16,24 or 32 bytes */
	int i;
	MR_BYTE H[16];
	for (i=0;i<16;i++) {H[i]=0; g->stateX[i]=0;}

	aes_init(&(g->a),MR_ECB,nk,key,iv);
	aes_ecb_encrypt(&(g->a),H);     /* E(K,0) */
	precompute(g,H);
	g->counter=1;
	for (i=0;i<12;i++) g->a.f[i]=iv[i];
	unpack(g->counter,(MR_BYTE *)&(g->a.f[12]));  /* initialise IV */

	g->status=GCM_ACCEPTING_HEADER;
	g->lenA[0]=g->lenC[0]=g->lenA[1]=g->lenC[1]=0;
}
int ZoltanLibClass::
order(Teuchos::ParameterList& zoltanParamList,
      std::vector<int>& properties)
{
  zoltanParamList_ = zoltanParamList;

  precompute();

  /* Note : this works because epetra ordinal type is int */
  int num_gid_entries = 1;

  properties.resize(num_obj_);

  // TODO64 - This only works if the global IDs fit in an int.

  ZOLTAN_ID_TYPE *gids=NULL;

  if (sizeof(ZOLTAN_ID_TYPE) != sizeof(int)){
    gids = new ZOLTAN_ID_TYPE [num_obj_];
    if (num_obj_ && ! gids){
      throw Isorropia::Exception("Out of memory in ZoltanLibClass::order()");
      return -1;
    }

    int *intIds = queryObject_->RowMap().MyGlobalElements();
    for (int i=0; i < num_obj_; i++){
      gids[i] = (ZOLTAN_ID_TYPE)intIds[i];
    }
  }
  else{
    gids = (ZOLTAN_ID_PTR)queryObject_->RowMap().MyGlobalElements();
  }

  int err = zz_->Order(num_gid_entries, num_obj_, gids, &properties[0], NULL);

  if (sizeof(ZOLTAN_ID_TYPE) != sizeof(int)){
    delete [] gids;
  }

  if (err != ZOLTAN_OK){
    throw Isorropia::Exception("Error computing ordering with Zoltan");
    return -1;
  }

  postcompute();
  return (0);
}
bool CNumericalVGLikelihood::set_variational_distribution(SGVector<float64_t> mu,
	SGVector<float64_t> s2, const CLabels* lab)
{
	bool status = true;
	status = CVariationalGaussianLikelihood::set_variational_distribution(mu, s2, lab);

	if (status)
	{
		if (supports_binary())
		{
			REQUIRE(lab->get_label_type()==LT_BINARY,
				"Labels must be type of CBinaryLabels\n");
		}
		else
		{
			if (supports_regression())
			{
				REQUIRE(lab->get_label_type()==LT_REGRESSION,
					"Labels must be type of CRegressionLabels\n");
			}
			else
				SG_ERROR("Unsupported Label type\n");
		}

		if (supports_binary())
			m_lab=((CBinaryLabels*)lab)->get_labels();
		else
			m_lab=((CRegressionLabels*)lab)->get_labels();

		if (!m_is_init_GHQ)
		{
			m_xgh=SGVector<float64_t>(m_GHQ_N);
			m_wgh=SGVector<float64_t>(m_GHQ_N);
			CIntegration::generate_gauher(m_xgh, m_wgh);
			m_is_init_GHQ=true;
		}

		precompute();

	}

	return status;
}
Ejemplo n.º 9
0
/***********************************************************************//**
 * @brief Read point spread function from FITS table
 *
 * @param[in] table FITS table.
 *
 * @exception GException::invalid_value
 *            Response table is not three-dimensional.
 *
 * Reads the point spread function form the FITS @p table. The following
 * column names are mandatory:
 *
 *     ENERG_LO - Energy lower bin boundaries
 *     ENERG_HI - Energy upper bin boundaries
 *     THETA_LO - Offset angle lower bin boundaries
 *     THETA_HI - Offset angle upper bin boundaries
 *     RAD_LO   - Delta angle lower bin boundaries
 *     RAD_HI   - Delta angle upper bin boundaries
 *     RPSF     - PSF histogram
 *
 * The data are stored in the m_psf member. The energy axis will be set to
 * log10, the offset and delta angle axes to radians.
 ***************************************************************************/
void GCTAPsfTable::read(const GFitsTable& table)
{
    // Clear response table
    m_psf.clear();

    // Read PSF table
    m_psf.read(table);

    // Get mandatory indices (throw exception if not found)
    m_inx_energy = m_psf.axis("ENERG");
    m_inx_theta  = m_psf.axis("THETA");
    m_inx_delta  = m_psf.axis("RAD");
    m_inx_rpsf   = m_psf.table("RPSF");

    // Throw an exception if the table is not three-dimensional
    if (m_psf.axes() != 3) {
        std::string msg = "Expected three-dimensional point spread function "
                          "response table but found "+
                          gammalib::str(m_psf.axes())+
                          " dimensions. Please specify a three-dimensional "
                          "point spread function.";
        throw GException::invalid_value(G_READ, msg);
    }

    // Set energy axis to logarithmic scale
    m_psf.axis_log10(m_inx_energy);

    // Set offset angle axis to radians
    m_psf.axis_radians(m_inx_theta);

    // Set delta angle axis to radians
    m_psf.axis_radians(m_inx_delta);

    // Precompute PSF information
    precompute();

    // Return
    return;
}
bool CLogitVGPiecewiseBoundLikelihood::set_variational_distribution(SGVector<float64_t> mu,
	SGVector<float64_t> s2, const CLabels* lab)
{
	bool status = true;
	status=CVariationalGaussianLikelihood::set_variational_distribution(mu, s2, lab);
	if (status)
	{
		REQUIRE(lab->get_label_type()==LT_BINARY,
			"Labels must be type of CBinaryLabels\n");

		m_lab = (((CBinaryLabels*)lab)->get_labels()).clone();

		//Convert the input label to standard label used in the class
		//Note that Shogun uses  -1 and 1 as labels and this class internally uses
		//0 and 1 repectively.
		for(index_t i = 0; i < m_lab.size(); ++i)
			m_lab[i] = CMath::max(m_lab[i], 0.0);

		precompute();

	}
	return status;
}
void CDualVariationalGaussianLikelihood::set_dual_parameters(SGVector<float64_t> lambda,  const CLabels* lab)
{
	REQUIRE(lab, "Labels are required (lab should not be NULL)\n");

	REQUIRE((lambda.vlen==lab->get_num_labels()),
		"Length of the vector of lambda (%d) "
		"and number of labels (%d) should be the same\n",
		lambda.vlen, lab->get_num_labels());
	REQUIRE(lab->get_label_type()==LT_BINARY,
		"Labels (%s) must be type of CBinaryLabels\n",
		lab->get_name());

	m_lab=(((CBinaryLabels*)lab)->get_labels()).clone();

	//Convert the input label to standard label used in the class
	//Note that Shogun uses  -1 and 1 as labels and this class internally uses
	//0 and 1 repectively.
	for(index_t i = 0; i < m_lab.size(); ++i)
		m_lab[i]=CMath::max(m_lab[i], 0.0);

	m_lambda=lambda;

	precompute();
}
Ejemplo n.º 12
0
void Camera::prepareForRender()
{
    precompute();
}
Ejemplo n.º 13
0
void Camera::setLookAt(const Vec3f &lookAt)
{
    _lookAt = lookAt;
    _transform = Mat4f::lookAt(_pos, _lookAt - _pos, _up);
    precompute();
}
Ejemplo n.º 14
0
int main(void)
{

	pairing_t pairing;
    char param[50000];
    size_t count = fread(param, 1, 50000, stdin);
    if (!count) pbc_die("input error");
    pairing_init_set_buf(pairing, param, count);

//    int cont = 0;

    struct timeval tvBegin, tvEnd;

    element_t g, h;
    element_t public_key, secret_key;
    element_t sig;
    element_t temp1, temp2;

    element_init_G2(g, pairing);
    element_init_G2(public_key, pairing);
    element_init_G1(h, pairing);
    element_init_G1(sig, pairing);
    element_init_GT(temp1, pairing);
    element_init_GT(temp2, pairing);
    element_init_Zr(secret_key, pairing);

    // Generating key
    element_random(g);
    element_random(secret_key);
    element_pow_zn(public_key, g, secret_key);

    // Generating message
    element_from_hash(h, "ABCDEF", 6);

    element_pow_zn(sig, h, secret_key);


    // RANDOM TESTS
    /*

    // Fp

    element_t p1, p2;
    element_init(p1, element_x(h)->field);
    element_init(p2, p1->field);
    element_random(p1);
    element_random(p2);

    // multiplication

    element_t puntos[2000];
    for(cont = 0; cont < 1000; cont++){
        element_init(puntos[cont], element_x(h)->field);
        element_init(puntos[2*cont], element_x(h)->field);
        element_random(puntos[cont]);
        element_random(puntos[2*cont]);
    }

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++){
        element_mul(puntos[cont], puntos[cont], puntos[2*cont]);
    }

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    //square

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) element_square(puntos[cont], puntos[2*cont]);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    // add

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) element_add(puntos[cont], puntos[cont], puntos[2*cont]);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    // invers

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) element_invert(puntos[cont], puntos[2*cont]);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);






    // Fpk

    element_t q1, q2;
    element_init_GT(q1, pairing);
    element_init_GT(q2, pairing);
    element_random(q1);
    element_random(q2);

    // multiplication

    for(cont = 0; cont < 1000; cont++){
        element_init_GT(puntos[cont], pairing);
        element_init_GT(puntos[2*cont], pairing);
        element_random(puntos[cont]);
        element_random(puntos[2*cont]);
    }

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) {
        element_mul(puntos[cont], puntos[cont], puntos[2*cont]);
    }

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    //square

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) element_square(puntos[cont], puntos[cont]);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    // add

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++){
        element_add(element_x(puntos[cont]), element_x(puntos[cont]), element_x(puntos[2*cont]));
        element_add(element_y(puntos[cont]), element_y(puntos[cont]), element_y(puntos[2*cont]));
    }

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    // invers

    gettimeofday(&tvBegin, NULL);

    for(cont = 0; cont < 1000; cont++) element_invert(puntos[cont], puntos[2*cont]);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);






    // CURVE OPERATIONS

    element_t punto, punto2;
    element_init(punto, h->field); element_random(punto);
    element_init(punto2, h->field); element_random(punto2);

    // add

    gettimeofday(&tvBegin, NULL);

    element_mul(punto, punto, punto2);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);

    // double

    gettimeofday(&tvBegin, NULL);

    element_double(punto, punto2);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1);










   // SIZE GROUP
    int m = mpz_sizeinbase(pairing->r, 2) - 2;
    printf("%i\n",  m);
    int contador = 0;
    for(;;){
        if(!m) break;
        if(mpz_tstbit(pairing->r,m)) contador++;
        m--;
    }
    printf("%i\n", contador);




*/


    // One pairing
    gettimeofday(&tvBegin, NULL);

    eval_miller(temp1, sig, g, pairing);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1000);

    //print_contador();



    // One pairing (with precomputed values)

    // Original method


    pairing_pp_t pp;
    // Precomp
    gettimeofday(&tvBegin, NULL);

    pairing_pp_init(pp, sig, pairing);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1000);

    // Eval
    gettimeofday(&tvBegin, NULL);

    pairing_pp_apply(temp1, g, pp);

    gettimeofday(&tvEnd, NULL);
    timeval_subtract(&tvEnd, &tvBegin, 1000);


    pairing_pp_clear(pp);



    void do_precomp(){
        lpoly *list;

        // precomputation
        gettimeofday(&tvBegin, NULL);

        list = lpoly_init();
        precompute(list, pairing->r, sig, g);

        gettimeofday(&tvEnd, NULL);
        timeval_subtract(&tvEnd, &tvBegin, 1000);

        // DMAX
        printf("%i\n", list->MAXD);

        // eval
        gettimeofday(&tvBegin, NULL);

        compute_miller(temp2, list, g, pairing);

        gettimeofday(&tvEnd, NULL);
        timeval_subtract(&tvEnd, &tvBegin, 1000);

        lpoly_free(list);
    }
Ejemplo n.º 15
0
int main(int argc, char *argv[])
	{
	precompute();
#ifdef USE_HASH
	hash_init();
#endif
	// load_endgames();
//	load_bitbases();
	if (argc == 2 && !strcmp(argv[1], "nobook"))
		{
		printf("Skipping opening book\n");
		}
	else if (argc == 2 && !strcmp(argv[1], "makebook"))
		{
		load_opening_book(1);
		opening_book_grow(0);
		return 0;
		}
	else if (argc == 2 && !strcmp(argv[1], "showbook"))
		{
		load_opening_book(1);
		opening_book_grow(1);
		return 0;
		}
	else
		load_opening_book(2);
	new_game();

	int ply;

	int i, j, k;

	FILE * input;
	FILE * output;

	char command[80] = "";
	char buffer[4100] = "";


/*	if (argc == 2 && !strcmp(argv[1], "files"))
		{
		printf("Using files for I/O\n");
		input = fopen("input.txt", "r+");
		output = fopen("output.txt", "w");
		}
	else */
		{
		input = stdin;
		output = stdout;
		}

	if (argc == 2 && !strcmp(argv[1], "bitbases"))
		{
		bitbase_report();
		return 0;
		}

	if (argc == 7 && !strcmp(argv[1], "position"))
		{
		i = bitbase_test(
			atoi(argv[2])
			,atoi(argv[3])
			,atoi(argv[4])
			,atoi(argv[5])
			,atoi(argv[6])
			);
		printf("%s\n", i ? "is a win for black" : "not a win for black");

		int pieces[MAX_BDB_PIECES];
		int total_pieces = 0;

		for (i = 0; i < atoi(argv[2]); ++i) pieces[total_pieces++] = 0;
		for (i = 0; i < atoi(argv[3]); ++i) pieces[total_pieces++] = 1;
		for (i = 0; i < atoi(argv[4]); ++i) pieces[total_pieces++] = 2;
		for (i = 0; i < atoi(argv[5]); ++i) pieces[total_pieces++] = 3;

		position_decode(atoi(argv[6]), pieces, total_pieces);

		print_board(0);

		return 0;
		}

	if (argc == 2 && !strcmp(argv[1], "sanity"))
		{
		sanity_checks();
		memory_report();
		return 0;
		}

	if (argc == 2 && !strcmp(argv[1], "perft"))
		{
		iterative_performance_test();
#ifdef SORT_STATISTIC
	for (i = 0; i < 5; ++i)
		printf("Returns at sort level %d: %d\n"
			, i
			, sort_statistic[i]);
#endif
		return 0;
		}

	if (argc >= 4 && !strcmp(argv[1], "pdn"))
		{
		ply = 0;

		FILE * pdn;

		pdn = fopen(argv[3], "a+");
		if (!pdn)
			{
			printf("error: fopen \"%s\" for append/create\n", argv[3]);
			// printf("err: %d - %s\n", errno, strerror(errno));
			// getcwd(buffer, sizeof(buffer));
			// printf("pwd: %s\n", buffer);
			return 1;
			}
		while (!feof(pdn)) // fixme: this loader sux...
			{
			if (!fgets(buffer, 4096, pdn))
				break;

			//if (!buffer || feof(pdn))
			//	break;

			i = 0;
			while (j = load_move_from_pdn(buffer, command, &i))
				{
				generate_moves(0, 0);
				k = find_move(0, command);
				if (k < 0 || k >= move_counter[0])
					{
					fprintf(output, "error invalid move from pdn (%s)\n"
						, command);
					for (k = 0; k < move_counter[0]; ++k)
						{
						fprintf(output, "move %d ",k);
						print_move(&moves[0][k], 0);
						fprintf(output, "\n");
						}
					}
				else
					{
					++ply;
					//fprintf(output, "executing move at index %d: ", k);
					if (!strcmp(argv[2], "show") || !strcmp(argv[2], "step"))
						{
						if (ply % 2 == 1)
							printf("%3d. ", (ply+1) / 2);
						print_move(&moves[0][k], 0);
						if (ply % 2 == 0)
							{
							printf("\n");
							//print_board(0);
							}
						else
							printf(" ");
						if (!strcmp(argv[2], "step") && ply % 2 == 0)
							{
							print_board(0);
							getc(stdin);
							}
						}
					//fprintf(output, "\n");
					move_do(&moves[0][k], 0);
					move_list_push(&moves[0][k]);
					}
				}
			if (feof(pdn))
				break;
			}
		fclose(pdn);

		if (!strcmp(argv[2], "play"))
			{
			pdn = fopen(argv[3], "a");
			if (!pdn)
				{
				printf("error: fopen \"%s\" for append\n", argv[3]);
				return 1;
				}

			if (argc >= 5 && strcmp(argv[4], "hint") && strcmp(argv[4], "move"))
				{
				generate_moves(0, 0);
				i = find_move(0, argv[4]);
				if (i < 0 || i >= move_counter[0])
					{
					print_moves(0);
					i = -1;
					}
				else
					{
					move_do(&moves[0][i], 0);
					move_list_push(&moves[0][i]);
					fprintf(pdn, "%s ", argv[4]);
					if (moves[0][i].same_player_square != -1)
						i = -1;
					}
				}

			if (i != -1)
				{
				if (argc >= 6)
					strength = atoi(argv[5]);
				if (argc >= 7)
					thinking_time = atoi(argv[6]);

				if (strength == 1)
					thinking_time = 1;

				if (!strcmp(argv[4], "hint"))
					bestmove(0, 0);
				else
					while (bestmove(pdn, 1));
				}

			fclose(pdn);
			fprintf(output, "boardok ");
			for (i = 0; i < 64; ++i)
				fprintf(output, "%d", board[i]);
			fprintf(output, " %d", state.tactical_square);
			fprintf(output, " %d", state.side_to_move);
			fprintf(output, " %d", state.this_piece_must_take);
			fprintf(output, "\n");
			}
		else
			{
			print_board(0);
//debug_moves = 1;
			generate_moves(0, 0);
			if (!strcmp(argv[2], "show"))
				print_moves(0);
			}

		if (!strcmp(argv[2], "load"))
			{
			printf("PDN loaded\n");
			command[0] = 0;
			buffer[0] = 0;
			}
		else
			return 0;
		}

	for (;;)
		{
		fscanf(input, "%20s", command);

		if (parse(command, "quit"))
			break;
		else if (parse(command, "gnt"))
			fprintf(output, "id name GNTredux\nid author QuakePhil\ngntok\n");
		else if (parse(command, "new"))
			new_game();
		else if (parse(command, "flipside"))
			state.side_to_move ^= 1;
		else if (parse(command, "flipkings"))
			{
			for (i = 0; i < 64; ++i) if (initial_board[i] != 4)
				{
				if (initial_board[i] < 2)
					initial_board[i] += 2;
				else
					initial_board[i] -= 2;
				}
			new_game();
			}
		else if (parse(command, "flipboardonly"))
			{ // fixme: need to re-do materials here?
			int temp[64];
			int flip_piece[5] = {1,0,3,2,4};
			j = 64;
			for (i = 0; i < 64; ++i)
				temp[--j] = flip_piece[board[i]];
			for (i = 0; i < 64; ++i)
				board[i] = temp[i];
			state.side_to_move ^= 1;
			}
		else if (parse(command, "rand"))
			rand_board();
		else if (parse(command, "think"))
			{
			bestmove(0, 0);
			}
		else if (parse(command, "go"))
			{
			bestmove(0, 1);
			}
		else if (parse(command, "perft"))
			{
			iterative_performance_test();
			}
		else if (parse(command, "ping"))
			{
			fprintf(output, "pong %.6lf\n", timer());
			}
		else if (parse(command, "pboard"))
			print_board(0);
		else if (parse(command, "board"))
			{
			fprintf(output, "boardok ");
			for (i = 0; i < 64; ++i)
				fprintf(output, "%d", board[i]);
			fprintf(output, " %d", state.tactical_square);
			fprintf(output, " %d", state.side_to_move);
			fprintf(output, " %d", state.this_piece_must_take);
			fprintf(output, "\n");
			}
		else if (parse(command, "time"))
			{
			fscanf(input, "%d", &thinking_time);
			printf("Think time limit set to: %d seconds\n", thinking_time);
			}
		else if (parse(command, "pdn"))
			{
			fscanf(input, "%20s", buffer);
			generate_moves(0, 0);
			i = find_move(0, buffer);
			if (i < 0 || i >= move_counter[0])
				fprintf(output, "error invalid move\n");
			else
				{
				move_do(&moves[0][i], 0);
				move_list_push(&moves[0][i]);
				//fprintf(output, "executing move at index %d: ", i);
				//print_move(&moves[0][i], 0);
				//fprintf(output, "\n");
				fprintf(output, "done\n");
				}
			}
		else if (parse(command, "do") || parse(command, "toggle"))
			{
			fscanf(input, "%d", &i);
			fprintf(output, "executing move %d\n", i);
			generate_moves(0, 0);
			if (i < 0)
				fprintf(output, "error move can't be negative\n");
			else if (i >= move_counter[0])
				fprintf(output, "error no such move\n");
			else
				{
				move_do(&moves[0][i], 0);
				move_list_push(&moves[0][i]);

				if (parse(command, "toggle"))
					{
					print_board(0);
					fprintf(output, "undoing move %d\n", i);
					move_undo(&moves[0][i], 0);
					print_board(0);
					}
				}
			fprintf(output, "done\n");
			}
		else if (parse(command, "list"))
			{
			print_move_list();
			}
		else if (parse(command, "pbook"))
			{
			print_book();
			}
		else if (parse(command, "moves"))
			{
			generate_moves(0, 0);
			for (i = 0; i < move_counter[0]; ++i)
				{
				fprintf(output, "move %d ",i);
				print_move(&moves[0][i], 1);
				fprintf(output, "\n");
				}
			fprintf(output, "movesok\n");
			}
		else // if (!strcmp(command, "help"))
			{
			// fprintf(output, "?\n");
			}

		fflush(output);
		}

#ifdef HASH_STATISTIC
	printf("Hash saves:      %d\n", hash_saves);
	printf("Hash collisions: %d\n", hash_collisions);
	printf("Hash probes:     %d\n", hash_probes);
	printf("Hash hits:       %d\n", hash_hits);
#endif

#ifdef SORT_STATISTIC
	for (i = 0; i < 5; ++i)
		printf("Returns at sort level %d: %d\n"
			, i
			, sort_statistic[i]);
#endif

	fclose(output);
	fclose(input);

	return 0;
	}
Ejemplo n.º 16
0
void Camera::setUp(const Vec3f &up)
{
    _up = up;
    _transform = Mat4f::lookAt(_pos, _lookAt - _pos, _up);
    precompute();
}
Ejemplo n.º 17
0
PinholeCamera::PinholeCamera(const Mat4f &transform, const Vec2u &res, float fov)
: Camera(transform, res),
  _fovDeg(fov)
{
    precompute();
}
int ZoltanLibClass::
repartition(Teuchos::ParameterList& zoltanParamList,
            std::vector<int>& properties,
            int& exportsSize,
            std::vector<int>& imports)
{
  zoltanParamList_  = zoltanParamList;

  // Avoid to construct import list.
  // Perhaps "PARTITION ASSIGNMENTS" will be better in term of performance.
  zoltanParamList_.set("RETURN_LISTS", "EXPORT AND IMPORT");

  preCheckPartition();
  precompute();

  // Set part sizes

  if (numPartSizes > 0){
    int err;
    int *wgtIdx = NULL;

    err = zz_->LB_Set_Part_Sizes(1, numPartSizes, partGIDs, wgtIdx, partSizes);

    if (err != ZOLTAN_OK){
      throw Isorropia::Exception("Error in LB_Set_Part_Sizes");
      return -1;
    }
  }

  //Generate Load Balance
  int changes=0, num_gid_entries=0, num_lid_entries=0, num_import=0, num_export=0;
  ZOLTAN_ID_PTR import_global_ids=NULL, import_local_ids=NULL;
  ZOLTAN_ID_PTR export_global_ids=NULL, export_local_ids=NULL;
  int * import_procs=NULL, * export_procs=NULL;
  int *import_to_part=NULL, *export_to_part=NULL;

  int err = zz_->LB_Partition(changes, num_gid_entries, num_lid_entries,
   num_import, import_global_ids, import_local_ids, import_procs, import_to_part,
   num_export, export_global_ids, export_local_ids, export_procs, export_to_part );

  if (err != ZOLTAN_OK){
    throw Isorropia::Exception("Error computing partitioning with Zoltan");
    return -1;
  }

  exportsSize = num_export;
  imports.clear();
  imports.assign(import_global_ids, import_global_ids + num_import);

  properties.assign(num_obj_, queryObject_->RowMap().Comm().MyPID());

  for( int i = 0; i < num_export; ++i )
  {
    properties[export_local_ids[i]] = export_to_part[i];
  }

  //Free Zoltan Data
  zz_->LB_Free_Part(&import_global_ids, &import_local_ids,
                     &import_procs, &import_to_part);
  zz_->LB_Free_Part(&export_global_ids, &export_local_ids,
                     &export_procs, &export_to_part);

  postcompute();

  return (0);
}
Ejemplo n.º 19
0
Gaussian::Gaussian(double alpha, int m, int n, int N) : SmoothingFunction(alpha, m, n, N)
{
	precompute();
}
Ejemplo n.º 20
0
PinholeCamera::PinholeCamera()
: Camera(),
  _fovDeg(60.0f)
{
    precompute();
}
Ejemplo n.º 21
0
 ReconstructionFilter(const std::string &name = "tent")
 : _typeString(name),
   _type(stringToType(name))
 {
     precompute();
 }
Ejemplo n.º 22
0
Quad4ShapeFunction::Quad4ShapeFunction(const MasterElement &mel)
  : ShapeFunction(4, mel)
{
  precompute(mel);
}
Ejemplo n.º 23
0
Tri3ShapeFunction::Tri3ShapeFunction(const MasterElement &mel)
  : ShapeFunction(3, mel)
{
  precompute(mel);
}
Ejemplo n.º 24
0
CFeatures* CFeatureSelection<ST>::apply_backward_elimination(CFeatures* features)
{
	SG_DEBUG("Entering!\n");

	// precompute whenever appropriate for performing the rest of the tasks
	precompute();

	// NULL check for features is handled in get_num_features
	index_t num_features=get_num_features(features);
	SG_DEBUG("Initial number of features %d!\n", num_features);

	// the main loop
	while (num_features>m_target_dim)
	{
		// tune the measurement parameters whenever necessary based on current
		// features
		adapt_params(features);

		// compute the measures for each of the current dimensions
		SGVector<float64_t> measures(num_features);
		for (index_t i=0; i<num_features; ++i)
			measures[i]=compute_measures(features, i);

		if (io->get_loglevel()==MSG_DEBUG || io->get_loglevel()==MSG_GCDEBUG)
			measures.display_vector("measures");

		// rank the measures
		SGVector<index_t> argsorted=CMath::argsort(measures);

		if (io->get_loglevel()==MSG_DEBUG || io->get_loglevel()==MSG_GCDEBUG)
			argsorted.display_vector("argsorted");

		// make sure that we don't end up with lesser feats than target dim
		index_t to_remove;
		if (m_policy==N_SMALLEST || m_policy==N_LARGEST)
			to_remove=m_num_remove;
		else
			to_remove=num_features*m_num_remove*0.01;

		index_t can_remove=num_features-m_target_dim;

		// if policy is to remove N feats corresponding to smallest/largest
		// measures, we just replace N with can_remove. if policy is to remove
		// N% feats, then we change the policy temporarily and remove a fixed
		// can_remove number of feats instead
		index_t orig_remove=m_num_remove;
		EFeatureRemovalPolicy orig_policy=m_policy;

		if (to_remove>can_remove)
		{
			m_num_remove=can_remove;
			SG_DEBUG("Can only remove %d features in this iteration!\n",
					can_remove);

			if (m_policy==PERCENTILE_SMALLEST)
				m_policy=N_SMALLEST;
			else if (m_policy==PERCENTILE_LARGEST)
				m_policy=N_LARGEST;
		}

		// remove appropriate number of features based on the measures and the
		// removal policy. this internally update the subset for selected
		// features as well
		features=remove_feats(features, argsorted);

		// restore original removal policy and numbers if necessary for the
		// sake of consistency
		if (to_remove>can_remove)
		{
			m_policy=orig_policy;
			m_num_remove=orig_remove;
		}

		// update the number of features
		num_features=get_num_features(features);
		SG_DEBUG("Current number of features %d!\n", num_features);
	}

	// sanity check
	ASSERT(m_subset->get_size()==m_target_dim);

	SG_DEBUG("Leaving!\n");
	return features;
}
Ejemplo n.º 25
0
void Camera::setPos(const Vec3f &pos)
{
    _pos = pos;
    _transform = Mat4f::lookAt(_pos, _lookAt - _pos, _up);
    precompute();
}
Ejemplo n.º 26
0
int main (int argc, char *argv[])
{



printf("Number of haplotypes: %d\n", atoi(argv[1]) );
int temp =0;
temp = atoi(argv[1]);
printf("Number of time intervals:  %d\n", atoi(argv[2]) );

printf("File name:  %s\n", argv[3] );

 int num_haps = atoi(argv[1]);
 int num_times = atoi(argv[2]);


//make_bins(num_haps);
//readfile(argv[3]);
read_binned_file(argv[3]);
//make_custom_bins(num_haps); // one bin per match length
// printf("num_loci = %d\n", num_loci);
// printf("marker %f\n", 1.7);
// printf("a;lskdjf %d\n", 3);


make_times(num_haps, num_times);
read_quant_file(argv[4]);
precompute(num_haps, num_times);




/*
 struct scenario the_scenario;
the_scenario.num_haps = argv[1];
the_scenario.num_times = argv[2];*/



  size_t iter = 0;
//  size_t i; // commented out to fix the problem labelled XYRQ below
		// there was a comparison between signed/unsiged int
  
int status;

  const gsl_multimin_fdfminimizer_type *T;
  gsl_multimin_fdfminimizer *s;

  /* Position of the minimum (1,2). */

int j=0;

double par[2];

par[0] = num_haps;
par[1] = num_times;

  gsl_vector *x;
  gsl_multimin_function_fdf my_func;

  my_func.f = &my_f;
  my_func.df = &my_df;
  my_func.fdf = &my_fdf;
  my_func.n = num_times;
  my_func.params = &par;


  /* Starting point, x = (5,7) */

  x = gsl_vector_alloc (num_times);

for (j=0; j<num_times; j++)
{
if(j<=50){gsl_vector_set (x, j, 30000  );}
else {gsl_vector_set (x, j, 20000   );}
}

 T = gsl_multimin_fdfminimizer_conjugate_fr;
//   T = gsl_multimin_fdfminimizer_vector_bfgs2;

  s = gsl_multimin_fdfminimizer_alloc (T, num_times);

// likelihood setting
  gsl_multimin_fdfminimizer_set (s, &my_func, x, 10000, .000001);

//  quantile setting
  //gsl_multimin_fdfminimizer_set (s, &my_func, x, 3000.0, .100);


  do
    {

      iter++;
      status = gsl_multimin_fdfminimizer_iterate (s);

	//printf("help %d\n", 3);

      if (status){
printf ("Iteration terminated at:\nSTART HERE\n");

	//printf ("%5zu ", iter);  // using %zu instead of %d b/c iter is type size_t not type int
			int k=0;
			for (k = 0; k < num_times; k++)  
			{
			printf ("%f\t%10.3f\n", time[k], gsl_vector_get (s->x, k));  // problem XYRQ
						// using k here renders size_t i above unused
			}
	printf ("f() = %7.3f \n", s->f);
//  q
        break;}

//printf("help %d\n", 4);


 //.likelihood setting
	status = gsl_multimin_test_gradient (s->gradient, 1e-10 );

// quantile setting
//	status = gsl_multimin_test_gradient (s->gradient, .010 );


      if (status == GSL_SUCCESS)
 { printf ("Minimum found at:\nSTART HERE\n");}
			int k=0;
 			for (k = 0; k < num_times; k++)  
 			{
 			printf ("%f\t%10.3f\n", time[k], gsl_vector_get (s->x, k)); // problem XYRQ
 						// using k here renders size_t i above unused
 			}
	//printf ("f() = %7.3f \n", s->f);
      
// 	  printf ("Minimum found at:\n");
// 
// 	printf ("%5zu ", iter);  // using %zu instead of %d b/c iter is type size_t not type int
// 			int k=0;
// 			for (k = 0; k < num_times; k++)  
// 			{
// 			printf ("%10.3e ", gsl_vector_get (s->x, k)); // problem XYRQ
// 						using k here renders size_t i above unused
// 			}
 	

	
//       printf ("%5d %.5f %.5f %10.5f\n", iter,
//               gsl_vector_get (s->x, 0),
//               gsl_vector_get (s->x, 1),
//               s->f);

    }

  while (status == GSL_CONTINUE && iter < 1000);

  gsl_multimin_fdfminimizer_free (s);
  gsl_vector_free (x);


  return 0;

}
Ejemplo n.º 27
0
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
  {
  QCADRectangleElectrode *rc_electrode = QCAD_RECTANGLE_ELECTRODE (object) ;

  switch (property_id)
    {
    case QCAD_RECTANGLE_ELECTRODE_PROPERTY_CX:
      {
      double new_cx = g_value_get_double (value) ;

      if (new_cx == rc_electrode->cxWorld) break ;
      rc_electrode->cxWorld = new_cx ;
      precompute (QCAD_ELECTRODE (object)) ;
      g_object_notify (object, "width") ;
      break ;
      }

    case QCAD_RECTANGLE_ELECTRODE_PROPERTY_CY:
      {
      double new_cy = g_value_get_double (value) ;

      if (new_cy == rc_electrode->cyWorld) break ;
      rc_electrode->cyWorld = new_cy ;
      precompute (QCAD_ELECTRODE (object)) ;
      g_object_notify (object, "height") ;
      break ;
      }

    case QCAD_RECTANGLE_ELECTRODE_PROPERTY_X_DOTS:
      {
      guint new_x_dots = g_value_get_uint (value) ;

      if (new_x_dots == rc_electrode->n_x_divisions) break ;
      rc_electrode->n_x_divisions = new_x_dots ;
      precompute (QCAD_ELECTRODE (object)) ;
      g_object_notify (object, "x-dots") ;
      break ;
      }

    case QCAD_RECTANGLE_ELECTRODE_PROPERTY_Y_DOTS:
      {
      guint new_y_dots = g_value_get_uint (value) ;

      if (new_y_dots == rc_electrode->n_y_divisions) break ;
      rc_electrode->n_y_divisions = new_y_dots ;
      precompute (QCAD_ELECTRODE (object)) ;
      g_object_notify (object, "y-dots") ;
      break ;
      }

    case QCAD_RECTANGLE_ELECTRODE_PROPERTY_ANGLE:
      {
      double new_angle = g_value_get_double (value) ;

      if (new_angle == rc_electrode->angle) break ;
      rc_electrode->angle = new_angle ;
      precompute (QCAD_ELECTRODE (object)) ;
      g_object_notify (object, "angle") ;
      break ;
      }
    }
  }