Ejemplo n.º 1
0
inline future<OutputIterator>
dispatch_copy_async(InputIterator first,
                    InputIterator last,
                    OutputIterator result,
                    command_queue &queue,
                    typename boost::enable_if<
                        mpl::and_<
                            is_device_iterator<InputIterator>,
                            is_device_iterator<OutputIterator>,
                            can_copy_with_copy_buffer<
                                InputIterator, OutputIterator
                            >
                        >
                    >::type* = 0)
{
    typedef typename std::iterator_traits<InputIterator>::value_type value_type;
    typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;

    difference_type n = std::distance(first, last);
    if(n < 1){
        // nothing to copy
        return make_future(result, event());
    }

    event event_ =
        queue.enqueue_copy_buffer(
            first.get_buffer(),
            result.get_buffer(),
            first.get_index() * sizeof(value_type),
            result.get_index() * sizeof(value_type),
            static_cast<size_t>(n) * sizeof(value_type)
        );

    return make_future(result + n, event_);
}
Ejemplo n.º 2
0
 T operator()(InputIterator first, InputIterator last) const
 {
    for (InputIterator it = first; it != last; ++it)
    {
       if (!it->empty())
          return *it;
    }
    return T();
 }
Ejemplo n.º 3
0
bool cGraphMaster::isMatchWildcard(const InputIterator& input, const InputIterator& pattern, const unsigned long& rec) {
  if (input.isDone()) { if (pattern.isDone()) return true; else return false; }
  else {
    if (pattern.isDone()) return true;
    else {
      InputIterator input_copy(input);
      do { if (isMatch(input_copy, pattern, rec+1)) return true; input_copy++; } while(!input_copy.isDone());
      return false;
    }
  }
  return false;
}
Ejemplo n.º 4
0
    void populate_imaging_table_data_by_cycle(InputIterator beg,
                                              InputIterator end,
                                              const size_t q20_idx,
                                              const size_t q30_idx,
                                              const constants::tile_naming_method naming_method,
                                              const summary::read_cycle_vector_t& cycle_to_read,
                                              const std::vector<size_t>& columns,
                                              const std::map<Id_t, size_t>& row_offset,
                                              const size_t column_count,
                                              OutputIterator data_beg,
                                              OutputIterator data_end)
    {
        for(;beg != end;++beg)
        {
            const Id_t id = beg->id();
            typename std::map<Id_t, size_t>::const_iterator row_it = row_offset.find(id);
            const size_t row = row_it->second;
            const summary::read_cycle& read = cycle_to_read[beg->cycle()-1];
            if(data_beg[row*column_count]==0)
            {
                if((beg->cycle()-1) >= cycle_to_read.size())
                    INTEROP_THROW(model::index_out_of_bounds_exception, "Cycle exceeds total cycles from Reads in the RunInfo.xml");


                INTEROP_ASSERTMSG(row_it != row_offset.end(), "Bug with row offset");
                INTEROP_ASSERT(row<row_offset.size())
                INTEROP_ASSERTMSG(columns[model::table::ReadColumn] < static_cast<size_t>(model::table::ImagingColumnCount), columns[model::table::ReadColumn] );
                INTEROP_ASSERTMSG(columns[model::table::CycleWithinReadColumn] < static_cast<size_t>(model::table::ImagingColumnCount), columns[model::table::CycleWithinReadColumn] );
                INTEROP_ASSERTMSG(data_beg+row*column_count+columns[model::table::ReadColumn] < data_end, columns[model::table::ReadColumn]
                        << " - " <<  row*column_count+columns[model::table::ReadColumn] << " < " << std::distance(data_beg, data_end) << " "
                        << "row: " << row << " < " << row_offset.size());
                // TODO: Only populate Id once!
                table_populator::populate_id(*beg,
                                             read,
                                             q20_idx,
                                             q30_idx,
                                             naming_method,
                                             columns,
                                             data_beg+row*column_count,
                                             data_end);
            }
            table_populator::populate(*beg,
                                      read.number,
                                      q20_idx,
                                      q30_idx,
                                      naming_method,
                                      columns,
                                      data_beg+row*column_count, data_end);
        }
    }
Ejemplo n.º 5
0
bool instructionsAreSinkable(InputIterator first, InputIterator last) {
  for (; first != last; ++first) {
    switch (first->op()) {
    case DecRef:
    case DecRefNZ:
    case IncRef:
    case LdMem:
      continue;
    default:
      FTRACE(5, "unsinkable: {}\n", first->toString());
      return false;
    }
  }
  return true;
}
Ejemplo n.º 6
0
bool cGraphMaster::getMatch(InputIterator input, NodeType curr_type, const NodeVec& tree, MatcherStruct& ms, unsigned long rec) {
  // save head of input and advance iterator
  string input_front = *input;
  input++;
    
   //cout<<"tree.front().key="<<tree.front().key<<endl;

  _DBG_CODE(msg_dbg() << "[" << rec << "]getMatch(" << curr_type << ") HEAD: [" << input_front << "] last input?:" << boolalpha << input.isDone() << endl);
  
  /** FIRST WILDCARD: try to match the '_' wildcard **/
  if (tree.front().key == "_") {
    _DBG_CODE(msg_dbg() << "[" << rec << "]" << "Looking in '_'" << endl);
    if (getMatchWildcard(input, curr_type, tree.front(), ms, rec, input_front)) { if (ms.log) ms.logMatch("_", curr_type); return true; }
  }
  
  /** KEYS: if wildcard didn't matched, look for specific matching keys against current input_front **/
  _DBG_CODE(msg_dbg() << "[" << rec << "]" << "KEYS" << endl);
  Node tmp_node;
  tmp_node.key = input_front;
  NodeVec::const_iterator it = lower_bound(tree.begin(), tree.end(), tmp_node);
  // if there was a match
  if (it != tree.end() && it->key == input_front) {
    // if there are more tokens on input
    if (!input.isDone()) {
      // if I have something to match with, then look for a match
      if (!it->same_childs.empty()) {
        if (getMatch(input, curr_type, it->same_childs, ms, rec+1)) { if (ms.log) ms.logMatch(it->key, curr_type); return true; }
      }
    }
    // else, this is the last token
    else {
      // get the the next type of nodes to match if necessary
      list<string> match_list;
      if (curr_type != NODE_TOPIC && !it->diff_childs.empty()) ms.user.getMatchList(NodeType(curr_type+1), match_list);

      // if in previous situation check if there's a match deeper
      if (curr_type != NODE_TOPIC && !it->diff_childs.empty() &&
          getMatch(match_list, nextNodeType(curr_type), it->diff_childs, ms, rec+1))
      {
        if (ms.log) ms.logMatch(it->key, curr_type); return true;
      }
      // if I'm in the final type of nodes, it needs to be a leaf to have a match
      else if (curr_type == NODE_TOPIC && !it->templ.empty()) {
        ms.templ = it->templ;
        if (ms.log) ms.logMatch(it->key, curr_type);
        return true;
      }
    }
  }

  /** LAST WILDCARD: if above didn't matched repeat procedure for '_' **/
  if (tree.back().key == "*") {
    _DBG_CODE(msg_dbg() << "[" << rec << "]" << "Looking in '*'" << endl);
    if (getMatchWildcard(input, curr_type, tree.back(), ms, rec, input_front)) { if (ms.log) ms.logMatch("*", curr_type); return true; }
  }
  
  return false;
}
Ejemplo n.º 7
0
bool instructionsAreSinkable(InputIterator first, InputIterator last) {
  for (; first != last; ++first) {
    switch (first->op()) {
    case ReDefSP:
    case ReDefGeneratorSP:
    case DecRef:
    case DecRefNZ:
    case Marker:
    case IncRef:
    case LdMem:
      return true;
    default:
      FTRACE(5, "unsinkable: {}\n", first->toString());
      return false;
    }
  }
  not_reached();
}
Ejemplo n.º 8
0
// Reduced version of the matching algorithm found on graphmaster.cpp, look there for a thorough explanation of the code
// This version doesn't have to handle with different node types. The pattern is just a list, not a tree, so it is much easier
bool cGraphMaster::isMatch(InputIterator input, InputIterator pattern, unsigned long rec) {
  string input_head(*input);
  string patt_head(*pattern);
  input++; pattern++;

  if (patt_head == "_" && isMatchWildcard(input, pattern, rec)) return true;
  
  if (patt_head == input_head) {
    if (input.isDone()) { if (pattern.isDone()) return true; else return false; }
    else {
      if (pattern.isDone()) return false;
      else {
        if (isMatch(input, pattern, rec+1)) return true;
        else return false;
      }
    }
  }

  if (patt_head == "*" && isMatchWildcard(input, pattern, rec)) return true;
  
  return false;
}
Ejemplo n.º 9
0
 listed_sqeuence(double concert_pitch, InputIterator begin, InputIterator end, std::size_t reserve = 0) {
   frequencies_.reserve(reserve);
   while (begin != end) {
     if (is_floating_point<typename InputIterator::value_type>(*begin)) {
       double f = boost::lexical_cast<double>(*begin);
       frequencies_.push_back(f);
     }
     else {
       int offset = parse_note(begin->c_str());
       frequencies_.push_back(offset_to_frequency(concert_pitch, offset));
     }
     ++begin;
   }
   iter_ = frequencies_.begin();
 }
Ejemplo n.º 10
0
inline OutputIterator
dispatch_copy(InputIterator first,
              InputIterator last,
              OutputIterator result,
              command_queue &queue,
              typename boost::enable_if_c<
                  boost::is_same<
                      InputIterator,
                      buffer_iterator<typename InputIterator::value_type>
                  >::value &&
                  boost::is_same<
                      OutputIterator,
                      buffer_iterator<typename OutputIterator::value_type>
                  >::value &&
                  boost::is_same<
                      typename InputIterator::value_type,
                      typename OutputIterator::value_type
                  >::value
              >::type* = 0)
{
    typedef typename std::iterator_traits<InputIterator>::value_type value_type;
    typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;

    difference_type n = std::distance(first, last);
    if(n < 1){
        // nothing to copy
        return first;
    }

    queue.enqueue_copy_buffer(first.get_buffer(),
                              result.get_buffer(),
                              first.get_index() * sizeof(value_type),
                              result.get_index() * sizeof(value_type),
                              static_cast<size_t>(n) * sizeof(value_type));
    return result + n;
}
Ejemplo n.º 11
0
template<class InputIterator> inline void
tws::core::copy_string_array(InputIterator first,
                             InputIterator last,
                             rapidjson::Value& jvalues,
                             rapidjson::Document::AllocatorType& allocator)
{
  if(!jvalues.IsArray())
    throw tws::conversion_error() << tws::error_description("copy_string_array: can only copy arrays of string data.");
  
  while(first != last)
  {
    jvalues.PushBack(first->c_str(), allocator);
    
    ++first;
  }
}
Ejemplo n.º 12
0
bool cGraphMaster::getMatchWildcard(const InputIterator& input, const NodeType& curr_type, const Node& tree_frontback, MatcherStruct& ms, const unsigned long& rec, const string& input_front) {
  // add the head token to the <*star/>, will remove it if it didn't matched later
  StarIt it = ms.sh.AddStar(input_front, curr_type);

  // if this is not the last token of input
  if (!input.isDone()) {
    // if this is the last node of the path, then it is a match (save the star and then proceed to match the next node type)
    if (tree_frontback.same_childs.empty()) {
      for (InputIterator input_copy(input); !input_copy.isDone(); input_copy++) *it += string(" ") + *input_copy;
    }
    // it isn't, so try matching this token with the wildcard and match the rest in a deeper recursion,
    // after that start making a bigger match for current wildcard, until all trailing input is matched against this wildcard
    else {
      InputIterator input_copy(input);
      do {
        if (getMatch(input_copy, curr_type, tree_frontback.same_childs, ms, rec+1)) return true;
        *it += string(" ") + *input_copy; input_copy++;
      } while(!input_copy.isDone());
    }
  }

  // this is reached if the match is in this recursion level (the deepest level will set the template and return true,
  // so I don't have to do anything but pass the 'true' if getMatch() returns true)
  // This situation is because either:
  //  a) one token of input (sure match, I have to continue the matching job deeper)
  //  b) more than one token of input and:
  //    b.1) trailing wildcard (sure match, eats all available input)
  //    b.2) the wildcard couldn't be used to match just a part of the trailing input, so it matches ALL the trailing input

  // if i'm not in the final type (ie: not matching the topic) of node and there are other type of nodes I
  // should get the next type of nodes to match
  list<string> match_list;
  if (curr_type != NODE_TOPIC && !tree_frontback.diff_childs.empty())
    ms.user.getMatchList(NodeType(curr_type+1), match_list);

  // so, If I'm in the previous situation AND there's a match with the current match list I should return 'there is a match'
  if (curr_type != NODE_TOPIC && !tree_frontback.diff_childs.empty() &&
       getMatch(match_list, nextNodeType(curr_type), tree_frontback.diff_childs, ms, rec+1)) return true;

  // if not, I need to see if I'm matching the topic AND I reached a possible leaf, if so I'm all done, set the template
  else if (curr_type == NODE_TOPIC && !tree_frontback.templ.empty()) { ms.templ = tree_frontback.templ; return true; }

  // If I reach here, then there was no match anywere, so I remove the previously added token from <*star>
  ms.sh.DelStar(it, curr_type);
  return false;
}
Ejemplo n.º 13
0
inline command_queue
default_queue_for_copy(InputIterator first,
                       OutputIterator result,
                       typename boost::enable_if<
                           typename boost::mpl::and_<
                               is_buffer_iterator<InputIterator>,
                               boost::mpl::not_<is_buffer_iterator<OutputIterator> >
                           >
                       >::type* = 0)
{
    (void) result;

    const buffer &buffer = first.get_buffer();
    const context &context = buffer.get_context();
    const device &device = context.get_device();

    return command_queue(context, device);
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
  const char text1[] = "(1*3+4)/5*93";
  const char text2[] = "9+(9-8)*10";  

  char buffer[BUFFER_SIZE];
  InputIterator* input; 
  MathematicalFormula* context; 
  AstNode *ast, *p_child;

  input = new StringInputIterator(text1, strlen(text1));
  context = new MathematicalFormula(input);
  assert(context->isMatch());
  cout << "\tVerified: Matching of input succeeds\n";
  ast = context->getAST();
  PrintVisitor::printAST(*ast);
  assert(ast->getToken()->getName() == "EXPRESSION");
  printf("\tVerified: The expected token name: '%s'.\n", ast->getToken()->getName().c_str());
  input->getText(buffer, ast->getToken()->getStart(), ast->getToken()->getEnd());
  assert(0 == strcmp(buffer, text1));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  assert(ast->getChildren().size() == 5);
  puts("\tVerified: Expected number of children.");
  p_child = ast->getChildren()[0];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "EXPRESSION"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "1*3+4"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[1];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "/"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);
  
  p_child = ast->getChildren()[2];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "5"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[3];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "*"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[4];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "93"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  assert(ast->getChildren()[0]->getChildren().size() == 5);
  puts("\tVerified: Expected number of children.");

  p_child = ast->getChildren()[0]->getChildren()[0];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "1"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[0]->getChildren()[1];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "*"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[0]->getChildren()[2];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "3"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[0]->getChildren()[3];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "+"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[0]->getChildren()[4];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "4"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  AstNode::deleteAST(ast);
  delete context;
  delete input;

  /*
   * Example 2
   */
  input = new StringInputIterator(text2, strlen(text2));
  context = new MathematicalFormula(input);
  assert(context->isMatch());
  printf("\tVerified: The expected input was matched by parser.\n");

  ast = context->getAST();
  assert(0 == strcmp(ast->getToken()->getName().c_str(), "EXPRESSION"));
  printf("\tVerified: The expected token name: '%s'.\n", ast->getToken()->getName().c_str());
  input->getText(buffer, ast->getToken()->getStart(), ast->getToken()->getEnd());
  assert(0 == strcmp(buffer, text2));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  assert(ast->getChildren().size() == 5);
  puts("\tVerified: Expected number of children.");

  p_child = ast->getChildren()[0];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "9"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);
  
  p_child = ast->getChildren()[1];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "+"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[2];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "EXPRESSION"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "9-8"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[3];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "*"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[4];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "10"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);
  
  assert(ast->getChildren()[2]->getChildren().size() == 3);
  puts("\tVerified: Expected number of children.");

  p_child = ast->getChildren()[2]->getChildren()[0];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "9"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[2]->getChildren()[1];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "SYMBOL"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "-"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  p_child = ast->getChildren()[2]->getChildren()[2];
  assert(0 == strcmp(p_child->getToken()->getName().c_str(), "VALUE"));
  printf("\tVerified: The expected token name: '%s'.\n", p_child->getToken()->getName().c_str());
  input->getText(buffer, p_child->getToken()->getStart(), p_child->getToken()->getEnd());
  assert(0 == strcmp(buffer, "8"));
  printf("\tVerified: The expected matched string: '%s'.\n", buffer);

  AstNode::deleteAST(ast);
  delete context;
  delete input;

  return 0;
}