Example #1
0
struct vector *
match_regexp(struct vector *v, char *pattern)
{
    struct regexp *reg;
    char *res;
    int i, num_match;
    struct vector *ret;

    if (v->size == 0)
	return allocate_array(0);
    reg = regcomp(pattern, 0);
    if (reg == 0)
	return 0;
    res = (char *)alloca((size_t)v->size);
    for (num_match=i=0; i < v->size; i++)
    {
	res[i] = 0;
	if (v->item[i].type != T_STRING)
	    continue;
	eval_cost++;
	if (regexec(reg, v->item[i].u.string) == 0)
	    continue;
	res[i] = 1;
	num_match++;
    }
    ret = allocate_array(num_match);
    for (num_match=i=0; i < v->size; i++)
    {
	if (res[i] == 0)
	    continue;
	assign_svalue_no_free(&ret->item[num_match], &v->item[i]);
	num_match++;
    }
    free((char *)reg);
    return ret;
}
Example #2
0
void f_str_to_arr(){
  static struct translation *newt = 0;
  if(!newt){
    newt = get_translator("UTF-32");
    translate_easy(newt->outgoing, " ");
  }
  int len;
  int *trans = (int *)translate(newt->outgoing, sp->u.string, SVALUE_STRLEN(sp)+1, &len);
  len/=4;
  array_t *arr = allocate_array(len);
  while(len--)
    arr->item[len].u.number = trans[len];
  free_svalue(sp, "str_to_arr");
  put_array(arr);
}
Example #3
0
/***********************************************************************
 * Return one column of a motif, as a newly allocated array of counts.
 ***********************************************************************/
ARRAY_T* get_motif_counts
  (int      position,
   MOTIF_T* motif)
{
  ARRAY_T* return_value = allocate_array(motif->alph_size);

  int i_alph;
  for (i_alph = 0; i_alph < motif->alph_size; i_alph++) {
    set_array_item(i_alph,
		   motif->num_sites * get_matrix_cell(position, 
						      i_alph, motif->freqs),
		   return_value);
  }
  return(return_value);
}
Example #4
0
extern MLvalue  c2ml_array(int count, ...)
{ mlval arr; 
  va_list ap;
  int i;

  arr = allocate_array((size_t)count);

  va_start(ap,count);

  for (i=0; i < count; i++)
    MLUPDATE(arr,i,TO_mlval(va_arg(ap,MLvalue)));

  va_end(ap);

  return_MLvalue(arr);
}
Example #5
0
void
Grid_i::height (CORBA::Short y)
{
  if (y > 0 && y != this->height_)
    {
      GridArray array (allocate_array (this->width_, y));
      for (CORBA::Short ctr = 0; ctr < Grid_i::ushort_min (this->height_, y); ++ctr)
        {
          ACE_OS::memcpy (array.get () + this->width_ * ctr, this->array_.get () + this->width_ * ctr,
                          this->width_ * sizeof (CORBA::Long));
        }
      this->array_ = array;
      array.release ();
      this->height_ = y;
    }
}
Example #6
0
//  Get a value from  the grid.
CORBA::Long
Grid_i::get (CORBA::Short x,
             CORBA::Short y)
{
  if (x < 0
      || y < 0
      || x >= this->width_
      || y >= this->height_)
    throw Grid::RANGE_ERROR ();
  else
    {
      if (this->array_.get () == 0)
        this->array_.reset (allocate_array (this->width_, this->height_));
      return *(this->array_.get () + this->width_ * y + x);
    }
}
Example #7
0
void
Grid_i::width (CORBA::Short x)
{
  if (x > 0 && x != this->width_)
    {
      GridArray array (allocate_array (x, this->height_));
      for (CORBA::Short ctr = 0; ctr < this->height_; ++ctr)
        {
          ACE_OS::memcpy (array.get () + x * ctr, this->array_.get () + this->width_ * ctr,
                          Grid_i::ushort_min (this->width_, x) * sizeof (CORBA::Long));
        }
      this->array_ = array;
      array.release ();
      this->width_ = x;
    }
}
Example #8
0
void dxml_handle_background(void *ctx, DREME_ALPH_EN alpha, double A, double C,
                            double G, double T, DREME_BG_EN source, char *file, char *last_mod_date) {
    CTX_T *data;
    MOTIF_T *motif;
    ARRAY_T *bg;

    data = (CTX_T*)ctx;
    data->file_type_match = 4; // it must be a dreme xml file!
    data->fscope.alphabet = DNA_ALPH;
    data->fscope.background = allocate_array(4);
    bg = data->fscope.background;
    set_array_item(0, A, bg);
    set_array_item(1, C, bg);
    set_array_item(2, G, bg);
    set_array_item(3, T, bg);
}
Example #9
0
/*
 * Returns a list of all inherited files.
 *
 */
struct vector *
inherit_list(struct object *ob)
{
    struct vector *ret;
    int inh;

    ret = allocate_array(ob->prog->num_inherited);

    for (inh = 0; inh < (int)ob->prog->num_inherited; inh++ )
    {
	ret->item[inh].type = T_STRING;
	ret->item[inh].string_type = STRING_MSTRING;
	ret->item[inh].u.string = add_slash(ob->prog->inherit[inh].prog->name);
    }
    return ret;
}
Example #10
0
/* Runs all elements of an array through fun
   and replaces each value in arr by the value returned by fun
   */
struct vector *
map_array (struct vector *arr, struct closure *fun)
{
    struct vector *r;
    int cnt;

    r = allocate_array(arr->size);
    push_vector(r, 0);
    for (cnt = 0; cnt < arr->size; cnt++) {
	push_svalue(&arr->item[cnt]);
	(void)call_var(1, fun);
	r->item[cnt] = *sp;	/* Just copy it.  Reference count is correct */
	sp--;			/* since we loose a reference here. */
    }
    sp--;
    return r;
}
Example #11
0
//  Set a value in the grid.
void
Grid_i::set (CORBA::Short x,
             CORBA::Short y,
             CORBA::Long value)
{
  if (x < 0
      || y < 0
      || x >= this->width_
      || y >= this->height_)
    throw Grid::RANGE_ERROR ();
  else
    {
      if (this->array_.get () == 0)
        this->array_.reset (allocate_array (this->width_, this->height_));
      *(this->array_.get () + this->width_ * y + x) = value;
    }
}
Example #12
0
INLINE void bson_to_array P2(const char *, data, svalue_t *, v){
	int size;
    array_t *av;
    svalue_t *sv;
    bson_iterator i;

    size = sizeof_bson(data);
    av = allocate_array(size);
    sv = av->item;
    bson_iterator_from_buffer( &i, data );
    while(bson_iterator_next( &i ) && size--){
		bson_to_v(&i,sv);
		sv++;
    }
    v->type = T_ARRAY;
    v->u.arr = av;
    
}
Example #13
0
struct svalue *
json_to_array(json_object *ob)
{
    int arraylen = json_object_array_length(ob);

    static struct svalue ret;
    ret.type = T_POINTER;
    ret.u.vec = allocate_array(arraylen);
    
    for (int x = 0; x < arraylen; x++) 
    {
        json_object *element = json_object_array_get_idx(ob, x);
        assign_svalue_no_free(&ret.u.vec->item[x], 
            json_to_value(element));
    }

    return &ret;
}
Example #14
0
/**
 * @name read_line:
 *   Read a line portably, relying only upon the C library's
 *   `getc` standard I/O function. This should work on any
 *   platform that has a standard I/O (stdio) implementation.
 */
char *read_line(FILE *stream, boolean_t *eof) {

  int c;
  unsigned int i = 0;
  size_t size = read_line_size_start;

  char *rv = allocate_array(sizeof(char), size, 1);

  for (;;) {

    if (!size || i >= size) {
      if ((size *= 8) >= read_line_size_maximum) {
        goto allocation_error;
      }
      if (!(rv = reallocate_array(rv, sizeof(char), size, 1))) {
        goto allocation_error;
      }
    }

    c = getc(stream);

    if (c == '\n') {
      break;
    } else if (c == EOF) {
      *eof = TRUE;
      break;
    }

    rv[i++] = c;
  }

  rv[i] = '\0';
  return rv;

  allocation_error:

    if (rv) {
      free(rv);
    }

    return NULL;
}
/**
 * Tests the pointer array with null values.
 */
void test_pointer_array_with_null_values() {

    log_write_terminated_message((void*) stdout, L"Test pointer array with null values:\n");

    // The pointer array.
    void* a = *NULL_POINTER_MEMORY_MODEL;
    int as = *NUMBER_5_INTEGER_MEMORY_MODEL;

    allocate_array((void*) &a, (void*) &as, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);

/*?? TODO!
    overwrite_array(a, (void*) &COMMERCIAL_AT_UNICODE_CHARACTER_CODE_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(a, (void*) (void*) &NUMBER_333_INTEGER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(a, (void*) (void*) NULL_POINTER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(a, (void*) (void*) NULL_POINTER_MEMORY_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(a, (void*) (void*) &COMMERCIAL_AT_UNICODE_CHARACTER_CODE_MODEL, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
*/

    // The result values.
    char** r0 = (char**) NULL_POINTER_MEMORY_MODEL;
    int** r1 = (int**) NULL_POINTER_MEMORY_MODEL;
    void** r2 = (void**) NULL_POINTER_MEMORY_MODEL;
    void* r3 = *NULL_POINTER_MEMORY_MODEL;
    char** r4 = (char**) NULL_POINTER_MEMORY_MODEL;

    get_array_elements((void*) &r0, a, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    get_array_elements((void*) &r1, a, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    get_array_elements((void*) &r2, a, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    get_array_elements((void*) &r3, a, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
    get_array_elements((void*) &r4, a, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);

    fwprintf(stdout, L"Result pointer as string r0: %s\n", *r0);
    fwprintf(stdout, L"Result pointer as integer r1: %i\n", **r1);
    fwprintf(stdout, L"Result pointer as pointer r2: %i\n", *r2);
    fwprintf(stdout, L"Result pointer as simple pointer r3: %i\n", r3);
    fwprintf(stdout, L"Result pointer as character r4: %c\n", **r4);

    fwprintf(stdout, L"NULL_POINTER_MEMORY_MODEL: %i \n", NULL_POINTER_MEMORY_MODEL);
    fwprintf(stdout, L"*NULL_POINTER_MEMORY_MODEL: %i \n", *NULL_POINTER_MEMORY_MODEL);

    deallocate_array((void*) &a, (void*) &as, (void*) POINTER_PRIMITIVE_MEMORY_ABSTRACTION);
}
Example #16
0
int main (int argc, char ** argv) {
	if (argc != 2) {
		fprintf (stderr, "usage: %s <N>\n", argv[0]);
		return 1;
	}

	int N = atoi (argv[1]);

	if (N <= 0)
		return 1;

	int * laminae_counts = allocate_array (TILES + 1, 0);

	for (int inner_size = 3;; inner_size++) {
		int outer_size = 0;
		int squares_used = 0;

		for (outer_size = inner_size;; outer_size += 2) {
			squares_used += (outer_size - 1) * 4;

			if (squares_used > TILES)
				break;

			laminae_counts[squares_used] += 1;
		}

		if (inner_size == outer_size)
			break;
	}

	int count = 0;

	for (size_t i = 0; i <= TILES; i++)
		if (laminae_counts[i] > 0 && laminae_counts[i] <= N)
			count++;

	printf ("%d\n", count);

	free (laminae_counts);

	return 0;
}
Example #17
0
/* Concatenation of two arrays into one
 */
struct vector *
add_array(struct vector *p, struct vector *r)
{
    int cnt,res;
    struct vector *d;
    
    d = allocate_array(p->size + r->size);
    res = 0;
    for (cnt = 0; cnt < p->size; cnt++) 
    {
	assign_svalue_no_free (&d->item[res],&p->item[cnt]);
	res++; 
    }
    for (cnt = 0; cnt < r->size; cnt++)
    {
	assign_svalue_no_free (&d->item[res],&r->item[cnt]);
	res++; 
    }
    return d;
}
/**
 * Tests the character array with a single element.
 */
void test_character_array_single_element() {

    log_write_terminated_message((void*) stdout, L"Test character array single element:\n");

    // The character array.
    void* c = *NULL_POINTER_MEMORY_MODEL;
    int cs = *NUMBER_5_INTEGER_MEMORY_MODEL;

    // Create character array.
    allocate_array((void*) &c, (void*) &cs, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);

/*?? TODO!
    overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_A_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_0_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_B_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_1_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(c, (void*) LATIN_CAPITAL_LETTER_C_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_2_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(c, (void*) LINE_FEED_CONTROL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_3_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
    overwrite_array(c, (void*) NULL_CONTROL_UNICODE_CHARACTER_CODE_MODEL, (void*) PRIMITIVE_MEMORY_MODEL_COUNT, (void*) NUMBER_4_INTEGER_MEMORY_MODEL, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
*/

    // Print out array contents.
    log_write_terminated_message((void*) stdout, (wchar_t*) c);

    int i = *NUMBER_0_INTEGER_MEMORY_MODEL;
    wchar_t* catest = (wchar_t*) *NULL_POINTER_MEMORY_MODEL;

    while (*TRUE_BOOLEAN_MEMORY_MODEL) {

        if (i >= cs) {

            break;
        }

        catest = (wchar_t*) (c + i);
        fwprintf(stdout, L"ca: %c\n", *catest);

        i++;
    }

    // Destroy character array.
    deallocate_array((void*) &c, (void*) &cs, (void*) WIDE_CHARACTER_PRIMITIVE_MEMORY_ABSTRACTION);
}
Example #19
0
/***********************************************************************
 * Create a bootstrapped copy of the given array.
 *
 * Allocates the bootstrap array; must be freed by caller.
 * Assumes that the random number generator is initialized. 
 ***********************************************************************/
ARRAY_T* bootstrap_array
  (ARRAY_T* source_array, 
   int      num_items)
{
  ARRAY_T* return_array;

  check_null_array(source_array);

  // Allocate the bootstrap array.
  return_array = allocate_array(num_items);

  // Fill up the bootstrap array.
  int i_item;
  int num_inputs = get_array_length(source_array);
  for (i_item = 0; i_item < num_items; i_item++) {
    int random_index = (int)(my_drand() * (double)(num_inputs));
    ATYPE random_item = get_array_item(random_index, source_array);
    set_array_item(i_item, random_item, return_array);
  }
  return(return_array);
}
Example #20
0
static vector_t * 
fetch_into_vector( hDBC * handle )
{
   int       i;

   vector_t  * vec;   

   STORE_DOUBLE_USED;
   
   vec = allocate_array( handle->colcnt );
   MEM_CHECK( vec );

   for( i = 0; i < handle->colcnt; ++i ) {
      if ( !handle->columns[ i ] ) continue;

      //printf( " fetch_into_vector[%2d] ", i );

      switch( handle->columns[ i ]->type ){
         case T_FLOAT:
            //printf( "float=%f\n",  handle->columns[ i ]->data.double_v );
            STORE_DOUBLE( vec->item + i, *handle->columns[ i ]->data.double_v );

            ( vec->item + i)->type = T_FLOAT;
            break; 

         case T_NUMBER:
            //printf( "number=%d\n",  *handle->columns[ i ]->data.number_v );
            put_number( vec->item + i, *handle->columns[ i ]->data.number_v );
            break;

         case T_STRING: 
         default      :
            //printf( "string=%s\n",  handle->columns[ i ]->data.string_v );
            put_malloced_string( vec->item + i, string_copy(  handle->columns[ i ]->data.string_v ) );
            break;
      }
   }

   return( vec );
}
Example #21
0
/*************************************************************************
 *  Build array containing the counts of columns in the alignment
 *  Caller is responsible for freeing the returned array.
 *  If input parameter "freqs" is NULL, allocates the array.
 *  Otherwise, the counts are added to the existing counts in the counts
 *  array.  Ignores all columns containing gaps or ambiguity characters:
 *    [.-nNxX]
 *************************************************************************/
static ARRAY_T* build_alignment_column_counts(
  ALPH_T alph,
  ALIGNMENT_T* alignment,
  ARRAY_T* counts 
) 
{

  assert(alignment != NULL);

  int asize = alph_size(alph, ALPH_SIZE);

  // Calculate number of possible alignment columns
  // and create storage for counting occurences.
  int num_seqs = get_num_aligned_sequences(alignment);
  int num_alignment_cols = (int) pow((double) asize, (double) num_seqs);
  if (counts == NULL) {
    counts = allocate_array(num_alignment_cols);
  }

  // Count how many examples of each column occur in the alignment.
  // Skip columns that contain gaps or ambiguity characters.
  int alignment_length = get_alignment_length(alignment);
  char* alignment_col = mm_malloc(sizeof(char) * (num_seqs + 1));
  alignment_col[num_seqs] = 0;
  int i, h;
  for(i = 0; i < alignment_length; i++) {
    get_alignment_col(i, alignment_col, alignment);
    if (strchr(alignment_col, '-') != NULL) { continue; }
    if (strchr(alignment_col, '.') != NULL) { continue; }
    if (strchr(alignment_col, 'N') != NULL) { continue; }
    if (strchr(alignment_col, 'n') != NULL) { continue; }
    if (strchr(alignment_col, 'X') != NULL) { continue; }
    if (strchr(alignment_col, 'x') != NULL) { continue; }
    h = hash_alignment_col(alph, alignment_col, num_seqs);
    incr_array_item(h, 1, counts);
  }

  return counts;
} // build_alignment_column_counts
Example #22
0
/****************************************************************************
*  Return an array containing the frequencies in the alignment for each 
*  character of the alphabet. Gaps and ambiguity characters other then
*  ANY_BASE are not counted. The freq. of ANY_BASE characters is stored
*  in the last element of the array.
****************************************************************************/
ARRAY_T* get_alignment_freqs(ALPH_T alph, ALIGNMENT_T* alignment) {
  char c = 0;
  int aindex = 0;
  int asize = 0;
  int i = 0;
  int s = 0;
  int total_bases = 0;
  int* num_bases = NULL;
  ARRAY_T* freqs = NULL;
  
  // Initialize counts for each character in the alphabet
  asize = alph_size(alph, ALPH_SIZE);
  num_bases = mm_malloc(asize * sizeof(int));
  for (i = 0; i < asize; i++) {
    num_bases[i] = 0;
  }

  for (s = 0; s < alignment->num_sequences; s++) {
    for (i = 0; i < alignment->length; i++) {
      c = get_seq_char(i, alignment->sequences[s]);
      aindex = alph_index(alph, c);
      // c might be an ambiguity code. We don't count ambiguity codes.
      if (aindex != -1 && aindex < asize) {
        num_bases[aindex]++;
        total_bases++;
      }
    }
  }

  freqs = allocate_array(asize);
  for (i = 0; i < asize; i++) {
    set_array_item(i, (double) num_bases[i] / (double) total_bases, freqs);
  }

  // Clean up the count of characters
  myfree(num_bases);

  return freqs;
}
Example #23
0
File: seq.c Project: CPFL/gmeme
/***************************************************************************
 * Set the sequence weights according to an external file.
 *
 * If the filename is "none," "internal," or NULL, then the weights are
 * set uniformly.
 ***************************************************************************/
void set_sequence_weights
  (char*    weight_filename, // Name of file containing sequence weights.
   int      num_seqs,        // Number of sequences.
   SEQ_T**  sequences)       // The sequences.
{
  ARRAY_T* weights;
  FILE *   weight_file;
  int      i_seq;

  /* Allocate the weights. */
  weights = allocate_array(num_seqs);

  /* Set uniform weights if no file was supplied. */
  if ((weight_filename == NULL) || (strcmp(weight_filename, "none") == 0) ||
      (strcmp(weight_filename, "internal") == 0)) {
    init_array(1.0, weights);
  }

  /* Read the weights from a file. */
  else {
    if (open_file(weight_filename, "r", FALSE, "weight", "weights",
		  &weight_file) == 0)
      exit(1);
    read_array(weight_file, weights);
    fclose(weight_file);

    /* Normalize the weights so they add to the total number of sequences. */
    normalize(0.0, weights);
    scalar_mult(num_seqs, weights);
  }

  /* Assign the weights to the sequences. */
  for (i_seq = 0; i_seq < num_seqs; i_seq++) {
    (sequences[i_seq])->weight = get_array_item(i_seq, weights);
  }

  /* Free the weights. */
  free_array(weights);
}
/*****************************************************************************
 * MEME > model > background_frequencies > alphabet_array > value
 ****************************************************************************/
void mxml_background_value(void *ctx, char *id, double freq) {
  CTX_T *data;
  char *symbol;
  int index;

  data = (CTX_T*)ctx;
  symbol = (char*)rbtree_get(data->letter_lookup, id);
  if (symbol == NULL) {
    local_error(data, "Background for unknown letter identifier \"%s\".\n", id);
    return;
  }
  index = alph_indexc(data->alph, symbol[0]);
  if (index < 0) {
    local_error(data, "Background for non-core letter %c.\n", symbol[0]);
    return;
  }
  if (data->nums == NULL) {
    data->nums = allocate_array(alph_size_core(data->alph));
    init_array(-1, data->nums);
  }
  set_array_item(index, freq, data->nums); 
}
Example #25
0
int *calc_breakpoints(int n, int threads)
{
    int i, *v; /* v is pointer to the vector */
    int rows = n/threads;
    int remainder = n%threads; /* number of rows not evenly distributed */
    int last_k = threads - remainder; /* number of threads get extra row */

    v = allocate_array(threads+1);

    /* row bands are attempted to be distributed evenly */
    for(i = 1; i <= threads; i++)
        v[i] += (v[i-1] + rows);

    /* The number of remaining rows are spread as evenly as possible amongst
     * the generated threads. This is done by giving the last k threads and
     * extra row, where k = remainder.
     */
    for(i = threads; i > last_k; i--)
        v[i] += remainder--;

    return(v); /* returns pointer to the vector */
} /* end calculate breakpoints */
void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
  LIRItem length(x->length(), this);
  length.load_item();

  LIR_Opr reg = result_register_for(x->type());
  LIR_Opr tmp1 = FrameMap::G1_oop_opr;
  LIR_Opr tmp2 = FrameMap::G3_oop_opr;
  LIR_Opr tmp3 = FrameMap::G4_oop_opr;
  LIR_Opr tmp4 = FrameMap::O1_oop_opr;
  LIR_Opr klass_reg = FrameMap::G5_oop_opr;
  LIR_Opr len = length.result();
  BasicType elem_type = x->elt_type();

  __ oop2reg(ciTypeArrayKlass::make(elem_type)->encoding(), klass_reg);

  CodeEmitInfo* info = state_for(x, x->state());
  CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
  __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);

  LIR_Opr result = rlock_result(x);
  __ move(reg, result);
}
Example #27
0
struct Buf *
buf_append(struct Buf *buf, const void *ptr, int n_elem)
{
	int n_alloc = 0;

	if (!ptr || n_elem == 0)
		return buf;

	/* May need to alloc more. */
	if (n_elem + buf->nelts > buf->nmax) {

		/* exact amount needed... */
		n_alloc = (n_elem + buf->nelts) * buf->elt_size;

		/* ...plus some extra */
		if (((n_alloc * buf->elt_size) % 512) != 0
		    && buf->elt_size < 512)
			n_alloc +=
			    (512 -
			    ((n_alloc * buf->elt_size) % 512)) /
			    buf->elt_size;

		if (!buf->elts)
			buf->elts =
			    allocate_array(n_alloc, buf->elt_size);
		else
			buf->elts =
			    reallocate_array(buf->elts, n_alloc,
			    buf->elt_size);

		buf->nmax = n_alloc;
	}
	memcpy((char *) buf->elts + buf->nelts * buf->elt_size, ptr,
	    n_elem * buf->elt_size);
	buf->nelts += n_elem;

	return buf;
}
Example #28
0
File: seq.c Project: CPFL/gmeme
/****************************************************************************
 *  Return an array containing the frequencies in the sequence for each
 *  character of the alphabet. Characters not in the alphabet are not
 *  counted.
 ****************************************************************************/
ARRAY_T* get_sequence_freqs
  (SEQ_T* seq, ALPH_T alph)
{
  char c = 0;
  int a_index = 0;
  int a_size = 0;
  int i = 0;
  int total_bases = 0;
  int* num_bases = NULL;
  ARRAY_T* freqs = NULL;

  // Initialize counts for each character in the alphabet
  a_size = alph_size(alph, ALPH_SIZE);
  num_bases = mm_malloc(a_size * sizeof(int));
  for (i = 0; i < a_size; i++) {
    num_bases[i] = 0;
  }

  for (i = 0; i < seq->length; i++) {
    c = get_seq_char(i, seq);
    if (c != '-' && c != '-') {
      a_index = alph_index(alph, c);
      if (a_index == -1 || a_index >= a_size) continue;
      num_bases[a_index]++;
      total_bases++;
    }
  }

  freqs = allocate_array(a_size);
  for (i = 0; i < a_size; i++) {
    set_array_item(i, (double) num_bases[i] / (double) total_bases, freqs);
  }

  // Clean up the count of characters
  myfree(num_bases);

  return freqs;
}
Example #29
0
static struct vector *
make_cpu_array2(int i, struct program *prog[])
{
    int num;
    struct vector *ret;
    char buff[1024]; /* should REALLY be enough */

    if (i <= 0) 
	return 0;
    ret = allocate_array(i);

    for(num = 0; num < i; num++) 
    {
	(void)sprintf(buff, "%22.18g:%s",
		      (double)(prog ? prog[num]->cpu_avg * 1e6: 0L),
		      prog ? prog[num]->name : "");
	free_svalue(&ret->item[num]);
	ret->item[num].type = T_STRING;
	ret->item[num].string_type = STRING_MSTRING;
	ret->item[num].u.string = make_mstring(buff);
    }
    return ret;
}
Example #30
0
double *create_external_input(double scale, double dt)
{
  double min = 10e10, max = -10e010, ave = 0.0, *data;
  int i, sz;

  /* How many neurons? */
  sz = sizeof(task_assigment_scores) / sizeof(double);

  /* Get some memory. */
  data = allocate_array(1, sizeof(double), sz);

  for(i = 0; i < sz; i++) {
    if(task_assigment_scores[i] < min) min = task_assigment_scores[i];
    if(task_assigment_scores[i] > max) max = task_assigment_scores[i];
    ave += task_assigment_scores[i];
  }
  ave /= sz;

  for(i = 0; i < sz; i++)
    data[i] = dt * (scale * (task_assigment_scores[i] - ave) /
                            (max - min) + 2);

  return(data);
}