Ejemplo n.º 1
0
  void Fit::setFunction()
  {
    // get the function
    m_function = getProperty("Function");
    auto mdf = boost::dynamic_pointer_cast<API::MultiDomainFunction>(m_function);
    if (mdf)
    {
        size_t ndom = mdf->getMaxIndex() + 1;
      m_workspacePropertyNames.resize( ndom );
      m_workspacePropertyNames[0] = "InputWorkspace";
      for(size_t i = 1; i < ndom; ++i)
      {
        std::string workspacePropertyName = "InputWorkspace_"+boost::lexical_cast<std::string>(i);
        m_workspacePropertyNames[i] = workspacePropertyName;
        if (!existsProperty(workspacePropertyName))
        {
          declareProperty(
            new API::WorkspaceProperty<API::Workspace>(workspacePropertyName,"",Kernel::Direction::Input), 
            "Name of the input Workspace");
        }
      }
    }
    else
    {
      m_workspacePropertyNames.resize(1,"InputWorkspace");
    }

  }
Ejemplo n.º 2
0
/*
 * Summary:     Evaluates the votes for all of the candidates and changes the
 *              RESULT (global variable for majority) appropriately.
 * Parameters:  None.
 * Return:      None.
 */
void
evalMajority()
{
  if (VOTE_COUNT >= VOTE_COUNT_MIN) // If there are at least 2 active nodes
    {
      if (0 == HOST_CALC) // Consider 0 an invalid calculation
        {
          flush(); // and reset everything
          return;
        }

      // Look to see the location of the candidate with the most votes
      u32 j = getMaxIndex(CANDIDATE_VOTES_ARR, (CANDIDATE_COUNT + 1));

      if (TIE == j) // turn off the LED's in a tie-case
        {
          MAJORITY_RSLT = TIE; // set the tie as an indicator
          setStatus(OFF);
          return;
        }

      else // if there was no tie
        {
          MAJORITY_RSLT = CANDIDATE_ARR[j]; // set majority accordingly
          setStatus((VOTE_NODE_ARR[0] == CANDIDATE_ARR[j]) ? MAJORITY
              : MINORITY); // set host LED based off of agreement.
          return;
        }
    }

  else
    setStatus(OFF); // Inadequate amount of IXM's for voting

  return;
}
Ejemplo n.º 3
0
static CNP_ITEM *storage_item_load(StorageData *sd, int index)
{
	if (!sd->ef)
	{
		DMSG("eet_file is NULL\n");
		return EINA_FALSE;
	}
	if (index >= STORAGE_ITEM_CNT)
		return NULL;

	indexType copyTable[STORAGE_ITEM_CNT];
	memcpy(copyTable, sd->indexTable, sizeof(copyTable));
	int i;
	for (i = 0; i < index; i++)
	{
		int maxIndex = getMaxIndex(copyTable, STORAGE_ITEM_CNT);
		if (maxIndex == -1)
			maxIndex = 0;
		copyTable[maxIndex] = 0;
	}

	char datakey[10];
	snprintf(datakey, 10, STORAGE_KEY_FORMAT, i);

	int read_size;
	char *read_data = eet_read(sd->ef, datakey, &read_size);

	if (!read_data)
	{
		DMSG("read failed index: %d\n", index);
		return NULL;
	}
	CNP_ITEM *item = CALLOC(1, sizeof(CNP_ITEM));
	if (item)
	{
		char *data = read_data + sizeof(int);
		int data_size = read_size - sizeof(int);
		char *buf = CALLOC(1, data_size);
		if (!buf)
		{
			FREE(item);
			return NULL;
		}
		item->type_index = ((int *)read_data)[0];
		memcpy(buf, data, data_size);
		item->data = buf;
		item->len = data_size;
	}
	return item;
}
double *
CoinPackedVectorBase::denseVector(int denseSize) const
{
   if (getMaxIndex() >= denseSize)
      throw CoinError("Dense vector size is less than max index",
		     "denseVector", "CoinPackedVectorBase");

   double * dv = new double[denseSize];
   CoinFillN(dv, denseSize, 0.0);
   const int s = getNumElements();
   const int * inds = getIndices();
   const double * elems = getElements();
   for (int i = 0; i < s; ++i)
      dv[inds[i]] = elems[i];
   return dv;
}
Ejemplo n.º 5
0
int main() {
  int i, j, k, n;
  int maxi, mini, sum;
  char newitem[10];
  memset (c_pan, 0, sizeof(c_pan));
  while (fgets(c_pan, N, stdin)) {
    printf ("%s", c_pan);

    for (i=0,j=0,k=0; c_pan[i]!='\0'; i++) {
      if (c_pan[i]== ' ' || c_pan[i]=='\n') {
        newitem[k] = '\0';
        sscanf (newitem, "%d", &sum);
        i_pan[j++] = sum;
        k = 0;
      } else {
        newitem[k++] = c_pan[i];
      }
    }

    n = j;
    for (i=0, j=1; i<n; i++, j++)
      pan[j] = i_pan[i];
    reverse (pan, 1, n);

#ifdef DEBUG_1
    for (i=1; i<=n; i++)
      printf ("%d ", pan[i]);
    printf ("\n");
#endif

    for (i=1; i<n; i++) {
      maxi = getMaxIndex (pan, i, n);
        if (maxi == i) continue;
        if (maxi != n) {
          printf ("%d ", maxi);
          reverse (pan, maxi, n);
        }
        printf ("%d ", i);
        reverse (pan, i, n);
    }

    printf ("0\n");
    memset (c_pan, 0, sizeof(c_pan));
    
  }
  return 0;
}
Ejemplo n.º 6
0
 Frame(DataTypeID data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
       uint_fast8_t frame_index, TransferID transfer_id, bool last_frame = false)
     : transfer_priority_(getDefaultPriorityForTransferType(transfer_type))
     , transfer_type_(transfer_type)
     , data_type_id_(data_type_id)
     , payload_len_(0)
     , src_node_id_(src_node_id)
     , dst_node_id_(dst_node_id)
     , frame_index_(frame_index)
     , transfer_id_(transfer_id)
     , last_frame_(last_frame)
 {
     UAVCAN_ASSERT((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast());
     UAVCAN_ASSERT(data_type_id.isValidForDataTypeKind(getDataTypeKindForTransferType(transfer_type)));
     UAVCAN_ASSERT(src_node_id.isUnicast() ? (src_node_id != dst_node_id) : true);
     UAVCAN_ASSERT(frame_index <= getMaxIndex());
 }
Ejemplo n.º 7
0
CVector* divideFam(CVector *wordVec, int wordLength, char ch, int *max_index)
{
    int n = 1;
    for (int i = 0; i < wordLength; i++) {
        n += n;
    }
    CVector **fam = malloc(n * sizeof(CVector*));
    for (int i = 0; i < n; i++) {
        fam[i] = NULL;
    }
    int *arr = calloc(n, sizeof(int));
    int index = 0;
    for (void *cur = cvec_first(wordVec); cur != NULL; cur = cvec_next(wordVec, cur)) {
        char *word = (char*)cur;
        int check = 0;
        for (int i = wordLength -1; i >= 0; i--) {
            if (word[i] == ch) {
                if(check != 0) {
                    // means the character appears more than once.
                    // remove it from the current family
                    cvec_remove(fam[check], cvec_count(fam[check]) - 1);
                    arr[check]--;
                    check = check | (1 << (wordLength -i - 1));
                }
                check = check | (1 << (wordLength -i - 1));
                appendElem(fam, check, wordLength, arr, word);
            }
        }
        
        if (check == 0) {
            appendElem(fam, check, wordLength, arr, word);
        }
    }
    *max_index = getMaxIndex(arr, n);
    free(arr);
    return fam[*max_index];
}
Ejemplo n.º 8
0
	template <class T> const T& Grid2<T>::getMaxValue() const
	{
		vec2ul index = getMaxIndex();
		return m_data[index.y * m_dimX + index.x];
	}
Ejemplo n.º 9
0
cl_int decomposer_GPUSparc(cl_kernel 	  	kernel,
						   cl_uint 	      	work_dim, 
						   const size_t * 	global_work_offset, 
						   const size_t * 	global_work_size,
						   const size_t * 	local_work_size,
						   cl_uint 		  	num_events_in_wait_list,
						   const cl_event *	event_wait_list,
						   cl_event *		event)
{
	cl_uint i;
	cl_int ret = CL_SUCCESS;

	map<cl_kernel, struct kernelinfo_GPUSparc>::iterator kiter;
	kiter = kernelmap_GPUSparc.find (kernel);
	if (kiter == kernelmap_GPUSparc.end()) {
		GPUSparcLog ("Cannot find kernel in clEnqueueNDRangeKernel\n");
	}
	cl_kernel *kernels = kiter->second.kernel;

	size_t *local_work 	   = (size_t *)malloc(sizeof(size_t) * work_dim);

	unsigned int *num_group = (unsigned int *)malloc(sizeof(unsigned int) * work_dim);

	for(i = 0; i < work_dim; i++) {
		local_work[i] = (local_work_size != NULL)? local_work_size[i] : 1;
		num_group[i] = global_work_size[i]/local_work[i];
	}

	timeval t1, t2;


	cl_uint max_index = getMaxIndex (work_dim,global_work_size, local_work);
	cl_uint step = getStep (work_dim, global_work_size, local_work, max_index);

	map<cl_uint, cl_mem> args = kiter->second.args;
	map<cl_uint, cl_mem>::iterator argiter;
	map<cl_mem, struct meminfo_GPUSparc>::iterator miter;
	/* inter-kernel dependency */
	GPUSparcLog ("Arg Sync\n");
	for (argiter = args.begin(); argiter != args.end(); ++argiter) {
		miter = memmap_GPUSparc.find (argiter->second);
		if (miter == memmap_GPUSparc.end()) {
			GPUSparcLog ("Cannot find args in clEnqueueNDRangeKernel\n");
			continue;
		}
		struct meminfo_GPUSparc *minfo = &(miter->second);
		if (!(miter->second.merged) && multiGPUmode) {
			ret |= bufferMerger_GPUSparc (minfo, NULL);
		}
		if (!(miter->second.synched)) {
			ret |= bufferSynchronizer_GPUSparc (minfo, NULL, NULL, NULL);
		}
	}
	gettimeofday (&t1, NULL);
	cl_event *tevent = (cl_event *)malloc(sizeof(cl_event) * nGPU_GPUSparc);
	
	cl_uint arg_index = kiter->second.arg_num;

	if (!multiGPUmode)
	{	
		if (migration)
			gpuid = -1;
		
		sendRequest('g', gpuid, 1);
		gpuid = waitRequest('g', -1);
		struct kernelLauncherData *kd = (struct kernelLauncherData *)malloc(sizeof(struct kernelLauncherData));
		kd->index = gpuid;
		kd->kernel = kernels[gpuid];
		kd->max_index = max_index;
		kd->work_dim = work_dim;
		kd->global_work_size = global_work_size;
		kd->global_work_offset = global_work_offset;
		kd->local_work_size = local_work_size;
		kd->step = step;
		kd->num_groups = num_group;
		kd->arg_num = arg_index;
		kd->event = NULL;
		kd->size = global_work_size[max_index]/local_work[max_index];
		kd->off = 0;
		single_kernel_launcher (kd);
	}
	else {

	
		struct kernelLauncherData *kd = (struct kernelLauncherData *)malloc(sizeof(struct kernelLauncherData)*nGPU_GPUSparc);
		int total = global_work_size[max_index]/local_work[max_index];
		int nGPU = nGPU_GPUSparc;
		
		for(i = 0; i < nGPU_GPUSparc; i++) {
			kd[i].index = i;
			kd[i].kernel = kernels[i];
			kd[i].work_dim = work_dim;
			kd[i].max_index = max_index;
			kd[i].global_work_size = global_work_size;
			kd[i].global_work_offset = global_work_offset;
			kd[i].local_work_size = local_work_size;
			kd[i].step = step;
			kd[i].num_groups = num_group;
			kd[i].arg_num = arg_index;
			kd[i].event = &tevent[i];
			int amount = CEIL(total,nGPU);
			total -= amount;
			nGPU--;
			kd[i].size = amount;
			if (i == 0)
					kd[i].off = 0;
					else
				kd[i].off = kd[i-1].off + kd[i-1].size;
		}
	
		pthread_t *kthread = (pthread_t *)malloc(sizeof(pthread_t) * nGPU_GPUSparc);
		for(i = 0; i < nGPU_GPUSparc; i++) {
			pthread_create (&kthread[i], NULL, kernel_launcher, &kd[i]);
		}

		for(i = 0; i < nGPU_GPUSparc; i++) {
			pthread_join (kthread[i], NULL);
		}


		if (event != NULL) {
			eventmap_GPUSparc.insert (map<cl_event, cl_event *>::value_type (tevent[0], tevent));
			*event = tevent[0];
	
		}
		else free (tevent);
	}
	gettimeofday (&t2, NULL);
	GPUSparcLog ("kernel time: %f\n", ELAPSEDTIME(t1, t2));
	for (argiter = args.begin(); argiter != args.end(); ++argiter) {
		miter = memmap_GPUSparc.find (argiter->second);
		struct meminfo_GPUSparc *minfo = &miter->second;
		minfo->merged = false;
		if (!multiGPUmode)
			minfo->cohered_gpu = gpuid;
	}
	if (migration)
		gpuid = -1;

	free (num_group);
	free (local_work);
	return ret;
}
Ejemplo n.º 10
0
 int getMax()
 {
   return values[getMaxIndex()];
 }
Ejemplo n.º 11
0
/*                           bar
       -------------------------------------------------
       |0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
       |0
foo    |0
       |0
       |0
       |0
       -------------------------------------------------

  F[1] F[2]
  F[0]

  direct = 't' means coming from top
  direct = 'l' means coming from left
  direct = 'c' means coming from the corner
  direct = 'n' means NULL
 */
void CSWAlign::calculate(){
  if(foolen==0||barlen==0){
    std::cerr<<"void CSWAlign::SWcalculate() can not calculate without strings assigned.\n";
    return;
  }

  result->clear();
  direct->clear();
  matchlength = 0;
  
  foolen++;
  barlen++;

  if(scorematrix!=NULL)
    delete scorematrix;
  scorematrix = new int[foolen*barlen];
  if(directmatrix!=NULL)
    delete directmatrix;
  directmatrix = new char[foolen*barlen];
  int i = 0, j = 0;
  int F[3] = {0,0,0};
  int maxindex = 0;
  for(; i<foolen; i++){
    for(j=0; j<barlen; j++){
      if(!i){
	scorematrix[j] = 0;
	directmatrix[j] = 'n';
	continue;
      }
      if(!j){
	scorematrix[i*barlen] = 0;
	directmatrix[i*barlen] = 'n';
	continue;
      }
      F[0] = scorematrix[i*barlen+j-1] +  score_of_gap;
      F[2] = scorematrix[(i-1)*barlen+j] +  score_of_gap;
      if(foostr[i-1]==barstr[j-1])
	F[1] = scorematrix[(i-1)*barlen+j-1] + score_of_match;
      else
	F[1] =  scorematrix[(i-1)*barlen+j-1] + score_of_mismatch;
      
      maxindex = getMaxIndex(F, 3);
      scorematrix[i*barlen+j] = F[maxindex];
      if(maxindex==0){;
	directmatrix[i*barlen+j] = 'l';
      }else if(maxindex==1){
	directmatrix[i*barlen+j] = 'c';
      }else{
	directmatrix[i*barlen+j] = 't';
      }
    }
  }

  maxindex = getMaxIndex(scorematrix, foolen*barlen);
  int w = maxindex%barlen;
  int h = maxindex/barlen;

  char t = 'n';
  while(w>0&&h>0){
    t = directmatrix[h*barlen+w];
    if(t=='l'){
      direct->push_back('f');
      w--;
    }else if(t=='t'){
      direct->push_back('b');
      h--;
    }else if(t=='c'){
      direct->push_back('m');
      matchlength++;
      w--;
      h--;
    }
  }
  if(h==0){
    while(w>0){
      direct->push_back('f');
      w--;
    }
  }else{
    while(h>0){
      direct->push_back('b');
      h--;
    }
  }

  int fooindex = 0;
  int barindex = 0;
  int matchindex = 0;
  std::list<char>::iterator iter = direct->end();
  if(matchstr!=NULL)
    delete matchstr;
  if(foomatchindex!=NULL)
    delete foomatchindex;
  if(barmatchindex!=NULL)
    delete barmatchindex;
  matchstr = new int[matchlength];
  foomatchindex = new int[matchlength];
  barmatchindex = new int[matchlength];
  for(;; iter--){
    if((*iter)=='m'){
      matchstr[matchindex] = foostr[fooindex];
      foomatchindex[matchindex] = fooindex;
      barmatchindex[matchindex] = barindex;
      fooindex++;
      barindex++;
      matchindex++;
    }else if((*iter)=='f'){
      barindex++;
    }else if((*iter)=='b'){
      fooindex++;
    }
    if(iter==direct->begin())
      break;
  }
  

  foolen--;
  barlen--;
 
}
Ejemplo n.º 12
0
static int execute(char *info, FILE *fs, FILE *fh)
{
    char temp[MAX_PATH_LEN];
    char id[50];
    char fileIn[MAX_PATH_LEN];
    int w, h, bpp;
    int isize, psize;
    int packed;
    int transInd;
    int nbElem;
    unsigned char *data;
    unsigned short *palette;
    unsigned char maxIndex;

    packed = 0;
    transInd = 0;

    nbElem = sscanf(info, "%s %s \"%[^\"]\" %d %d", temp, id, temp, &packed, &transInd);

    if (nbElem < 3)
    {
        printf("Wrong BITMAP definition\n");
        printf("BITMAP name \"file\" [packed]\n");
        printf("  name\t\tBitmap variable name\n");
        printf("  file\tthe image to convert to Bitmap structure (should be a 8bpp .bmp or .png)\n");
        printf("  packed\tset to 1 to pack the Bitmap data, by default 0 is assumed.\n\n");

        return FALSE;
    }

    // adjust input file path
    adjustPath(resDir, temp, fileIn);

    // retrieve basic infos about the image
    if (!Img_getInfos(fileIn, &w, &h, &bpp)) return FALSE;

    // adjust bitmap size on pixel pair
    w = ((w + 1) / 2) * 2;

    // get image data (always 8bpp)
    data = Img_getData(fileIn, &isize, 2, 1);
    if (!data) return FALSE;

    // find max color index
    maxIndex = getMaxIndex(data, isize);
    // not allowed here
    if (maxIndex >= 16)
    {
        printf("Error: Image %s use color index >= 16\n", fileIn);
        printf("BITMAP resource require image with a maximum of 16 colors.\n");
        printf("Use 4bpp image instead if you are unsure.\n");
        return FALSE;
    }

    // convert to 4BPP
    data = to4bppAndFree(data, isize);
    isize /= 2;
    if (!data) return FALSE;

    // pack data
    if (packed)
    {
        data = pack(data, 0, isize, &isize, &packed);
        if (!data) return FALSE;
    }

    // get palette
    palette = Img_getPalette(fileIn, &psize);
    if (!palette) return FALSE;

    // we keep 16 colors max
    psize = MIN(16, psize);

    // EXPORT PALETTE
    strcpy(temp, id);
    strcat(temp, "_palette");
    outPalette(palette, 0, psize, fs, fh, temp, FALSE);

    // EXPORT BITMAP
    outBitmap(data, packed, w, h, isize, fs, fh, id, TRUE);

    return TRUE;
}