// The constructor uses the appropriate settings in the config file to // properly set up the sensor model for the specified "phase" of the LGMD // input signal. SensorModel::SensorModel(const std::string& lgmd_phase) : m_sigma(0.0f), m_name(lgmd_phase) { const range<float> lgmd_range = get_conf(locust_model(), "spike_range", make_range(0.0f, 800.0f)) ; // Get the LGMD ranges for the columns of the sensor model m_lgmd_ranges = string_to_deque<float>( conf<std::string>(lgmd_phase + "_lgmd_ranges", "0 800")) ; if (m_lgmd_ranges.size() < 2) { // crappy configuration! m_lgmd_ranges.clear() ; m_lgmd_ranges.push_back(lgmd_range.min()) ; m_lgmd_ranges.push_back(lgmd_range.max()) ; } sort(m_lgmd_ranges.begin(), m_lgmd_ranges.end()) ; if (m_lgmd_ranges.front() > lgmd_range.min()) m_lgmd_ranges.push_front(lgmd_range.min()) ; if (m_lgmd_ranges.back() < lgmd_range.max()) m_lgmd_ranges.push_back(lgmd_range.max()) ; // Figure out how many rows and columns the sensor model's probability // table has and allocate space for the required number of elements. // Initialize the probability table using a uniform distribution. const int C = m_lgmd_ranges.size() - 1 ; const int R = column_size() ; const int N = R * C ; m_prob.reserve(N) ; std::fill_n(std::back_inserter(m_prob), N, 1.0f/N) ; // Apply Gabbiani model to obtain causal probabilities and Gaussian // blur neighbouring bins in each row. update(clamp(conf(lgmd_phase + "_sigma", 1.0f), 0.1f, static_cast<float>(row_size()))) ; }
// Quick helper to return a label for the current range of probability // values used for scaling the texels used to represent the sensor // model's probabilities. static std::string prob_label(const range<float>& prob_range) { std::ostringstream str ; str << "P-range: [" << prob_range.min() << ", " << prob_range.max() << ']' ; return str.str() ; }
void MipsELFFile<ELFT>::createRelocationReferences(const Elf_Sym *symbol, ArrayRef<uint8_t> symContent, ArrayRef<uint8_t> secContent, range<Elf_Rel_Iter> rels) { const auto value = this->getSymbolValue(symbol); for (Elf_Rel_Iter rit = rels.begin(), eit = rels.end(); rit != eit; ++rit) { if (rit->r_offset < value || value + symContent.size() <= rit->r_offset) continue; auto r = new (this->_readerStorage) MipsELFReference<ELFT>(value, *rit); this->addReferenceToSymbol(r, symbol); this->_references.push_back(r); auto addend = readAddend(*rit, secContent); auto pairRelType = getPairRelocation(*rit); if (pairRelType != llvm::ELF::R_MIPS_NONE) { addend <<= 16; auto mit = findMatchingRelocation(pairRelType, rit, eit); if (mit != eit) addend += int16_t(readAddend(*mit, secContent)); else // FIXME (simon): Show detailed warning. llvm::errs() << "lld warning: cannot matching LO16 relocation\n"; } this->_references.back()->setAddend(addend); } }
void operator()(const range& r) const{ for (int i = r.begin(); i != r.end(); ++i) { if (compareWord(word, words[i])) { cout << words[i] << endl; } } }
void jacobi_kernel_wrapper(range const & y_range, size_t n, vector<double> & dst, vector<double> const & src) { for(size_t y = y_range.begin(); y < y_range.end(); ++y) { double * dst_ptr = &dst[y * n]; const double * src_ptr = &src[y * n]; jacobi_kernel( dst_ptr, src_ptr, n ); } }
double_block_type::double_block_type(const range &bounds, const offset_multiplier &ls) : bounds_(bounds), ls_(ls) { if (bounds.has_low() || bounds.has_high()) if (ls.has_offset() || ls.has_multiplier()) throw std::invalid_argument("Block type cannot have both a bound and" "an offset/multiplier."); }
void jacobi_kernel_wrap( range const & r, crs_matrix<double> const & A, std::vector<double> & x_dst, std::vector<double> const & x_src, std::vector<double> const & b) { for(std::size_t row = r.begin(); row < r.end(); ++row) { jacobi_kernel_nonuniform(A, x_dst, x_src, b, row); } }
void database::del(range key) { assert(_db); struct slice sk; sk.data = const_cast<char*>(key.begin()); sk.len = key.size(); ::db_remove(_db, &sk); }
inline bool is_mergeable (const range<iter1_t> &src1, const range<iter2_t> &src2, compare comp ) { //---------------------------- begin ------------------------------------ typedef typename iterator_traits<iter1_t>::value_type type1 ; typedef typename iterator_traits<iter2_t>::value_type type2 ; static_assert ( std::is_same<type1, type2>::value, "Incompatible iterators\n"); //---------------------------- begin -------------------------------------- return comp ( *(src2.front()), *(src1.back())); };
__forceinline NodeRef operator() (const PrimRef* prims, const range<size_t>& set, const FastAllocator::CachedAllocator& alloc) const { size_t n = set.size(); size_t items = Primitive::blocks(n); size_t start = set.begin(); Primitive* accel = (Primitive*) alloc.malloc1(items*sizeof(Primitive),BVH::byteAlignment); typename BVH::NodeRef node = BVH::encodeLeaf((char*)accel,items); for (size_t i=0; i<items; i++) { accel[i].fill(prims,start,set.end(),bvh->scene); } return node; }
inline range<Iter2_t> init_move ( const range<Iter2_t> & dest, const range<Iter1_t> & src) { //------------- static checking ------------------------------------------ typedef typename iterator_traits<Iter1_t>::value_type type1 ; typedef typename iterator_traits<Iter2_t>::value_type type2 ; static_assert ( std::is_same<type1, type2>::value, "Incompatible iterators\n"); //------------------------------- begin ---------------------------------- if ( src.size() == 0 ) return range<Iter2_t>(dest.first, dest.first); init_move(dest.first ,src.first, src.last ); return range<Iter2_t>(dest.first, dest.first + src.size()) ; };
void OffsetRange(range& ioRange, cell inOffset, SplitType what, int split, int shift) { bool wasSpecial = false; if (shift < 0 && what != noSplit) if (what == hSplit) { if (abs(ioRange.left) >= split && abs(ioRange.right) <= split - shift) ioRange.Set(0, 0, 0, 0); else if (abs(ioRange.left) >= split && abs(ioRange.left) <= split - shift) { if (ioRange.left < 0) ioRange.left = -split; else ioRange.left = split; OffsetCell(ioRange.BotRight(), inOffset, what, split, shift); wasSpecial = true; } else if (abs(ioRange.right) >= split && abs(ioRange.right) <= split - shift) { if (ioRange.right < 0) ioRange.right = -split + 1; else ioRange.right = split - 1; OffsetCell(ioRange.TopLeft(), inOffset, what, split, shift); wasSpecial = true; } } else if (what == vSplit) { if (abs(ioRange.top) >= split && abs(ioRange.bottom) <= split - shift) ioRange.Set(0, 0, 0, 0); else if (abs(ioRange.top) >= split && abs(ioRange.top) <= split - shift) { if (ioRange.top < 0) ioRange.top = -split; else ioRange.top = split; OffsetCell(ioRange.BotRight(), inOffset, what, split, shift); wasSpecial = true; } else if (abs(ioRange.bottom) >= split && abs(ioRange.bottom) <= split - shift) { if (ioRange.bottom < 0) ioRange.bottom = -split + 1; else ioRange.bottom = split - 1; OffsetCell(ioRange.TopLeft(), inOffset, what, split, shift); wasSpecial = true; } } if (!wasSpecial) { OffsetCell(ioRange.TopLeft(), inOffset, what, split, shift); OffsetCell(ioRange.BotRight(), inOffset, what, split, shift); } } /* OffsetRange */
void generic_par_for_wg(range<Dimensions> k_range, range<Dimensions> workgroup_size) { queue my_queue; // the product of all Dimensions e.g. 10*10*10 for {10,10,10} auto linr_size = k_range.size(), linwg_size = workgroup_size.size(); // these will simply have the group, local and global linear ids assigned to // them auto group_lin = buffer<int>(linr_size / linwg_size); auto loc_lin = buffer<int>(linr_size); auto gl_lin = buffer<int>(linr_size); my_queue.submit([&](handler &cgh) { auto group_lin_acc = group_lin.get_access<access::mode::write>(cgh); auto loc_lin_acc = loc_lin.get_access<access::mode::write>(cgh); auto gl_lin_acc = gl_lin.get_access<access::mode::read_write>(cgh); cgh.parallel_for_work_group<kernel_name>( nd_range<Dimensions>(k_range, workgroup_size), [=](group<Dimensions> group) { group_lin_acc[group.get_linear_id()] = group.get_linear_id(); group.parallel_for_work_item([=](h_item<Dimensions> tile) { loc_lin_acc[tile.get_global_linear_id()] = tile.get_local_linear_id(); gl_lin_acc[tile.get_global_linear_id()] = tile.get_global_linear_id(); }); }); }); auto loc_lin_out = loc_lin.get_access<access::mode::read>(); auto group_lin_out = group_lin.get_access<access::mode::read>(); auto gl_lin_out = gl_lin.get_access<access::mode::read>(); for (int i = 0; i < linr_size / linwg_size; ++i) { BOOST_CHECK(group_lin_out[i] == i); // group id } for (int i = 0; i < linr_size; ++i) { BOOST_CHECK(gl_lin_out[i] == i); // w1 global id BOOST_CHECK(loc_lin_out[i] == loc_lin_out[i] % linwg_size); // local id } /* We must wait for for the queue to finish as none of buffer's destruction is blocking. */ my_queue.wait(); }
void database::add(range key, range data) { assert(_db); struct slice sk, sv; sk.data = const_cast<char*>(key.begin()); sk.len = key.size(); sv.data = const_cast<char*>(data.begin()); sv.len = data.size(); if (::db_add(_db, &sk, &sv) == 0) { throw exception("error adding to ness backend"); } }
[[nodiscard]] inline size_t read(std::istream& Stream, const range<char*>& Buffer) { { const auto Exceptions = Stream.exceptions(); Stream.exceptions(Exceptions & ~(Stream.failbit | Stream.eofbit)); SCOPE_EXIT{ Stream.exceptions(Exceptions); }; Stream.read(Buffer.data(), Buffer.size()); if (!Stream.bad() && Stream.eof()) Stream.clear(); } return Stream.gcount(); }
void compare (Distances distances, Reference const & reference_) { auto reference = range::view (reference_); while (!empty (reference)) { BOOST_CHECK (!empty (distances)); if (empty (distances)) return; auto d = chop_in_place (distances); auto r = chop_in_place (reference); BOOST_CHECK_EQUAL (first (d), first (r)); BOOST_CHECK_EQUAL (second (d), second (r)); } BOOST_CHECK (empty (distances)); }
rect<R> intersection_with(rect<U> const r) const { auto const& a = *this; auto const& b = r; range<T> const ax(a.left, a.right); range<T> const ay(a.top, a.bottom); range<U> const bx(b.left, b.right); range<U> const by(b.top, b.bottom); auto const ix = ax.intersection_with(bx); auto const iy = ay.intersection_with(by); return rect<R>( ix.first, iy.first, ix.last, iy.last ); }
// assume start < end // assume s <= start < end <= e // return true if one or more than one item in [start, end) has been inserted bool conflict(int start, int end) { if (inserted) return true; if (start == s && end == e) { if (l == nullptr && r == nullptr) return inserted; } if (end <= p) { return l == nullptr ? false : l->conflict(start, end); } else if (start < p && end > p) { return (l == nullptr ? false : l->conflict(start, p)) || (r == nullptr ? false : r->conflict(p, end)); } else // (start >= p) { return r == nullptr ? false : r->conflict(start, end); }
/// \brief Adds a transition for a range of surrogate symbols for the specified state static void add_surrogate_transition(const range<int>& surrogateRange, int currentState, int targetState, ndfa* nfa) { // If the range is out of the range of valid surrogate characters then clip it if (surrogateRange.lower() >= 0x110000) return; if (surrogateRange.upper() > 0x110000) { add_surrogate_transition(range<int>(surrogateRange.lower(), 0x110000), currentState, targetState, nfa); return; } // Work out the range as surrogate pairs pair<int, int> surrogateLower = surrogate_pair(surrogateRange.lower()); pair<int, int> surrogateHigher = surrogate_pair(surrogateRange.upper()-1); // Action depends on whether or not there are 1, 2 or more 'upper' characters if (surrogateLower.first == surrogateHigher.first) { // Transit to a state if we match the 'upper' code point int tmpState = nfa->add_state(); nfa->add_transition(currentState, range<int>(surrogateLower.first, surrogateLower.first+1), tmpState); // Transit to the final state if we match any of the lower symbols nfa->add_transition(tmpState, range<int>(surrogateLower.second, surrogateHigher.second+1), targetState); } else { // Transit to a new state for the lower set of symbols int tmpState1 = nfa->add_state(); nfa->add_transition(currentState, range<int>(surrogateLower.first, surrogateLower.first+1), tmpState1); // Transit to the final state for all the 'lower' symbols nfa->add_transition(tmpState1, range<int>(surrogateLower.second, 0xdc00), targetState); // ... do the same for the 'upper' set of symbols int tmpState2 = nfa->add_state(); nfa->add_transition(currentState, range<int>(surrogateHigher.first, surrogateHigher.first+1), tmpState2); // Transit to the final state for all the 'lower' symbols nfa->add_transition(tmpState2, range<int>(0xd800, surrogateHigher.second+1), targetState); // If there's a middle range, then add transitions for that as well if (surrogateHigher.first-1 > surrogateLower.first) { // Transit for all of the remaining 'higher' symbols int tmpState3 = nfa->add_state(); nfa->add_transition(currentState, range<int>(surrogateLower.first+1, surrogateHigher.first), tmpState3); // Accept for any 'lower' symbol nfa->add_transition(tmpState3, range<int>(0xdc00, 0xe000), targetState); } } }
void escape_line(range const& line) { auto begin = line.begin(); auto end = begin; while (end != line.end()) { if (*end == '<') { stream_ << range(begin, end) << "<"; begin = ++end; } else if (*end == '>') { stream_ << range(begin, end) << ">"; begin = ++end; } else ++end; } if (begin != end) stream_ << range(begin, end); }
void accessor<BufferT>::set(const range& blk, uint32_t offset, const std::vector<type>& v) { if(!blk.is_valid() || offset + v.size() > blk.count || !is_mapped()) return; const uint32_t idx = map_start_ == 0 ? blk.start + offset : offset, count = uint32_t(v.size()); buffer_ptr_->mapped_copy(v, idx, count); enqueue_flush(range(idx, uint32_t(v.size()))); }
void accessor<BufferT>::set(const range& blk, uint32_t offset, uint32_t count, const type* p) { if(!blk.is_valid() || offset + count > blk.count || !is_mapped()) return; const uint32_t idx = map_start_ == 0 ? blk.start + offset : offset; buffer_ptr_->mapped_copy(p, idx, count); enqueue_flush(range(idx, count)); }
void accessor<BufferT>::set(const range& blk, uint32_t offset, const type& i) { if(!blk.is_valid() || offset >= blk.count || !is_mapped()) return; const auto idx = map_start_ == 0 ? blk.start + offset : offset; buffer_ptr_->operator[](idx) = i; enqueue_flush(range(idx, 1)); }
std::string database::get(range key) { assert(_db); struct slice sk, sv; sk.data = const_cast<char*>(key.begin()); sk.len = key.size(); if (::db_get(_db, &sk, &sv) == 0) { throw exception("error reading from ness backend"); } // copy the data out std::string result(sv.data, sv.len); ::free(sv.data); return result; }
// This method regenerates the sensor model's probabilities using the // Gabbiani LGMD model and the given standard deviation for the Gaussian // blurring operation for bins near the ones actually "pointed to" by the // [TTI, LGMD] pairs returned by the Gabbiani model. // // DEVNOTE: The sigma provided to this function is actually added to the // m_sigma member variable. This allows client behaviours to increment or // decrement the current sigma value rather than provide an actual sigma. // The very first sigma will be read from the config file (see // constructor). void SensorModel::update(float dsigma) { AutoMutex M(m_mutex) ; // Record new standard deviation const float R = row_size() ; m_sigma = clamp(m_sigma + dsigma, 0.1f, R) ; // Begin with a uniform distribution for each state const int N = m_prob.size() ; std::fill_n(m_prob.begin(), N, 1/R) ; // Apply Gabbiani LGMD model to generate causal likelihoods const float step = row_step()/4.0f ; const range<float> tti = conf(m_name + "_tti_range", Params::tti_range()) ; for (float t = tti.min(); t <= tti.max(); t += step) update_row(t, GabbianiModel::spike_rate(t), m_sigma) ; }
virtual std::size_t take (const range& data) { detail::dummy_input_take_impl (); typename range::value_type zero ( sound::sample_traits< typename sound::sample_type<range>::type >::zero_value ()); fill_frames (data, zero); return data.size (); }
range<const byte*> write(const range<const byte*>& buf){ AIO_PRE_CONDITION(!finished); AIO_PRE_CONDITION(zstream.avail_in == 0); crc = crc32(buf, crc); zstream.next_in = (Bytef*)buf.begin(); zstream.avail_in = uInt(buf.size()); for(;zstream.avail_in != 0;){ if (zstream.avail_out ==0 ) new_buffer_(); switch (deflate(&zstream, Z_NO_FLUSH)){ case Z_OK: case Z_BUF_ERROR: break; default: AIO_THROW(deflate_exception)("deflate with Z_NO_FLUSH failed"); } } return range<const byte*>(buf.end(), buf.end()); }
// assume start < end // assume s <= start < end <= e void insert(int start, int end) { if (s == start && e == end) { inserted = true; return; } if (end <= p) { if (l == nullptr) l = new range(s, p); l->insert(start, end); } else if (start < p && end > p) { if (l == nullptr) l = new range(s, p); if (r == nullptr) r = new range(p, e); l->insert(start, p); r->insert(p, end); } else if (start >= p) { if (r == nullptr) r = new range(p, e); r->insert(start, end); } }
inline bool operator == (range<char const*> const &value, range<char const*> const &other) { if (value.size() == other.size()) { return value.empty() ? true : strncmp(value.begin(), other.begin(), value.size()) == 0; } return false; }
template <typename Iter, typename Other> inline bool operator == (range<Iter> const &value, range<Other> const &other) { if (value.size() == other.size()) { return value.empty() ? true : std::equal(value.begin(), value.end(), other.begin()); } return false; }