示例#1
0
void Universe::InitializeSystemClass(VMClass* systemClass,
VMClass* superClass, const char* name) {
    StdString s_name(name);

    if (superClass != nullptr) {
        systemClass->SetSuperClass(superClass);
        VMClass* sysClassClass = systemClass->GetClass();
        VMClass* superClassClass = superClass->GetClass();
        sysClassClass->SetSuperClass(superClassClass);
    } else {
        VMClass* sysClassClass = systemClass->GetClass();
        sysClassClass->SetSuperClass(load_ptr(classClass));
    }

    VMClass* sysClassClass = systemClass->GetClass();

    systemClass->SetInstanceFields(NewArray(0));
    sysClassClass->SetInstanceFields(NewArray(0));

    systemClass->SetInstanceInvokables(NewArray(0));
    sysClassClass->SetInstanceInvokables(NewArray(0));

    systemClass->SetName(SymbolFor(s_name));
    ostringstream Str;
    Str << s_name << " class";
    StdString classClassName(Str.str());
    sysClassClass->SetName(SymbolFor(classClassName));

    SetGlobal(systemClass->GetName(), systemClass);
}
示例#2
0
void calc_interpolated_prob(arpa_lm_t *lm, arpa_lm_t *lm1, arpa_lm_t *lm2,fb_info* fb1,fb_info* fb2,double w1,double w2)
{
	TBROWSE br;
	id__t id[MAX_K];
	char** words;
	int k,j;
	double p1,p2,p;

	words=(char**)NewArray(MAX_K,MAX_WORD,sizeof(char));

	for (k=1;k<=lm->n;k++) {
		begin_browse(lm,k,&br);
		j=0;
		printf("\nProcessing %d-gram\n",k);
		while (get_next_ngram(id,&br)) {
		  j++;
		  show_dot(j);
			ids2words(words,id,k,lm->vocab);
			p1=calc_prob(words,k,lm1,fb1);
			p2=calc_prob(words,k,lm2,fb2);
			p=w1*p1+w2*p2;
			lm->probs[k-1][br.pos[k-1]-1]=log10(p);
			/* comment out this probability correction
			if(lm->probs[k-1][br.pos[k-1]-1]==0.0){
				lm->probs[k-1][br.pos[k-1]-1]=-0.00001;
			}
			*/

		}
	}

	DeleteArray(words);
}
示例#3
0
void NewLdaSuffStats(LdaModelC &m, LdaSuffStats* ss) {
  ss->class_total = new double[m.num_topics];
  double init = 0.0;
  Init(m.num_topics, init, ss->class_total);
  ss->class_word = NewArray(m.num_topics, m.num_terms);
  Init(m.num_topics, m.num_terms, init, ss->class_word);
}
示例#4
0
文件: std2.c 项目: MattWherry/yorick
static void GetTNworker(int nArgs, int cycs)
{
  IOStream *file;
  long i, n= 0;
  long *ncycs= 0;
  double *times= 0;
  Array *array;
  HistoryInfo *history;
  Dimension *dims;
  if (nArgs!=1) YError("get_times/get_ncycs takes exactly one argument");

  file= yarg_file(0);
  history= file->history;

  if (history) {
    n= history->nRecords;
    if (cycs) ncycs= history->ncyc;
    else times= history->time;
  }
  if (n<=0 || (cycs? (!ncycs) : (!times))) {
    PushDataBlock(RefNC(&nilDB));
    return;
  }

  dims= tmpDims;
  tmpDims= 0;
  FreeDimension(dims);
  tmpDims= NewDimension(n, 1L, (Dimension *)0);
  array= PushDataBlock(NewArray(cycs? &longStruct : &doubleStruct, tmpDims));

  if (cycs)
    for (i=0 ; i<n ; i++) array->value.l[i]= ncycs[i];
  else
    for (i=0 ; i<n ; i++) array->value.d[i]= times[i];
}
示例#5
0
void NewLdaModel(int num_topics, int num_terms, LdaModel* model) {
  model->num_topics = num_topics;
  model->num_terms = num_terms;
  model->alpha = 1.0;
  model->log_prob_w = NewArray(num_topics, num_terms);
  Init(num_topics, num_terms, 0.0, model->log_prob_w);
}
示例#6
0
ERRORCODE SplitArray::write_new_data(StorageDevicePtr device)
{
    ERRORCODE error = ERRORCODE_None;
    SHORT nStoredElemSize = SizeDifference();

    if ((error = device->write(&nStoredElemSize, sizeof (nStoredElemSize))) != ERRORCODE_None)
    {
        return error;
    }

    Array NewArray(nStoredElemSize);
    if ((error = NewArray.set_array_size(count())) != ERRORCODE_None)
    {
        return error;
    }

    LPBYTE lpSrcData, lpDestData;
    lpSrcData = (LPBYTE)data + OldSize();
    lpDestData = (LPBYTE)NewArray.get_element(0);

    for (int i = 0; i < count(); i++)
    {
        memcpy(lpDestData, lpSrcData, nStoredElemSize);
        lpDestData += nStoredElemSize;
        lpSrcData += NewSize();
    }

    error = NewArray.write(device);
    return error;
}
示例#7
0
static int alloc_ht(T_HashTable *H, int size)
{
  int i;

  for(i=0; sizes[i]; i++)
    if (sizes[i] > size*4 )
      break;
  if (!sizes[i])
    for(i=0; sizes[i]; i++)
      if (sizes[i] > size*2 )
	break;
  if (!sizes[i])
    for(i=0; sizes[i]; i++)
      if (sizes[i] > size)
	break;
  if(!sizes[i])
    return -1;
  size = sizes[i];
  if(size < H->size)
	  size = H->size; /* never shrink the table */
  H->max = size * 4 / 5 - 2;
  H->size = size;
  H->fill = 0;
  H->inuse = 0;
  H->entries = NewArray(size, T_HashTableEl);
  if (H->entries == NULL)
    return -1; /* out of memory error */
  
  for(i=0; i < size; i++)
    H->entries[i] = &unallocated;
  return 0;
}
示例#8
0
文件: std1.c 项目: MattWherry/yorick
void Y_digitize(int nArgs)
{
  long number, origin, nbins, i, ip;
  double *x, *bins;
  Dimension *dimsx, *dimsb;
  long *ibin;
  if (nArgs!=2) YError("digitize takes exactly two arguments");

  bins= YGet_D(sp, 0, &dimsb);
  x= YGet_D(sp-1, 0, &dimsx);

  if (!dimsb || dimsb->number<2 || dimsb->next)
    YError("2nd argument to digitize must be 1D with >=2 elements");
  nbins= dimsb->number;
  origin= dimsb->origin;
  number= TotalNumber(dimsx);

  if (dimsx) {
    Array *array= PushDataBlock(NewArray(&longStruct, dimsx));
    ibin= array->value.l;
  } else {
    PushLongValue(0L);
    ibin= &sp->value.l;
  }
  ip= 0;
  for (i=0 ; i<number ; i++)
    ibin[i]= ip= origin+hunt(bins, nbins, x[i], ip);
}
示例#9
0
void SetName( INDEX iWorld, INDEX iName, CTEXTSTR text )
{
	GETWORLD( iWorld );
	PNAME name = GetName( iName );
	int l, start, end;
	if( !name )
		return;
	if( name->name )
	{
		for( l = 0; l < name->lines; l++ )
			Release( name->name[l].name );
		Release( name->name );
	}
	name->lines = LineCount( text );
	if( name->lines )
	{
		name->name = (struct name_data*)Allocate( sizeof( *name->name ) * name->lines );
		start = 0;
		end = 0;
		for( l= 0; l < name->lines; l++ )
		{
			while( text[end] && text[end] != '\n' ) end++;
			name->name[l].length = end-start;
			name->name[l].name = NewArray( TEXTCHAR, (end-start) + 1 );
			MemCpy( name->name[l].name, text + start, end-start * sizeof( TEXTCHAR ) );
			name->name[l].name[end-start] = 0;
			start = end+1;
			end = start;
		}
	}
	else
		name->name = NULL;
}
示例#10
0
文件: std2.c 项目: MattWherry/yorick
void Y_get_primitives(int nArgs)
{
  IOStream *file;
  Dimension *dims;
  Array *array;
  long *p;
  FPLayout *fpl;
  int i, j;
  if (nArgs!=1) YError("get_primitives requires exactly one argument");

  file = yarg_file(0);
  dims = tmpDims;
  tmpDims = 0;
  FreeDimension(dims);
  tmpDims = NewDimension(32L, 1L, (Dimension *)0);
  array = PushDataBlock(NewArray(&longStruct, tmpDims));
  p = array->value.l;

  for (i=j=0 ; i<6 ; i++) {
    p[j++] = file->structList[i]->size;
    p[j++] = file->structList[i]->alignment;
    p[j++] = file->structList[i]->order;
  }
  p[1] = file->structAlign;
  for (i=4 ; i<6 ; i++) {
    fpl = file->structList[i]->fpLayout;
    p[j++] = fpl->sgnAddr;
    p[j++] = fpl->expAddr;
    p[j++] = fpl->expSize;
    p[j++] = fpl->manAddr;
    p[j++] = fpl->manSize;
    p[j++] = fpl->manNorm;
    p[j++] = fpl->expBias;
  }
}
示例#11
0
ERRORCODE SplitArray::read_new_data(StorageDevicePtr device)
{
    ERRORCODE error = ERRORCODE_None;

    SHORT nStoredElemSize;

    if ((error = device->read(&nStoredElemSize, sizeof (nStoredElemSize))) != ERRORCODE_None)
    {
        return error;
    }

    Array NewArray(nStoredElemSize);
    if ((error = NewArray.read(device)) != ERRORCODE_None)
    {
        return error;
    }

    if (NewArray.count() != count())
    {
        return ERRORCODE_TypeMismatch;
    }

    LPBYTE lpSrcData, lpDestData;
    lpDestData = (LPBYTE)data + OldSize();
    lpSrcData = (LPBYTE)NewArray.get_element(0);

    for (int i = 0; i < count(); i++)
    {
        memcpy(lpDestData, lpSrcData, nStoredElemSize);
        lpDestData += NewSize();
        lpSrcData += nStoredElemSize;
    }
    return error;
}
示例#12
0
文件: tkOption.c 项目: das/tcltk
static void
OptionInit(
    register TkMainInfo *mainPtr)
				/* Top-level information about window that
				 * isn't initialized yet. */
{
    int i;
    Tcl_Interp *interp;
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Element *defaultMatchPtr = &tsdPtr->defaultMatch;

    /*
     * First, once-only initialization.
     */

    if (tsdPtr->initialized == 0) {
	tsdPtr->initialized = 1;
	tsdPtr->cachedWindow = NULL;
	tsdPtr->numLevels = 5;
	tsdPtr->curLevel = -1;
	tsdPtr->serial = 0;

	tsdPtr->levels = (StackLevel *)
		ckalloc((unsigned) (5*sizeof(StackLevel)));
	for (i = 0; i < NUM_STACKS; i++) {
	    tsdPtr->stacks[i] = NewArray(10);
	    tsdPtr->levels[0].bases[i] = 0;
	}

	defaultMatchPtr->nameUid = NULL;
	defaultMatchPtr->child.valueUid = NULL;
	defaultMatchPtr->priority = -1;
	defaultMatchPtr->flags = 0;
	Tcl_CreateThreadExitHandler(OptionThreadExitProc, NULL);
    }

    /*
     * Then, per-main-window initialization. Create and delete dummy
     * interpreter for message logging.
     */

    mainPtr->optionRootPtr = NewArray(20);
    interp = Tcl_CreateInterp();
    GetDefaultOptions(interp, mainPtr->winPtr);
    Tcl_DeleteInterp(interp);
}
示例#13
0
static int yp_yajl_start_array(void *o)
{
	JsonParserCtx *ctx = static_cast<JsonParserCtx*>(o);
	JsonEl *arr = NewArray();
	if (ctx->nestingChain)
		jp_add_element(ctx, arr);
	return jp_nesting_chain_head_push(ctx, arr);
}
示例#14
0
static void GenerateInput( int key1, int key2 )
{
	INPUT *inputs = NewArray( INPUT, 4 );
	UINT result;
	inputs[0].type = INPUT_KEYBOARD;
	inputs[1].type = INPUT_KEYBOARD;
	inputs[2].type = INPUT_KEYBOARD;
	inputs[3].type = INPUT_KEYBOARD;

   if( key2 && key1 != key2 )
	{
		inputs[0].ki.wVk = key2;  // VK_ ;
		inputs[0].ki.wScan = 0;  // scancode of key...
		inputs[0].ki.dwFlags = 0; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[0].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[0].ki.dwExtraInfo = 0;
		inputs[1].ki.wVk = key1;  // VK_ ;
		inputs[1].ki.wScan = 0;  // scancode of key...
		inputs[1].ki.dwFlags = 0; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[1].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[1].ki.dwExtraInfo = 0;
		inputs[2].ki.wVk = key1; // VK_ ;
		inputs[2].ki.wScan = 0;  // scancode of key...
		inputs[2].ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[2].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[2].ki.dwExtraInfo = 0;
		inputs[3].ki.wVk = key2;  // VK_ ;
		inputs[3].ki.wScan = 0;  // scancode of key...
		inputs[3].ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[3].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[3].ki.dwExtraInfo = 0;
      result = 4;
	}
	else
	{
		inputs[0].ki.wVk = key1;  // VK_ ;
		inputs[0].ki.wScan = 0;  // scancode of key...
		inputs[0].ki.dwFlags = 0; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[0].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[0].ki.dwExtraInfo = 0;
		inputs[1].ki.wVk = key1;  // VK_ ;
		inputs[1].ki.wScan = 0;  // scancode of key...
		inputs[1].ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_UNICODE, KEYEVENTF_SCANCODE, KEYEVENTF_KEYUP, KEYEVENTF_EXTENDEDKEY
		inputs[1].ki.time = 0; // event timestamp in milliseconds... if 0, system fills it in.
		inputs[1].ki.dwExtraInfo = 0;
      result = 2;
	}

	result = SendInput( result, inputs, sizeof( INPUT ) );

	if( result == 0 )
	{
      // input is blocked somehow.
	}


   Deallocate( PINPUT, inputs );
}
示例#15
0
/**
   Very similar to write_lms except that it use arpa_lm_t but not
   lm_t.  Headers of the two files are also written. 
 */
void write_interpolated_lm(arpa_lm_t *ng, const char* arpa_filename, const char* header1, const char* header2, int verbosity) 
{		
  int i;
  int j;
  FILE* fp;
  TBROWSE br;
  id__t id[MAX_K];
  char** words;
  
  words=(char**)NewArray(MAX_K,MAX_WORD,sizeof(char));
  if (words==NULL) {
    Error ("Cannot allocate memory");
    return;
  }
  
  if ((fp=fopen(arpa_filename,"w"))==NULL) {
    Error ("Cannot open file to write arpa lm file.");
    return ;
  }
	
  /* HEADER */
  
  pc_message(verbosity,1,"ARPA-style %d-gram will be written to %s\n",ng->n,arpa_filename);
  
  write_arpa_copyright(fp,ng->n,(int) ng->vocab_size,ng->vocab[1],ng->vocab[2],ng->vocab[3]);
  write_arpa_format(fp,ng->n);	
  write_arpa_headers(fp, header1, header2);
  write_arpa_num_grams(fp,NULL,ng,1);
 
  /* Print 1-gram, ... n-gram info. */
  
  for (i=0;i<=ng->n-1;i++) {    
    /* Print out the (i+1)-gram */		
    write_arpa_k_gram_header(fp,i+1);
    
    begin_browse(ng,i+1,&br);
    
    /* Go through the n-gram list in order */
    
    while (get_next_ngram(id,&br)) {
      fprintf(fp,"%.4f ",ng->probs[i][br.pos[i]-1]);
      for (j=0;j<=i;j++)
	fprintf(fp,"%s ",ng->vocab[id[j]]);

      if (i <= ng->n-2)
	fprintf(fp,"\t%.4f\n",ng->bo_weight[i][br.pos[i]-1]);
      else
	fprintf(fp,"\n");
    }
  }	
	
  fprintf(fp,"\n\\end\\\n");

  fclose(fp);
	
  DeleteArray(words);
} 
示例#16
0
HandleProxy* V8EngineProxy::CreateArray(uint16_t** items, uint16_t length)
{
	Local<Array> array = NewArray(length);

	if (items != nullptr && length > 0)
		for (auto i = 0; i < length; i++)
			array->Set(i, NewUString(items[i]));

	return GetHandleProxy(array);
}
示例#17
0
stackADT NewStack(void)
{
	stackADT stack;

	stack = New(stackADT);
	stack->elements = NewArray(InitialStackSize, stackElementT);
	stack->count = 0;
	stack ->size = InitialStackSize;
	return stack;
}
示例#18
0
文件: std2.c 项目: MattWherry/yorick
void Y_get_vars(int nArgs)
{
  IOStream *file, *child;
  Array *array;
  char **pNames= 0, **cNames= 0;
  long i, nParent, nChild;
  Dimension *dims;
  if (nArgs!=1) YError("get_vars takes exactly one argument");

  file= yarg_file(0);

  child= file->history? file->history->child : 0;

  /* create result array */
  dims= tmpDims;
  tmpDims= 0;
  FreeDimension(dims);
  tmpDims= NewDimension(2L, 1L, (Dimension *)0);
  array= PushDataBlock(NewArray(&pointerStruct, tmpDims));
  nParent= file->dataTable.nItems;
  nChild= child? child->dataTable.nItems : 0;
  if (nParent) {
    dims= tmpDims;
    tmpDims= 0;
    FreeDimension(dims);
    tmpDims= NewDimension(nParent, 1L, (Dimension *)0);
    array->value.p[0]= pNames= NewArray(&stringStruct, tmpDims)->value.q;
  }
  if (nChild) {
    dims= tmpDims;
    tmpDims= 0;
    FreeDimension(dims);
    tmpDims= NewDimension(nChild, 1L, (Dimension *)0);
    array->value.p[1]= cNames= NewArray(&stringStruct, tmpDims)->value.q;
  }

  /* and fill it */
  for (i=0 ; i<nParent ; i++) pNames[i]= p_strcpy(file->dataTable.names[i]);
  for (i=0 ; i<nChild ; i++) cNames[i]= p_strcpy(child->dataTable.names[i]);
}
示例#19
0
static void ExpandStack(stackADT stack)
{
	stackElementT *array;
	int i, newSize;

	newSize = stack->size*2;
	array = NewArray(newSize, stackElementT);
	for(i=0; i<stack->size; i++)
		array[i] = stack->elements[i];

	FreeBlock (stack->elements);
	stack->elements = array;
	stack->size = newSize;
}
示例#20
0
文件: hash.c 项目: deepfield/MRT
/*-----------------------------------------------------------
 *  Name: 	HASH_ToArray()
 *  Created:	Thu Sep  8 23:49:47 1994
 *  Author: 	Jonathan DeKock   <dekock@winter>
 *  DESCR:  	reallocates array and coverts the hash table into it
 */
DATA_PTR *HASH_ToArray(HASH_TABLE *h, DATA_PTR *array, unsigned *size)
{
   unsigned index;
   unsigned array_index = 0;

#ifdef HASH_DEBUG
   if (!h) {
      if (HASH_Handler) { (HASH_Handler)(h, HASH_BadArgument, "HASH_ToArray()"); }
   }
#endif

   if (!array) { 
      array = NewArray(DATA_PTR, h->count);
      if (!array) {
	 if (HASH_Handler) { (HASH_Handler)(h, HASH_MemoryErr, "HASH_ToArray()"); }
	 return(NULL);
      }
   }

   if (h->attr & HASH_Intrusive) {
      DATA_PTR data;
      for (index = 0; index < h->size; index++) {
	 for (data = h->array.data[index]; data; data = NextP(h, data)) {
	    array[array_index++] = data;
	 }
      }
   }
   else {
      HASH_CONTAINER *cont;
      for (index = 0; index < h->size; index++) {
	 for (cont = h->array.cont[index]; cont; cont = cont->next) {
	    array[array_index++] = cont->data;
	 }
      }
   }
#ifdef HASH_DEBUG
   if (h->attr & HASH_ReportAccess) {
      printf("HASH TABLE: 0x%.8x ToArray(0x%.8x, %u) count\n", h, array, h->count);
   }
#endif
   
   if (size) *size = h->count;

#ifdef _HASH_INTERNAL_DEBUG
   HASH_Verify(h);
#endif

   return(array);
}
示例#21
0
文件: yeti_math.c 项目: emmt/Yeti
/* similar to BuildResultU in ops0.c */
static void *build_result(Operand *op, StructDef *base)
{
  if (! op->references && op->type.base == base) {
    /* similar to PushCopy in ydata.c */
    Symbol *stack = sp + 1;
    Symbol *s = op->owner;
    int isDB = (s->ops == &dataBlockSym);
    stack->ops = s->ops;
    if (isDB) stack->value.db = Ref(s->value.db);
    else stack->value = s->value;
    sp = stack; /* sp updated AFTER new stack element intact */
    return (isDB ? op->value : &sp->value);
  } else {
    return (void *)(((Array *)(PushDataBlock(NewArray(base, op->type.dims))))->value.c);
  }
}
示例#22
0
文件: ydrat.c 项目: MattWherry/yorick
void Y_set_tolerances(int nArgs)
{
  double *tols, t1, t2, t3;
  Dimension *dims;
  Array *array;

  if (nArgs!=1) YError("set_tolerances takes exactly one argument");

  tols= YGet_D(sp, 1, &dims);
  if (tols && (!dims || dims->number!=3 || dims->next))
    YError("argument to set_tolerances must be nil or array(double,3)");

  /* get current tolerances */
  if (polishRoot) {
    t1= polishTol1;
    t2= polishTol2;
  } else {
    t1= t2= -1.0;
  }
  t3= findRayTol;

  if (tols) {
    /* set tolerances to new values */
    if (tols[0]>=0.0) {
      if (tols[0]>0.0) polishTol1= tols[0];
      else polishTol1= 1.0e-3;   /* default value as set in track.c */
      if (tols[1]>0.0) polishTol2= tols[1];
      else polishTol2= 1.0e-6;   /* default value as set in track.c */
      polishRoot= 1;
    } else {
      polishRoot= 0;
    }
    if (tols[2]>0.0) findRayTol= tols[2];
    else findRayTol= 0.0;   /* default value as set in track.c */
  }

  dims= tmpDims;
  tmpDims= 0;
  FreeDimension(dims);
  tmpDims= NewDimension(3L, 1L, (Dimension *)0);
  array= (Array *)PushDataBlock(NewArray(&doubleStruct, tmpDims));
  tols= array->value.d;
  tols[0]= t1;
  tols[1]= t2;
  tols[2]= t3;
}
示例#23
0
文件: std1.c 项目: MattWherry/yorick
void Y_indgen(int nArgs)
{
  long number, origin, stride, i;
  Array *array;
  Dimension *tmp;
  Operand op;
  if (nArgs != 1) YError("indgen takes exactly one argument");

  sp->ops->FormOperand(sp, &op);
  if (op.ops==&rangeOps) {
    Range *range= op.value;
    if (range->rf || range->nilFlags)
      YError("range function and/or nil range component in indgen");
    origin= range->min;
    stride= range->inc;
    if (stride>0) number= (range->max-origin)/stride;
    else number= (origin-range->max)/(-stride);
    number++;  /* number of footprints, not number of strides */
  } else if (op.ops->promoteID<=T_LONG && !op.type.dims) {
    op.ops->ToLong(&op);
    number= *(long *)op.value;
    origin= 1L;
    stride= 1;
  } else {
    YError("indgen argument must be range or scalar integer");
    return;
  }

  if (number>0) {
    tmp= tmpDims;
    tmpDims= 0;
    FreeDimension(tmp);
    tmpDims= NewDimension(number, 1L, (Dimension *)0);
    array= PushDataBlock(NewArray(&longStruct, tmpDims));

    for (i=0 ; i<number ; i++) {
      array->value.l[i]= origin;
      origin+= stride;
    }

  } else {
    /* indgen(0) returns default origin */
    PushLongValue(1L);
  }
}
示例#24
0
void Newton::initialize(int m, 
			int SDP_nBlock, int* SDP_blockStruct,
			int SOCP_nBlock, int* SOCP_blockStruct,
			int LP_nBlock)
{
  gVec.initialize(m);

  DxMat.initialize(SDP_nBlock,SDP_blockStruct,
		   SOCP_nBlock,SOCP_blockStruct,
		   LP_nBlock);
  DyVec.initialize(m);
  DzMat.initialize(SDP_nBlock,SDP_blockStruct,
		   SOCP_nBlock,SOCP_blockStruct,
		   LP_nBlock);
  r_zinvMat.initialize(SDP_nBlock,SDP_blockStruct,
		      SOCP_nBlock,SOCP_blockStruct,
		      LP_nBlock);
  x_rd_zinvMat.initialize(SDP_nBlock,SDP_blockStruct,
			  SOCP_nBlock,SOCP_blockStruct,
			  LP_nBlock);

  NewArray(useFormula,FormulaType,m*SDP_nBlock);

  bMat_type = DENSE;
  // Caution: if SDPA doesn't use sparse bMat, 
  //          following variables are indefinite.
  this->SDP_nBlock = -1;
  SDP_number = NULL;  SDP_location_sparse_bMat = NULL;
  SDP_constraint1 = NULL;  SDP_constraint2 = NULL;
  SDP_blockIndex1 = NULL;  SDP_blockIndex2 = NULL;
  this->SOCP_nBlock = -1;
  SOCP_number = NULL;  SOCP_location_sparse_bMat = NULL;
  SOCP_constraint1 = NULL;  SOCP_constraint2 = NULL;
  SOCP_blockIndex1 = NULL;  SOCP_blockIndex2 = NULL;
  this->LP_nBlock = -1;
  LP_number = NULL;  LP_location_sparse_bMat = NULL;
  LP_constraint1 = NULL;  LP_constraint2 = NULL;
  LP_blockIndex1 = NULL;  LP_blockIndex2 = NULL;

  ordering = NULL;
  reverse_ordering = NULL;
  diagonalIndex = NULL;
}
示例#25
0
文件: std1.c 项目: MattWherry/yorick
void Y_random(int nArgs)
{
  Symbol *stack= sp-nArgs+1;
  double *random;
  long n;
  if (nArgs==1 && !YNotNil(stack)) {
    /* return scalar result */
    PushDoubleValue(0.0);
    random= &sp->value.d;
    n= 1;
  } else {
    /* return array result */
    Array *array;
    BuildDimList(stack, nArgs);
    array= PushDataBlock(NewArray(&doubleStruct, tmpDims));
    random= array->value.d;
    n= array->type.number;
  }
  NextRandom(random, n);
}
示例#26
0
static int handshake( PCLIENT pc ) {
   struct ssl_session *ses = pc->ssl_session;
	if (!SSL_is_init_finished(ses->ssl)) {
		int r;
		lprintf( "doing handshake...." );
		/* NOT INITIALISED */

		r = SSL_do_handshake(ses->ssl);
		lprintf( "handle data posted to SSL? %d", r );
		if( r == 0 ) {
			ERR_print_errors_cb( logerr, (void*)__LINE__ );
			r = SSL_get_error( ses->ssl, r );
			ERR_print_errors_cb( logerr, (void*)__LINE__ );
			lprintf( "SSL_Read failed... %d", r );
			return -1;
		}
		if (r < 0) {

			r = SSL_get_error(ses->ssl, r);
			if( SSL_ERROR_SSL == r ) {
				lprintf( "SSL_Read failed... %d", r );
				ERR_print_errors_cb( logerr, (void*)__LINE__ );
				return -1;
			}
			if (SSL_ERROR_WANT_READ == r) 
			{
				int pending = BIO_ctrl_pending( ses->wbio);
				if (pending > 0) {
					int read;
					if( pending > ses->obuflen ) {
						if( ses->obuffer )
							Deallocate( uint8_t *, ses->obuffer );
						ses->obuffer = NewArray( uint8_t, ses->obuflen = pending*2 );
					}
					read = BIO_read(ses->wbio, ses->obuffer, pending);
					lprintf( "send %d for handshake", read );
					if (read > 0)
						SendTCP( pc, ses->obuffer, read );
				}
示例#27
0
文件: parse.c 项目: MattWherry/yorick
static long StringConstant(char *string)
{
  Array *array;
  long i;
  for (i=0 ; i<nConstants ; i++) {
    if (constantTable[i].ops==&dataBlockSym) {
      array= (Array*)constantTable[i].value.db;
      if (strcmp(array->value.q[0], string)==0) break;
    }
  }
  if (i>=nConstants) {
    if (CheckConstSpace()) return 0;
    array= NewArray(&stringStruct, (Dimension *)0);
    constantTable[nConstants].ops= &dataBlockSym;
    constantTable[nConstants].index= 0;
    constantTable[nConstants++].value.db= (DataBlock *)array;
    array->value.q[0]= p_strcpy(string);
  } else {
    constantTable[i].index++;
  }
  return i;
}
示例#28
0
SaneWinMain( argc, argv )
{
	if( argc > 1 )
	{
		TEXTSTR result;
		uint8_t* buf;
		size_t length;
		FILE *file = sack_fopen( 0, argv[1], "rb" );
		length = sack_fseek( file, 0, SEEK_END );
		buf = NewArray( uint8_t, length );
		sack_fseek( file, 0, SEEK_SET );
		sack_fread( buf, 1, length, file );
		sack_fclose( file );
		result = SRG_EncryptData( buf, length );
		{
			int wrote = 0;
			while( result[wrote] )
			{
				wrote += printf( "%.80s", result + wrote );
				if( result[wrote] )
					printf("\\\n" );
			}
		}
		{
			size_t testlen;
			uint8_t* testbuf;
			SRG_DecryptData( result, &testbuf, &testlen );
			if( testlen != length )
				printf( "\n length fail \n" );
			if( MemCmp( testbuf, buf, testlen ) )
				printf( "\nFAIL\n" );
			Release( testbuf );
		}
		Release( buf );
		Release( result );

	}
}
示例#29
0
void calc_backoff_weight(arpa_lm_t* lm,fb_info* fb_list)
{
	int k;
	TBROWSE br;
	id__t id[MAX_K];
	int bo_case,acl;
	double p,q;
	int bo_pos;

	char** words;
	words=(char**)NewArray(MAX_K,MAX_WORD,sizeof(char));

	lm->bo_weight[0][0]=0.0;		//for <UNK>

	for (k=2;k<=lm->n;k++) {
		begin_browse(lm,k,&br);
		p=q=0;
		bo_pos=br.pos[k-2];
		while (get_next_ngram(id,&br)) {
			ids2words(words,id,k,lm->vocab);
			p+=calc_prob_of(id[k-1],id,k-1,NULL,lm,fb_list,&bo_case,&acl,TRUE);
			q+=calc_prob_of(id[k-1],&id[1],k-2,NULL,lm,fb_list,&bo_case,&acl,TRUE);
			if (br.pos[k-2]!=bo_pos) {
				if (p>=1) {
					lm->bo_weight[k-2][bo_pos]=MIN_LOG;
				}else if (q>=1) {
					/* printf ("Warning: sum of low order prob is 1"); */
					lm->bo_weight[k-2][bo_pos]=MAX_LOG;
				}else {
					lm->bo_weight[k-2][bo_pos]=safe_log10((1-p)/(1-q));
				}
				p=q=0;
				bo_pos=br.pos[k-2];
			}
		}
	}
}
示例#30
0
void check_prob(arpa_lm_t *lm, arpa_lm_t *lm1, arpa_lm_t *lm2,fb_info* fb1,fb_info* fb2,double w1,double w2)
{
  TBROWSE br;
  id__t id[MAX_K];
  char** words;
  int j,k;
  double p1,p2,p,s1,s2;
  int bo_pos = 0; /* for a quiet compile */
  
  words=(char**)NewArray(MAX_K,MAX_WORD,sizeof(char));

  for (k=1;k<=lm->n;k++) {
    begin_browse(lm,k,&br);
    if (k>=2) bo_pos=br.pos[k-2];
    s1=s2=0;
    j=0;

    printf("\nProcessing %d-gram\n",k);
    while (get_next_ngram(id,&br)) {
      ids2words(words,id,k,lm->vocab);
      p1=calc_prob(words,k,lm1,fb1);
      p2=calc_prob(words,k,lm2,fb2);

      j++;
      show_dot(j);
      s1+=p1;
      s2+=p2;
      if ((k>=2 && br.pos[k-2]!=bo_pos) || (k==1 && br.pos[0]==lm->num_kgrams[0])) {
	s1=s2=0;
      }
      p=w1*p1+w2*p2;
      lm->probs[k-1][br.pos[k-1]-1]=log10(p);
    }
  }

  DeleteArray(words);
}