示例#1
0
	void push( context * c) {
        spinlock_lock lk{ splk_ };
		if ( is_full_() ) {
			resize_();
		}
		slots_[pidx_] = c;
		pidx_ = (pidx_ + 1) % capacity_;
	}
示例#2
0
/**Refreshes the specified window or if none specified all windows.
 *
 *\param[in] window The pointer to the window to be updated.
 */
void Terminal::refresh_(){
	if(!init){ return; }
	if (SIGNAL_RESIZE) resize_();

	pnoutrefresh(output_window, 
		_scrollbackBufferSize - _winSizeY - _scrollPosition + 1, 0,  //Pad corner to be placed in top left 
		0, 0, _winSizeY - _statusWindowSize - 2, _winSizeX-1); //Size of window
	pnoutrefresh(input_window,0,0, _winSizeY - _statusWindowSize - 1, 0, _winSizeY - _statusWindowSize, _winSizeX-1);
	if (status_window) 
		pnoutrefresh(status_window,0,0, _winSizeY - _statusWindowSize, 0, _winSizeY, _winSizeX-1);

	refresh();

}
示例#3
0
// throw 0 if errors
bool CStack::push_back (int elem)
{
    $
    ASSERT;

    if (cur_ == size_)
        if ( ! resize_ ())
            throw false;

    data_[cur_++] = elem;

    ASSERT;
    return true;
}
示例#4
0
std::tuple<Tensor, Tensor, Tensor, Tensor>
embedding_bag_cpu(const Tensor &weight, const Tensor &indices__,
                  const Tensor &offsets__, const bool scale_grad_by_freq,
                  const int64_t mode, bool sparse) {
  auto indices_arg = TensorArg(indices__, "indices__", 1);
  checkScalarType("embedding_bag", indices_arg, kLong);
  auto offsets_arg = TensorArg(offsets__, "offsets__", 1);
  checkScalarType("embedding_bag", offsets_arg, kLong);
  Tensor indices = indices__.contiguous();
  Tensor offsets = offsets__.contiguous();
  auto weight_arg = TensorArg(weight, "weight", 1);
  checkScalarTypes("embedding_bag", weight_arg, {kFloat, kDouble});

  auto bag_size = at::zeros(offsets.sizes(), indices.type());
  make_bag_size(offsets, indices, mode, bag_size);

  // If the last entries are empty, that the last offsets are irrelevant as they
  // won't change anything in the assignment of ID -> bag, but index_add would
  // throw out of bounds error. So to keep it simple we just add one more
  // entry to the end then get rid of it after make_offset2bag.
  auto offset2bag = at::zeros(
     {indices.sizes()[0] + 1}, indices__.type()); // offset2bag = [0 0 0 0 0]

  make_offset2bag(offsets, indices, offset2bag);

  offset2bag.resize_({indices.sizes()[0]});

  auto output = at::zeros({offsets.size(0), weight.size(1)}, weight.type());

  if (mode == MODE_MEAN || mode == MODE_SUM) {
    if (weight.type().scalarType() == kFloat) {
      index_select_add<float>(indices, offset2bag, weight, output);
    } else if (weight.type().scalarType() == kDouble) {
      index_select_add<double>(indices, offset2bag, weight, output);
    }
    auto ret = apply_bag_size(offsets, indices, mode, output, bag_size);
    return std::tuple<Tensor, Tensor, Tensor, Tensor>(ret, offset2bag, bag_size, bag_size);
  } else { // MODE_MAX
    return AT_DISPATCH_FLOATING_TYPES_AND_HALF(
      weight.type(), "embedding_bag_cpu_max", [&]() {
        return embedding_bag_cpu_max<scalar_t>(weight, indices, offset2bag, output, bag_size, offsets);
      }
    );
  }
}
示例#5
0
static void *delete_(cs_hash_tab *tab, const char *key) {
    size_t index = tab->hash(key) % tab->size;
    cs_knode *n, *p;
    uint32_t i = 0;
    for (n = p = tab->buckets[index]; n != NULL; p = n, n = n->next) {
        if (strcmp(key, n->key) == 0) {
            p->next = n->next;
            // need to specifically set the "de-facto" list head to NULL if the element to be removed is the last one in its bucket
            if (i++ == 0 && n->next == NULL)
                tab->buckets[index] = NULL;
            void *data = n->val;
            destroy_node_(n, tab->free_keys);
            
            if (tab->count-- / (float)tab->size <= tab->min_load)
                resize_(tab, 0.5f);
            
            return data;
        }   
    }
    return NULL;
}
示例#6
0
static void map_(cs_hash_tab *tab, const char *key, void *val) {
    size_t index = tab->hash(key) % tab->size;
    cs_knode *n = lookup_i_(tab, key, index);
    
    // a value is already defined for this key
    // cleanup old; assign new
    if (n != NULL) {
        if (tab->cleanup)
            tab->cleanup(n->key, n->val);
        n->val = val;
        return;
    }
        
    cs_knode *node = malloc(sizeof(cs_knode));
    node->key = (tab->copy_keys ? strdup(key) : (char *)key);
    node->val = val;
    
    install_(tab->buckets, node, index);
    
    if (tab->count++ / (float)tab->size >= tab->max_load)
        resize_(tab, 1.5f);
}
         const std::string &,
         std::string::size_type,
         std::string::size_type
     > >()
 )
 .def(py::init<const boost::dynamic_bitset<> &>())
 .def("swap",
     static_cast<void (boost::dynamic_bitset<>::*)(
         boost::dynamic_bitset<> &
     )>(&boost::dynamic_bitset<>::swap)
 )
 .def("resize",
     static_cast<void (boost::dynamic_bitset<>::*)(
         boost::dynamic_bitset<>::size_type, bool
     )>(&boost::dynamic_bitset<>::resize),
     resize_()
 )
 .def("clear",
     static_cast<void (boost::dynamic_bitset<>::*)(
         void
     )>(&boost::dynamic_bitset<>::clear)
 )
 .def("pop_back",
     static_cast<void (boost::dynamic_bitset<>::*)(
         void
     )>(&boost::dynamic_bitset<>::pop_back)
 )
 .def("push_back",
     static_cast<void (boost::dynamic_bitset<>::*)(
         bool
     )>(&boost::dynamic_bitset<>::push_back)