Пример #1
0
const MetaWindowSessionInfo*
meta_window_lookup_saved_state (MetaWindow *window)
{
  GSList *possibles;
  const MetaWindowSessionInfo *info;
  
  /* Window is not session managed.
   * I haven't yet figured out how to deal with these
   * in a way that doesn't cause broken side effects in
   * situations other than on session restore.
   */
  if (window->sm_client_id == NULL)
    {
      meta_topic (META_DEBUG_SM,
                  "Window %s is not session managed, not checking for saved state\n",
                  window->desc);
      return NULL;
    }

  possibles = get_possible_matches (window);

  if (possibles == NULL)
    {
      meta_topic (META_DEBUG_SM, "Window %s has no possible matches in the list of saved window states\n",
                  window->desc);
      return NULL;
    }

  info = find_best_match (possibles, window);
  
  g_slist_free (possibles);
  
  return info;
}
Пример #2
0
static value_t find_best_match(runtime_t *runtime, value_t current,
    value_t target, value_t current_score, value_t space, value_t *score_out) {
  if (value_identity_compare(current, target)) {
    *score_out = current_score;
    return success();
  } else {
    TRY_DEF(parents, get_type_parents(runtime, space, current));
    int64_t length = get_array_buffer_length(parents);
    value_t score = new_no_match_score();
    for (int64_t i = 0; i < length; i++) {
      value_t parent = get_array_buffer_at(parents, i);
      value_t next_score = whatever();
      TRY(find_best_match(runtime, parent, target, get_score_successor(current_score),
          space, &next_score));
      score = best_score(score, next_score);
    }
    *score_out = score;
    return success();
  }
}
Пример #3
0
value_t guard_match(value_t guard, value_t value, runtime_t *runtime,
    value_t space, value_t *score_out) {
  CHECK_FAMILY(ofGuard, guard);
  switch (get_guard_type(guard)) {
    case gtEq: {
      value_t guard_value = get_guard_value(guard);
      bool match = value_identity_compare(guard_value, value);
      *score_out = match ? new_identical_match_score() : new_no_match_score();
      return success();
    }
    case gtIs: {
      TRY_DEF(primary, get_primary_type(value, runtime));
      value_t target = get_guard_value(guard);
      return find_best_match(runtime, primary, target,
          new_perfect_is_match_score(), space, score_out);
    }
    case gtAny:
      *score_out = new_any_match_score();
      return success();
    default:
      UNREACHABLE("Unknown guard type");
      return new_condition(ccWat);
  }
}
Пример #4
0
    int function_dispatcher(lua_State* L)
    {
        function_rep* rep = static_cast<function_rep*>(
            lua_touserdata(L, lua_upvalueindex(1))
        );

        bool ambiguous = false;
        int min_match = std::numeric_limits<int>::max();
        int match_index = -1;
        bool ret;

#ifdef LUABIND_NO_ERROR_CHECKING2
        if (rep->overloads().size() == 1)
        {
            match_index = 0;
        }
        else
        {
#endif
            int num_params = lua_gettop(L);
            ret = find_best_match(
                L
              , &rep->overloads().front()
              , (int)rep->overloads().size()
              , sizeof(overload_rep)
              , ambiguous
              , min_match
              , match_index
              , num_params
            );
#ifdef LUABIND_NO_ERROR_CHECKING2
        }
#else
        if (!ret)
        {
            // this bock is needed to make sure the string_class is destructed
            {
                string_class msg = "no match for function call '";
                msg += rep->name();
                msg += "' with the parameters (";
                msg += stack_content_by_name(L, 1);
                msg += ")\ncandidates are:\n";

                msg += get_overload_signatures(
                    L
                  , rep->overloads().begin()
                  , rep->overloads().end()
                  , rep->name()
                );

                lua_pushstring(L, msg.c_str());
            }

            lua_error(L);
        }

        if (ambiguous)
        {
            // this bock is needed to make sure the string_class is destructed
            {
                string_class msg = "call of overloaded function '";
                msg += rep->name();
                msg += "(";
                msg += stack_content_by_name(L, 1);
                msg += ") is ambiguous\nnone of the overloads "
                       "have a best conversion:";

                std::vector<overload_rep_base const*> candidates;
                find_exact_match(
                    L
                  , &rep->overloads().front()
                  , (int)rep->overloads().size()
                  , sizeof(overload_rep)
                  , min_match
                  , num_params
                  , candidates
                );

                msg += get_overload_signatures_candidates(
                    L
                  , candidates.begin()
                  , candidates.end()
                  , rep->name()
                );

                lua_pushstring(L, msg.c_str());
            }
            lua_error(L);
        }
#endif
        overload_rep const& ov_rep = rep->overloads()[match_index];

#ifndef LUABIND_NO_EXCEPTIONS
        try
        {
#endif
            return ov_rep.call(L, ov_rep.fun);
#ifndef LUABIND_NO_EXCEPTIONS
        }
        catch(const luabind::error&)
        {
        }
        catch(const std::exception& e)
        {
            lua_pushstring(L, e.what());
        }
        catch (const char* s)
        {
            lua_pushstring(L, s);
        }
        catch(...)
        {
            string_class msg = rep->name();
            msg += "() threw an exception";
            lua_pushstring(L, msg.c_str());
        }
        // we can only reach this line if an exception was thrown
        lua_error(L);
        return 0; // will never be reached
#endif
    }
Пример #5
0
int main(int argc, char *argv[]) {
  kseq_t *seq;
  int l, index, shift, min=5, min_keep=35;
  int debug=0, verbose=1;
  int contaminated=0, total=0;
  quality_type qual_type=SANGER;
  match *best_match;
  float *qprobs, prior=default_prior;
  adapter_array *aa;
  gzFile adapter_fp=NULL, fp;
  FILE *output_fp=stdout, *matches_fp=NULL;
  int optc;
  int add_tag = 0;
  extern char *optarg;

  while (1) {
    int option_index = 0;
    optc = getopt_long(argc, argv, "dtfp:a:o:q:m:o:n:M:", long_options, &option_index);

    if (optc == -1)
       break;
    switch (optc) {
      if (long_options[option_index].flag != 0)
        break;
      case 'a':
        adapter_fp = gzopen(optarg, "r");
        if (!adapter_fp) {
          fprintf(stderr, "Could not open adapter file '%s'.\n", optarg);
          return EXIT_FAILURE;
        }
        break;
      case 'd':
        debug = 1;
        break;
      case 't':
        add_tag = 1;
        break;
      case 'Q':
        verbose = 0;
        break;
      case 'o':
        output_fp = fopen(optarg, "w");
        if (!output_fp) {
          fprintf(stderr, "Could not open output file '%s'.\n", optarg);
          return EXIT_FAILURE;
        }
        break;
      case 'm':
        matches_fp = fopen(optarg, "w");
        if (!matches_fp) {
          fprintf(stderr, "Could not open matches file '%s'.\n", optarg);
          return EXIT_FAILURE;
        }
        break;
      case 'n':
        min = atoi(optarg);
        break;
      case 'M':
        min_keep = atoi(optarg);
        break;
      case 'q':
        if (strcmp(optarg, "illumina") == 0)
          qual_type = ILLUMINA;
        else if (strcmp(optarg, "solexa") == 0)
          qual_type = SOLEXA;
        else if (strcmp(optarg, "sanger") == 0)
          qual_type = SANGER;
        else {
          fprintf(stderr, "Unknown quality type '%s'.\n", optarg);
          usage(EXIT_FAILURE);
        }          
        break;
      case 'p':
        /* This truncation is acceptable... priors need not be doubles */
        prior = (float) atof(optarg);
        if (prior > 1 || prior < 0) {
          fprintf(stderr, "Prior must be between 0 and 1\n");
          usage(EXIT_FAILURE);
        }
        break;
        
      case_GETOPT_HELP_CHAR;
      case_GETOPT_VERSION_CHAR(PROGRAM_NAME, VERSION, AUTHORS);
      case '?':
        break;
      default:
        usage(EXIT_FAILURE);
      }
  }
  
  if (debug) {
    matches_fp = stdout;
    output_fp = stdout;
  }
  
  if ((index = optind) == argc) {
    fprintf(stderr, "No FASTQ file specified.\n");
    usage(EXIT_FAILURE);
  }
 
  /* load all adapter sequences into memory */
  if (!adapter_fp) {
    fprintf(stderr, "No adapter file specified.\n");
    usage(EXIT_FAILURE);
  }
  aa = load_adapters(adapter_fp);
  gzclose(adapter_fp);

  fp = strcmp(argv[index], "-") ? gzopen(argv[index], "r") : gzdopen(fileno(stdin), "r");

  if (!fp) {
    fprintf(stderr, "FASTQ file '%s' not found.\n", argv[index]);
    return EXIT_FAILURE;
  }

  seq = kseq_init(fp);

  /* Loop through entire sequence file. Write trimmed sequences to
     file (or stdout), and record matches in a match file if specifed.
  */
  while ((l = kseq_read(seq)) >= 0) {
    shift = -1;
    if (!seq->qual.s) {
      fputs("Sequence file missing or has malformed quality line.\n", stderr);
      usage(EXIT_FAILURE);
    }
      
    qprobs = qual_to_probs(seq->qual.s, qual_type);
    best_match = find_best_match(aa, seq->seq.s, qprobs, prior, 0.25, min);
    
    if (best_match && best_match->ps->is_contam) {
      contaminated++;
      shift = best_match->shift;
      if (matches_fp) print_match(seq, best_match, matches_fp, aa, qual_type);
      /* TODO */
      /* aa->adapters[best_match->adapter_index].occurrences[best_match->n-1]++; */
    }    
    write_fastq(output_fp, seq, add_tag, shift, min_keep);
    if (best_match) destroy_match(best_match);
    free(qprobs);
    total++;
  }
  
  if (verbose) 
    print_summary(aa, prior, total-contaminated, contaminated, total);

  kseq_destroy(seq);
  destroy_adapters(aa, MAX_ADAPTERS);
  gzclose(fp);
  return 0;
}
Пример #6
0
//
// Supported commands are:
//	<dict.file> e <word> - find exact match, if nothing found, dump list
//	<dict.file> l <word> - dump list
//  <dict.file> n <offset> - dump next word list starting from <offset>
//  <dict.file> p <offset> - dump previous word list, ending at offset <offset>
//  <dict.file> x <offset> - dump article at address x
//
// Output format:
//	list result
//		"list"
//		<word>\t<short translation>\n
//		<word>\t<short translation>\n
//		...
//		<starting_offset>\t<ending_offset>\n
//
//	exact result
//		"match"\n
//		<translation>
//			
int main(int argc, char* argv[])
{
	// Set console codepage to UTF8 on windows
	#ifdef _MSC_VER
		SetConsoleOutputCP(CP_UTF8);
	#endif


	// Expecting <exec name> <dictionary file> <word>
	if (argc < 4) {
		print_usage();
		return ERR_INVALID_ARGUMENT;
	}

	char* command = (char*) argv[2];

	// dictionary file name, fancy names aren't supported
	char* filename = (char*) argv[1];

	// UTF 16 version of the search string (assuming input is UTF8)
	int search_len;
	uint16_t* searchUTF16 = utf8to16((uint8_t*) argv[3], search_len);
	
	// Open dictionary file
	f = fopen(filename, "rb");
	if (!f) {
		printf("Failed to open file: %s", filename);
		return ERR_FILE_NOT_FOUND;
	}

	// Read header
	doread(&header, sizeof(header));

	// check magic (PRSPDICT ascii)
	int MAGIC[8] = {0x50, 0x52, 0x53, 0x50, 0x44, 0x49, 0x43, 0x54};
	for (int i = 0; i < 8; i++) {
		if (header.magic[i] != MAGIC[i]) {
			printf("Invalid file magic");
			return ERR_INVALID_MAGIC;
		}
	}

	// Check dicitonary version
	if (header.version_lo != 0 || header.version_hi != 1) {
		printf("Unsupported dictionary version: %d.%d", header.version_hi, header.version_lo);
		return ERR_UNSUPPORTED_VERSION;
	}

	switch (command[0]) {
		case 'e':
			//	e <word> - find exact match, if nothing found, dump list
			if (!find_exact_match(header.offset_radix, searchUTF16, search_len)) {
				find_best_match(searchUTF16, search_len);
			}
			break;
		//	l <word> - dump list
		case 'l':
			find_best_match(searchUTF16, search_len);
			break;
		//  n <offset> - dump next word list starting from <offset>
		case 'n':
			dump_word_list(atoi(argv[3]), NEXT);
			break;
		//  p <offset> - dump previous word list, ending at offset <offset>
		case 'p':
			dump_word_list(atoi(argv[3]), PREV);
			break;
		//  x <offset> - dump article at address x
		case 'x':
			dump_article(atoi(argv[3]));
			break;
		default:
			print_usage();
	}

	
	fclose(f);
	return 0;
}
//--------------------------------------------------------------------------------------------//
//  Thread Create 
//  Description: This function encapsulates all of the thread create functions (i.e. dynamic
//      create smart, microblaze create, hthread create, etc.
//  Arguments:
//      1) Thread ID - Thread ID returned by the OS. Assigned during hthread_setup().
//      2) Thread Attribute - Attribute structure for the thread
//      3) Function ID - The function number the thread will execute
//      4) Argument - Argument to be passed to the function
//      5) Type - The type of thread you want to be created. (i.e. Software, dynamic_hw, etc.
//      6) Dma Length - the length of the parameter, arg. Passing a zero indicates no DMA'ing
//
//      NOTE: DMA LENGTH IS NOT USED AT THIS TIME.
//--------------------------------------------------------------------------------------------//
Huint thread_create(
        hthread_t * tid,        
        hthread_attr_t * attr,  
        Huint func_id,   
        void * arg,             
        Huint type,      
        Huint dma_length)
{

    Huint ret;
    void * func;

    assert(attr!=NULL); // Efficient NULL pointer check

    // ---------------------------------------------
    // Make sure tables are initialized
    // ---------------------------------------------
    if (!table_initialized_flag) {
        
        // Assert flag
        table_initialized_flag = 1;

        // Init thread table
        init_thread_table(&global_thread_table);

        // Load entries with app-specific data
        load_my_table();

        // Init function-to-accelerator table
        init_func_2_acc_table();
       
        // Initialize mutexes, ICAP, and bitfiles
        // for Partial Reconfiguration.
        init_PR_data();
    }

    // Check if we have not passed our threshold
    // TODO: Remove?
    //while( (NUM_AVAILABLE_HETERO_CPUS - get_num_free_slaves() + thread_counter) >  (NUM_AVAILABLE_HETERO_CPUS + SW_THREAD_COUNT))
        //hthread_yield();

    //--------------------------------
    // Is this a software thread?
    //--------------------------------
    if (type == SOFTWARE_THREAD) {
       
        // Create a native/software thread on the host processor
       
        // Make sure user didn't call  hthread_attr_sethardware()
        if (attr->hardware) {
            #ifdef DEBUG_DISPATCH
            printf("Your thread attribute is set for hardware but");
            printf(" you are creating a software thread!\n");
            #endif
            ret = FAILURE;
        } else
            ret = software_create(tid, attr, func_id, arg);
    
    //------------------------------------------------------------
    // For hardware threads, should we dynamically schedule them?
    //------------------------------------------------------------
    } else if(type == DYNAMIC_HW) {

        // Identify a slave processor the best fits our needs (i.e., is 
        // available, is available and has an accelerator we want, etc.)
        Hint slave_num = find_best_match(func_id);

        // If we did not find any processors available.
        if (slave_num == MAGIC_NUMBER) {
            #ifdef DEBUG_DISPATCH
            printf("No Free Slaves:Creating software thread\n");
            #endif
            ret = software_create(tid, NULL, func_id, arg);
        } else {
            // Grab the function handle according to the processor type.
            func = lookup_handle(&global_thread_table, func_id, slave_table[slave_num].processor_type);
            #ifdef DEBUG_DISPATCH
            printf("Creating Hetero Thread (CPU#%d)!\n",slave_num);
            #endif

            // -------------------------------------------------------------- //
            //         Write extra parameters for PR functionality            //
            // -------------------------------------------------------------- //
            // Write pointer for first_used_accelerator so slave can update the table.
            // This assumes that for a particular function (id), slaves will also have 
            // the same first accelerator used.
            _hwti_set_first_accelerator_ptr( (Huint) hwti_array[slave_num], (Huint) &func_2_acc_table[func_id]);

            // -------------------------------------------------------------- //
            //         Create the hardware thread using better target         //
            // -------------------------------------------------------------- //
            hthread_attr_sethardware( attr, (void*)hwti_array[slave_num] );
            ret =  hthread_create(tid, attr, func, arg);
        }
    //-------------------------------------------------------
    // For hardware threads, we will statically schedule them
    //-------------------------------------------------------
    } else { 
        // Determine the exact slave processor number 
        Huint slave_num = type + STATIC_HW_OFFSET;

        // Check if valid slave number. Since 'slave_num' is 
        // and unsigned int, it cannot be negative, right?
        if (slave_num >= NUM_AVAILABLE_HETERO_CPUS) {
            #ifdef DEBUG_DISPATCH
            printf("Invalid slave number: %d\n", slave_num);
            printf("Creating a software thread instead\n");
            #endif
            ret = software_create(tid, NULL, func_id, arg);
        }

        // If that slave number exists, is it Free?
        if (_hwti_get_utilized_flag(hwti_array[slave_num]) == FLAG_HWTI_UTILIZED) { 
            #ifdef DEBUG_DISPATCH
            printf("Slave number %d is busy! Creating software thread\n", slave_num);
            #endif
            ret = software_create(tid, NULL, func_id, arg);
        }
        else {
            #ifdef DEBUG_DISPATCH
            printf("Creating Hetero Thread (CPU#%d)!\n",slave_num);
            #endif
            
            // -------------------------------------------------------------- //
            //         Write extra parameters for PR functionality            //
            // -------------------------------------------------------------- //
            // Write pointer for first_used_accelerator so slave can update the table.
            // This assumes that for a particular function (id), slaves will also have 
            // the same first accelerator used.
            _hwti_set_first_accelerator_ptr( (Huint) hwti_array[slave_num], (Huint) &func_2_acc_table[func_id]);

            // Grab the function according to the processor type
            func = lookup_handle(&global_thread_table, func_id, slave_table[slave_num].processor_type);
            
            // -------------------------------------------------------------- //
            //         Create the hardware thread using slave num             //
            // -------------------------------------------------------------- //
            hthread_attr_sethardware( attr, (void*)hwti_array[slave_num] );
            ret = hthread_create(tid, attr, func, arg);
        }
    }
    return ret;
}