void __multi_array<T, RANK>::InternalGetReference(void* elemRef, int32_t rank, int32_t* pIndices)
{
	if (rank != RANK)
	{
		throw __new<::CoreLib::System::RankException>(u"rank"_s);
	}

	if (elemRef == nullptr)
	{
		throw __new<::CoreLib::System::ArgumentNullException>(u"elemRef"_s);
	}	

	if (pIndices == nullptr)
	{
		throw __new<::CoreLib::System::ArgumentNullException>(u"pIndices"_s);
	}	

	auto index = calculate_index(pIndices);
	if (index < 0 || index >= this->get_Length())
	{
		throw __new<::CoreLib::System::IndexOutOfRangeException>();
	}	

	auto typedRef = reinterpret_cast<::CoreLib::System::TypedReference*>(elemRef);
	typedRef->Value = __init<::CoreLib::System::IntPtr>((void*)&this->_data[index]);
	typedRef->Type = __init<::CoreLib::System::IntPtr>((void*)_typeMT<T>());
}
Example #2
0
int main(int argc, char *argv){
  unsigned long ans = 1,max,i, mod_constant = 1000000009;
  UD *bottom, *trav1, *trav2, *temp, *prev;
  printf("Enter the number whose factorial you want to factorize:");

  scanf("%lu", &max);
  printf("Initializing ..");
  trav1 = bottom = make_ud(2);
  for(i = 3 ; i <= max; i += 2){
    trav1->next = make_ud(i);
    trav1->next->prev = trav1;
    trav1 = trav1->next;
  }
  printf("Done\nFactorizing & calculating .. ");
  calculate_index(bottom, max);
  i = (1 + pow_modn(bottom->num, 2 * bottom->index, mod_constant)) % mod_constant;
  ans = ((ans * i) % mod_constant);
  printf("\n%lu, %u :> %lu :> %lu, ", bottom->num, bottom->index, i, ans);
  trav1 = bottom->next;
  while(trav1 != NULL){
    trav2 = trav1->next;
    prev = trav1;
#pragma omp parallel
    {
      while(trav2 != NULL){
        if((trav2->num) % (trav1->num) == 0){
          prev->next = trav2->next;
          trav2->is_prime = FALSE;
        } else
          prev = trav2;
        trav2 = trav2->next;
      }
    }
    calculate_index(trav1, max);
    i = (1 + pow_modn(trav1->num, 2 * trav1->index, mod_constant)) % mod_constant;
    ans = ((ans * i) % mod_constant);
    printf("\n%lu, %u :> %lu :> %lu, ", trav1->num, trav1->index, i, ans);
    while(trav != NULL && !trav->is_prime) trav1 = trav1->next;
  }
  printf("\n..Done\n");

  printf("The required answer is %lu\n", ans);
  return 0;
}
void get_index()
{
    char ch;
	int i, k;
	double c;
	double deviation = 100;
	FILE* fp = fopen(file_name6, "r");
	FILE* fp1 = fopen(file_name8, "r");
	if(!fp)
		exit(0);
	if(!fp1)
		exit(0);
 
    min_distance = (double* ) malloc(sizeof(double) * N);
	data_set = (double** ) malloc(sizeof(double*) * N);
	data_set_index = (int*) malloc(sizeof(int) * N);
	for(i=0;i < N; ++i){
        data_set_index[i] = 0;
        min_distance[i] = 0;     
        data_set[i]=(double *)malloc(sizeof(double) * NO_OF_CEP);
		for(k = 0; (k < NO_OF_CEP) && (!feof(fp)); ++k){
			fscanf(fp, "%lf", &c);
			data_set[i][k] = c;
		}
    }

	cluster_length = (int*) malloc(sizeof(int) * K );
    
    centroid = (double**) malloc(sizeof(double*) * K);
    for(i=0;i < K; ++i){
        centroid[i] = (double*) malloc(sizeof(double) * NO_OF_CEP );
        			
		for(k = 0; (k < NO_OF_CEP) && (!feof(fp1)); ++k){
			fscanf(fp1, "%lf", &c);
			//printf("%35.30lf\t", c);
			centroid[i][k] = c;
			//printf("%35.30lf\t", centroid[i][k]);
		}
    }
    for(i = 0; i < K; ++i)
        cluster_length[i] = 0;
        
    prev_distortion = 1000;
    i = 0;
    calculate_index();
    //fprintf(fp_log, "Kmeans ends\n");
	fclose(fp);
	fclose(fp1);
}
int
brhist_init(const lame_global_flags * gf, const int bitrate_kbps_min, const int bitrate_kbps_max)
{
    brhist.hist_printed_lines = 0;

    /* initialize histogramming data structure */
    lame_bitrate_kbps(gf, brhist.kbps);
    brhist.vbr_bitrate_min_index = calculate_index(brhist.kbps, BRHIST_WIDTH, bitrate_kbps_min);
    brhist.vbr_bitrate_max_index = calculate_index(brhist.kbps, BRHIST_WIDTH, bitrate_kbps_max);

    if (brhist.vbr_bitrate_min_index >= BRHIST_WIDTH ||
        brhist.vbr_bitrate_max_index >= BRHIST_WIDTH) {
        error_printf("lame internal error: VBR min %d kbps or VBR max %d kbps not allowed.\n",
                     bitrate_kbps_min, bitrate_kbps_max);
        return -1;
    }

    memset(brhist.bar_asterisk, '*', sizeof(brhist.bar_asterisk) - 1);
    memset(brhist.bar_percent, '%', sizeof(brhist.bar_percent) - 1);
    memset(brhist.bar_space, '-', sizeof(brhist.bar_space) - 1);
    memset(brhist.bar_coded, '-', sizeof(brhist.bar_space) - 1);

    return 0;
}
static ll stressful(int a, int b) {
	int index = calculate_index(a, b);

	if (cache_stressful[index] == -1)

		cache_stressful[index] =
			a  > b ? stressful(b, b) :
			a == 0 ? 1 :
			(
				(
					(b > a ? stressful(a, b-1) : 0) +
					(a > 0 ? stressful(a-1, b) : 0)
				) % 1000000007LL
			);

	return cache_stressful[index];
}
static ll stressfree(int a, int b) {
	int index = calculate_index(a, b);

	if (cache_stressfree[index] == -1)

		cache_stressfree[index] =
			(b == 0) ? 1 :
			(a == 0) ? 0 :
			(
				(
					((b > 0)   ? stressfree(a, b-1) : 0) +
					((a > b+1) ? stressfree(a-1, b) : 0)
				) % 1000000007LL
			);

	return cache_stressfree[index];
}
Example #7
0
MonoMissile::MonoMissile( SpaceLocation* creator, double ox, double oy, double oangle,
double ov, int odamage, double orange, int oarmour,
SpaceLocation *opos, SpaceSprite *osprite, SpaceObject* otarget ) :
HomingMissile( creator, Vector2(ox,oy), oangle, ov, odamage, orange, oarmour,
0, opos, osprite, otarget )
{
	STACKTRACE;

	/*
	while (angle < 0)
	angle += PI2;
	int iangle = (int)((angle + PI/4) / (PI/2)) % 4;
	angle = iangle * PI/2;
	sprite_index = iangle;
	*/
	calculate_index();
	from_beacon = to_beacon = NULL;
	set_up_beacons();
	last_target = target;

	//attributes &= ~ATTRIB_STANDARD_INDEX;
}
Example #8
0
int
brhist_init(const lame_global_flags * gf, const int bitrate_kbps_min,
            const int bitrate_kbps_max)
{
#ifdef HAVE_TERMCAP
    char    term_buff[2048]; /* see 1) */
    const char *term_name;
    char   *tp;
    char    tc[10];
    int     val;
#endif

    /* setup basics of brhist I/O channels */
    Console_IO.disp_width = 80;
    Console_IO.disp_height = 25;
    brhist.hist_printed_lines = 0;
    Console_IO.Console_fp = stderr;
    Console_IO.Error_fp = stderr;
    Console_IO.Report_fp = stderr;

    setvbuf(Console_IO.Console_fp, Console_IO.Console_buff, _IOFBF,
            sizeof(Console_IO.Console_buff));
/*  setvbuf ( Console_IO.Error_fp  , NULL                   , _IONBF, 0                                ); */

#if defined(_WIN32)  &&  !defined(__CYGWIN__)
    Console_IO.Console_Handle = GetStdHandle(STD_ERROR_HANDLE);
#endif

    strcpy(Console_IO.str_up, "\033[A");

#ifndef RH_HIST
    /* some internal checks */
    if (bitrate_kbps_min > bitrate_kbps_max) {
        fprintf(Console_IO.Error_fp,
                "lame internal error: VBR min %d kbps > VBR max %d kbps.\n",
                bitrate_kbps_min, bitrate_kbps_max);
        return -1;
    }
    if (bitrate_kbps_min < 8 || bitrate_kbps_max > 320) {
        fprintf(Console_IO.Error_fp,
                "lame internal error: VBR min %d kbps or VBR max %d kbps out of range.\n",
                bitrate_kbps_min, bitrate_kbps_max);
        return -1;
    }
#endif

    /* initialize histogramming data structure */
    lame_bitrate_kbps(gf, brhist.kbps);
    brhist.vbr_bitrate_min_index =
        calculate_index(brhist.kbps, BRHIST_WIDTH, bitrate_kbps_min);
    brhist.vbr_bitrate_max_index =
        calculate_index(brhist.kbps, BRHIST_WIDTH, bitrate_kbps_max);

    if (brhist.vbr_bitrate_min_index >= BRHIST_WIDTH ||
        brhist.vbr_bitrate_max_index >= BRHIST_WIDTH) {
        fprintf(Console_IO.Error_fp,
                "lame internal error: VBR min %d kbps or VBR max %d kbps not allowed.\n",
                bitrate_kbps_min, bitrate_kbps_max);
        return -1;
    }

    memset(brhist.bar_asterisk, '*', sizeof(brhist.bar_asterisk) - 1);
    memset(brhist.bar_percent, '%', sizeof(brhist.bar_percent) - 1);
    memset(brhist.bar_space, '-', sizeof(brhist.bar_space) - 1);
    memset(brhist.bar_coded, '-', sizeof(brhist.bar_space) - 1);

#ifdef HAVE_TERMCAP
    /* try to catch additional information about special console sequences */

    if ((term_name = getenv("TERM")) == NULL) {
        fprintf(Console_IO.Error_fp,
                "LAME: Can't get \"TERM\" environment string.\n");
        return -1;
    }
    if (tgetent(term_buff, term_name) != 1) {
        fprintf(Console_IO.Error_fp,
                "LAME: Can't find termcap entry for terminal \"%s\"\n",
                term_name);
        return -1;
    }

    val = tgetnum("co");
    if (val >= 40 && val <= 512)
        Console_IO.disp_width = val;
    val = tgetnum("li");
    if (val >= 16 && val <= 256)
        Console_IO.disp_height = val;

    *(tp = tc) = '\0';
    tp = tgetstr("up", &tp);
    if (tp != NULL)
        strcpy(Console_IO.str_up, tp);

    *(tp = tc) = '\0';
    tp = tgetstr("ce", &tp);
    if (tp != NULL)
        strcpy(Console_IO.str_clreoln, tp);

    *(tp = tc) = '\0';
    tp = tgetstr("md", &tp);
    if (tp != NULL)
        strcpy(Console_IO.str_emph, tp);

    *(tp = tc) = '\0';
    tp = tgetstr("me", &tp);
    if (tp != NULL)
        strcpy(Console_IO.str_norm, tp);

#endif /* HAVE_TERMCAP */

    return 0;
}