OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quantile::detail::Centroids< RealType, IndexType > Struct Template Reference

#include <quantile.h>

+ Collaboration diagram for quantile::detail::Centroids< RealType, IndexType >:

Public Member Functions

 Centroids ()=default
 
DEVICE Centroids (RealType *sums, IndexType *counts, IndexType const size)
 
DEVICE Centroids (VectorView< RealType > sums, VectorView< IndexType > counts)
 
DEVICE void appendAndSortCurrent (Centroids &buff)
 
DEVICE IndexType capacity () const
 
DEVICE void clear ()
 
DEVICE IndexType currCount () const
 
DEVICE RealType currMean () const
 
DEVICE bool hasCurr () const
 
DEVICE bool hasNext () const
 
DEVICE RealType mean (IndexType const i) const
 
DEVICE bool mergeIfFits (Centroids &centroid, IndexType const max_count)
 
DEVICE void moveNextToCurrent ()
 
DEVICE IndexType nextCount () const
 
DEVICE RealType nextSum () const
 
DEVICE bool operator< (Centroids const &b) const
 
DEVICE void push_back (RealType const value, RealType const count)
 
DEVICE void resetIndices (bool const forward)
 
DEVICE size_t size () const
 
DEVICE IndexType totalWeight () const
 

Public Attributes

IndexType curr_idx_
 
IndexType next_idx_
 
int inc_
 
VectorView< RealType > sums_
 
VectorView< IndexType > counts_
 
RealType max_ {-infinity}
 
RealType min_ {infinity}
 

Static Public Attributes

static constexpr RealType infinity = std::numeric_limits<RealType>::infinity()
 
static constexpr RealType nan = std::numeric_limits<RealType>::quiet_NaN()
 

Friends

template<typename RealType2 , typename IndexType2 >
std::ostream & operator<< (std::ostream &, Centroids< RealType2, IndexType2 > const &)
 

Detailed Description

template<typename RealType, typename IndexType>
struct quantile::detail::Centroids< RealType, IndexType >

Definition at line 54 of file quantile.h.

Constructor & Destructor Documentation

template<typename RealType, typename IndexType>
quantile::detail::Centroids< RealType, IndexType >::Centroids ( )
default
template<typename RealType, typename IndexType>
DEVICE quantile::detail::Centroids< RealType, IndexType >::Centroids ( RealType *  sums,
IndexType *  counts,
IndexType const  size 
)
inline

Definition at line 67 of file quantile.h.

68  : sums_(sums, size, size), counts_(counts, size, size) {}
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59
DEVICE size_t size() const
Definition: quantile.h:119
template<typename RealType, typename IndexType>
DEVICE quantile::detail::Centroids< RealType, IndexType >::Centroids ( VectorView< RealType >  sums,
VectorView< IndexType >  counts 
)
inline

Definition at line 70 of file quantile.h.

71  : sums_(sums), counts_(counts) {}
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59

Member Function Documentation

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::Centroids< RealType, IndexType >::appendAndSortCurrent ( Centroids< RealType, IndexType > &  buff)

Definition at line 299 of file quantile.h.

References VectorView< T >::begin(), gpu_enabled::copy(), quantile::detail::Centroids< RealType, IndexType >::counts_, quantile::detail::Centroids< RealType, IndexType >::curr_idx_, gpu_enabled::reverse(), VectorView< T >::size(), quantile::detail::Centroids< RealType, IndexType >::size(), gpu_enabled::sort(), and quantile::detail::Centroids< RealType, IndexType >::sums_.

299  {
300  if (inc_ == -1 && curr_idx_ != 0) {
301  // Shift data to the left left by curr_idx_.
302  // Prefer to copy, but thrust::copy doesn't support overlapping ranges.
303  // Reverse instead, which gets sorted below.
304  // gpu_enabled::copy(sums_.begin() + curr_idx_, sums_.end(), sums_.begin());
305  // gpu_enabled::copy(counts_.begin() + curr_idx_, counts_.end(), counts_.begin());
308  }
309  // Shift VectorViews to the right by buff.curr_idx_.
310  IndexType const offset = inc_ == 1 ? 0 : buff.curr_idx_;
311  IndexType const buff_size =
312  inc_ == 1 ? buff.curr_idx_ + 1 : buff.size() - buff.curr_idx_;
313  VectorView<RealType> buff_sums(buff.sums_.begin() + offset, buff_size, buff_size);
314  VectorView<IndexType> buff_counts(buff.counts_.begin() + offset, buff_size, buff_size);
315  // Copy buff into sums_ and counts_.
316  IndexType const curr_size = inc_ == 1 ? curr_idx_ + 1 : size() - curr_idx_;
317  IndexType const total_size = curr_size + buff_sums.size();
318  assert(total_size <= sums_.capacity()); // TODO proof of inequality
319  sums_.resize(total_size);
320  gpu_enabled::copy(buff_sums.begin(), buff_sums.end(), sums_.begin() + curr_size);
321  assert(total_size <= counts_.capacity());
322  counts_.resize(total_size);
323  gpu_enabled::copy(buff_counts.begin(), buff_counts.end(), counts_.begin() + curr_size);
324 
325  // Sort sums_ and counts_ by (mean, -count).
328  gpu_enabled::sort(begin, end, OrderByMeanAscCountDesc<RealType, IndexType>());
329 }
DEVICE size_type capacity() const
Definition: VectorView.h:61
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
VectorView< RealType > sums_
Definition: quantile.h:58
DEVICE void resize(size_type const size)
Definition: VectorView.h:75
VectorView< IndexType > counts_
Definition: quantile.h:59
DEVICE size_type size() const
Definition: VectorView.h:84
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
DEVICE T * begin() const
Definition: VectorView.h:60
DEVICE size_t size() const
Definition: quantile.h:119
DEVICE void reverse(ARGS &&...args)
Definition: gpu_enabled.h:96
DEVICE T * end() const
Definition: VectorView.h:68

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE IndexType quantile::detail::Centroids< RealType, IndexType >::capacity ( ) const
inline

Definition at line 75 of file quantile.h.

References VectorView< T >::capacity(), and quantile::detail::Centroids< RealType, IndexType >::sums_.

75 { return sums_.capacity(); }
DEVICE size_type capacity() const
Definition: VectorView.h:61
VectorView< RealType > sums_
Definition: quantile.h:58

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE void quantile::detail::Centroids< RealType, IndexType >::clear ( )
inline

Definition at line 77 of file quantile.h.

References VectorView< T >::clear(), quantile::detail::Centroids< RealType, IndexType >::counts_, quantile::detail::Centroids< RealType, IndexType >::infinity, quantile::detail::Centroids< RealType, IndexType >::max_, quantile::detail::Centroids< RealType, IndexType >::min_, and quantile::detail::Centroids< RealType, IndexType >::sums_.

Referenced by quantile::detail::TDigest< RealType, IndexType >::mergeCentroids().

77  {
78  sums_.clear();
79  counts_.clear();
80  max_ = -infinity;
81  min_ = infinity;
82  }
static constexpr RealType infinity
Definition: quantile.h:60
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59
DEVICE void clear()
Definition: VectorView.h:64

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename RealType, typename IndexType>
DEVICE IndexType quantile::detail::Centroids< RealType, IndexType >::currCount ( ) const
inline
template<typename RealType, typename IndexType>
DEVICE RealType quantile::detail::Centroids< RealType, IndexType >::currMean ( ) const
inline

Definition at line 86 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::curr_idx_, and quantile::detail::Centroids< RealType, IndexType >::mean().

86 { return mean(curr_idx_); }
DEVICE RealType mean(IndexType const i) const
Definition: quantile.h:92

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE bool quantile::detail::Centroids< RealType, IndexType >::hasCurr ( ) const
inline

Definition at line 88 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::curr_idx_, and quantile::detail::Centroids< RealType, IndexType >::size().

88 { return curr_idx_ < size(); }
DEVICE size_t size() const
Definition: quantile.h:119

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE bool quantile::detail::Centroids< RealType, IndexType >::hasNext ( ) const
inline

Definition at line 90 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::next_idx_, and quantile::detail::Centroids< RealType, IndexType >::size().

90 { return next_idx_ < size(); }
DEVICE size_t size() const
Definition: quantile.h:119

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE RealType quantile::detail::Centroids< RealType, IndexType >::mean ( IndexType const  i) const
inline

Definition at line 92 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::counts_, i, and quantile::detail::Centroids< RealType, IndexType >::sums_.

Referenced by quantile::detail::Centroids< RealType, IndexType >::currMean().

92 { return sums_[i] / counts_[i]; }
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType >
DEVICE bool quantile::detail::Centroids< RealType, IndexType >::mergeIfFits ( Centroids< RealType, IndexType > &  centroid,
IndexType const  max_count 
)

Definition at line 333 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::inc_, quantile::detail::Centroids< RealType, IndexType >::next_idx_, quantile::detail::Centroids< RealType, IndexType >::nextCount(), and quantile::detail::Centroids< RealType, IndexType >::nextSum().

334  {
335  if (counts_[curr_idx_] + centroid.nextCount() <= max_count) {
336  sums_[curr_idx_] += centroid.nextSum();
337  counts_[curr_idx_] += centroid.nextCount();
338  centroid.next_idx_ += centroid.inc_;
339  return true;
340  }
341  return false;
342 }
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59

+ Here is the call graph for this function:

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::Centroids< RealType, IndexType >::moveNextToCurrent ( )

Definition at line 345 of file quantile.h.

345  {
346  curr_idx_ += inc_;
347  if (curr_idx_ != next_idx_) {
350  }
351  next_idx_ += inc_;
352 }
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59
template<typename RealType, typename IndexType>
DEVICE IndexType quantile::detail::Centroids< RealType, IndexType >::nextCount ( ) const
inline
template<typename RealType, typename IndexType>
DEVICE RealType quantile::detail::Centroids< RealType, IndexType >::nextSum ( ) const
inline
template<typename RealType, typename IndexType>
DEVICE bool quantile::detail::Centroids< RealType, IndexType >::operator< ( Centroids< RealType, IndexType > const b) const
inline

Definition at line 105 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::nextCount(), and quantile::detail::Centroids< RealType, IndexType >::nextSum().

105  {
106  // lhs < rhs is same as nextMean() < b.nextMean() without division
107  RealType const lhs = nextSum() * b.nextCount();
108  RealType const rhs = b.nextSum() * nextCount();
109  return lhs < rhs || (lhs == rhs && b.nextCount() < nextCount());
110  }
DEVICE IndexType nextCount() const
Definition: quantile.h:99
DEVICE RealType nextSum() const
Definition: quantile.h:101

+ Here is the call graph for this function:

template<typename RealType, typename IndexType>
DEVICE void quantile::detail::Centroids< RealType, IndexType >::push_back ( RealType const  value,
RealType const  count 
)
inline

Definition at line 112 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::counts_, VectorView< T >::push_back(), and quantile::detail::Centroids< RealType, IndexType >::sums_.

112  {
113  sums_.push_back(value);
115  }
DEVICE void push_back(T const &value)
Definition: VectorView.h:74
VectorView< RealType > sums_
Definition: quantile.h:58
VectorView< IndexType > counts_
Definition: quantile.h:59
int count

+ Here is the call graph for this function:

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::Centroids< RealType, IndexType >::resetIndices ( bool const  forward)

Definition at line 355 of file quantile.h.

355  {
356  if (forward) {
357  inc_ = 1;
358  curr_idx_ = ~IndexType(0);
359  } else {
360  inc_ = -1;
361  curr_idx_ = size();
362  }
363  static_assert(std::is_unsigned<IndexType>::value,
364  "IndexType must be an unsigned type.");
366 }
DEVICE size_t size() const
Definition: quantile.h:119
template<typename RealType, typename IndexType>
DEVICE size_t quantile::detail::Centroids< RealType, IndexType >::size ( ) const
inline

Definition at line 119 of file quantile.h.

References VectorView< T >::size(), and quantile::detail::Centroids< RealType, IndexType >::sums_.

Referenced by quantile::detail::Centroids< RealType, IndexType >::appendAndSortCurrent(), quantile::detail::Centroids< RealType, IndexType >::hasCurr(), quantile::detail::Centroids< RealType, IndexType >::hasNext(), and quantile::detail::operator<<().

119 { return sums_.size(); }
VectorView< RealType > sums_
Definition: quantile.h:58
DEVICE size_type size() const
Definition: VectorView.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename RealType, typename IndexType>
DEVICE IndexType quantile::detail::Centroids< RealType, IndexType >::totalWeight ( ) const
inline

Definition at line 121 of file quantile.h.

References gpu_enabled::accumulate(), VectorView< T >::begin(), quantile::detail::Centroids< RealType, IndexType >::counts_, and VectorView< T >::end().

121  {
122  return gpu_enabled::accumulate(counts_.begin(), counts_.end(), IndexType(0));
123  }
VectorView< IndexType > counts_
Definition: quantile.h:59
DEVICE T * begin() const
Definition: VectorView.h:60
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42
DEVICE T * end() const
Definition: VectorView.h:68

+ Here is the call graph for this function:

Friends And Related Function Documentation

template<typename RealType, typename IndexType>
template<typename RealType2 , typename IndexType2 >
std::ostream& operator<< ( std::ostream &  ,
Centroids< RealType2, IndexType2 > const  
)
friend

Member Data Documentation

template<typename RealType, typename IndexType>
constexpr RealType quantile::detail::Centroids< RealType, IndexType >::infinity = std::numeric_limits<RealType>::infinity()
static
template<typename RealType, typename IndexType>
RealType quantile::detail::Centroids< RealType, IndexType >::max_ {-infinity}
template<typename RealType, typename IndexType>
RealType quantile::detail::Centroids< RealType, IndexType >::min_ {infinity}
template<typename RealType, typename IndexType>
constexpr RealType quantile::detail::Centroids< RealType, IndexType >::nan = std::numeric_limits<RealType>::quiet_NaN()
static

Definition at line 61 of file quantile.h.


The documentation for this struct was generated from the following file: