Beispiel #1
0
	// Can copy all levels from a source 2d texture to a destination texture of equivalent storage_linear shape
	static int main()
	{
		int Error = 0;

		gli::texture2d const TextureExpected = make2d(gli::FORMAT_RGBA8_UNORM_PACK8, gli::texture2d::extent_type(8), glm::u8vec4(193, 127, 0, 255));

		// Scenario: Using gli::copy on a specialized texture 2d to copy all images at once
		{
			gli::texture2d TextureScenario(TextureExpected.format(), TextureExpected.extent());
			Error += TextureExpected != TextureScenario ? 0 : 1;

			gli::copy_level(TextureExpected, 0, TextureScenario, 0, TextureScenario.levels());
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		// Scenario: Using gli::copy on a specialized texture 2d to copy all images one by one
		{
			gli::texture2d TextureScenario(TextureExpected.format(), TextureExpected.extent());
			Error += TextureExpected != TextureScenario ? 0 : 1;

			for(gli::size_t LevelIndex = 0, LevelCount = TextureExpected.levels(); LevelIndex < LevelCount; ++LevelIndex)
				gli::copy_level(TextureExpected, LevelIndex, TextureScenario, LevelIndex);
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		// Scenario: Using gli::copy on a specialized texture 2d array
		{
			gli::texture2d_array TextureScenario(TextureExpected.format(), TextureExpected.extent(), 1);
			Error += TextureExpected != gli::texture2d(TextureScenario) ? 0 : 1;

			gli::copy_level(TextureExpected, 0, TextureScenario, 0, TextureScenario.levels());
			Error += TextureExpected == gli::texture2d(TextureScenario) ? 0 : 1;
		}

		// Scenario: Using gli::copy on a generic texture 2d to copy all images at once
		{
			gli::texture::extent_type const TextureExtent(TextureExpected.extent(), 1);
			gli::texture TextureScenario(TextureExpected.target(), TextureExpected.format(), TextureExtent, 1, 1, gli::levels(TextureExtent));
			Error += TextureExpected != TextureScenario ? 0 : 1;

			gli::copy_level(TextureExpected, 0, TextureScenario, 0, TextureExpected.levels());
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		// Scenario: Using gli::copy on a generic texture 2d to copy all images one by one
		{
			gli::texture::extent_type const TextureExtent(TextureExpected.extent(), 1);
			gli::texture TextureScenario(TextureExpected.target(), TextureExpected.format(), TextureExtent, 1, 1, gli::levels(TextureExtent));
			Error += TextureExpected != TextureScenario ? 0 : 1;

			for(gli::size_t LevelIndex = 0, LevelCount = TextureExpected.levels(); LevelIndex < LevelCount; ++LevelIndex)
				gli::copy_level(TextureExpected, LevelIndex, TextureScenario, LevelIndex);
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		// Scenario: Using member gli::texture::copy on a specialized texture 2d
		{
			gli::texture2d TextureScenario(TextureExpected.format(), TextureExpected.extent());
			Error += TextureExpected != TextureScenario ? 0 : 1;

			for(gli::size_t Level = 0; Level < TextureScenario.levels(); ++Level)
				TextureScenario.copy(TextureExpected, 0, 0, Level, 0, 0, Level);
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		// Scenario: Using member gli::texture::copy on a specialized texture 2d array
		{
			gli::texture2d_array TextureScenario(TextureExpected.format(), TextureExpected.extent(), 1);
			Error += TextureExpected != gli::texture2d(TextureScenario) ? 0 : 1;

			for(gli::size_t Level = 0; Level < TextureScenario.levels(); ++Level)
				TextureScenario.copy(TextureExpected, 0, 0, Level, 0, 0, Level);
			Error += TextureExpected == gli::texture2d(TextureScenario) ? 0 : 1;
		}

		// Scenario: Using member gli::texture::copy on a generic texture 2d
		{
			gli::texture::extent_type const TextureExtent(TextureExpected.extent(), 1);
			gli::texture TextureScenario(TextureExpected.target(), TextureExpected.format(), TextureExtent, 1, 1, gli::levels(TextureExtent));
			Error += TextureExpected != TextureScenario ? 0 : 1;

			for(gli::size_t Level = 0; Level < TextureExpected.levels(); ++Level)
				TextureScenario.copy(TextureExpected, 0, 0, Level, 0, 0, Level);
			Error += TextureExpected == TextureScenario ? 0 : 1;
		}

		return Error;
	}
Beispiel #2
0
t_genalg *init_ga(FILE *fplog, const char *infile, int D, t_range range[])
{
    FILE     *fpin_ptr;
    t_genalg *ga;
    double    ff = 0.0, cr = 0.0;
    int       i, j;

    /*------Initializations----------------------------*/
    snew(ga, 1);
    /*-----Read input data------------------------------------------------*/
    fpin_ptr   = gmx_fio_fopen(infile, "r");
    if (fscanf(fpin_ptr, "%d", &ga->NP) != 1         ||      /*---choice of strategy---*/
        fscanf(fpin_ptr, "%d", &ga->strategy) != 1   ||      /*---choice of strategy---*/
        fscanf(fpin_ptr, "%lf", &ff) != 1            ||      /*---weight factor------------*/
        fscanf(fpin_ptr, "%lf", &cr) != 1            ||      /*---crossing over factor-----*/
        fscanf(fpin_ptr, "%d", &ga->seed) != 1       ||      /*---random seed----------*/
        gmx_fio_fclose(fpin_ptr) != 1)
    {
        gmx_fatal(FARGS, "Error reading from file %s", infile);
    }

    ga->FF   = ff;
    ga->CR   = cr;
    ga->D    = D;
    ga->ipop = 0;
    ga->gen  = 0;

    /* Allocate memory */
    ga->pold = make2d(ga->NP, ga->D);
    ga->pnew = make2d(ga->NP, ga->D);
    snew(ga->tmp, ga->D);
    snew(ga->best, ga->D);
    snew(ga->bestit, ga->D);
    snew(ga->cost, ga->NP);
    snew(ga->msf, ga->NP);
    snew(ga->pres, ga->NP);
    snew(ga->scale, ga->NP);
    snew(ga->energy, ga->NP);

    /*-----Checking input variables for proper range--------------*/
    if ((ga->CR < 0) || (ga->CR > 1.0))
    {
        gmx_fatal(FARGS, "CR=%f, should be ex [0,1]", ga->CR);
    }
    if (ga->seed <= 0)
    {
        gmx_fatal(FARGS, "seed=%d, should be > 0", ga->seed);
    }
    if ((ga->strategy < 0) || (ga->strategy > 10))
    {
        gmx_fatal(FARGS, "strategy=%d, should be ex {1-10}", ga->strategy);
    }

    /* spread initial population members */
    for (i = 0; (i < ga->NP); i++)
    {
        for (j = 0; (j < ga->D); j++)
        {
            ga->pold[i][j] = value_rand(&(range[j]), &ga->seed);
        }
    }

    fprintf(fplog, "-----------------------------------------------\n");
    fprintf(fplog, "Genetic algorithm parameters\n");
    fprintf(fplog, "-----------------------------------------------\n");
    fprintf(fplog, "Number of variables:   %d\n", ga->D);
    fprintf(fplog, "Population size:       %d\n", ga->NP);
    fprintf(fplog, "Strategy:              %s\n", strat[ga->strategy]);
    fprintf(fplog, "Weight factor:         %g\n", ga->FF);
    fprintf(fplog, "Crossing over factor:  %g\n", ga->CR);
    fprintf(fplog, "Random seed:           %d\n", ga->seed);
    fprintf(fplog, "-----------------------------------------------\n");

    return ga;
}