OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 56 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 69 of file quantile.h.

70  : sums_(sums, size, size), counts_(counts, size, size) {}
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61
DEVICE size_t size() const
Definition: quantile.h:121
template<typename RealType, typename IndexType>
DEVICE quantile::detail::Centroids< RealType, IndexType >::Centroids ( VectorView< RealType >  sums,
VectorView< IndexType >  counts 
)
inline

Definition at line 72 of file quantile.h.

73  : sums_(sums), counts_(counts) {}
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61

Member Function Documentation

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

Definition at line 321 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_.

321  {
322  if (inc_ == -1 && curr_idx_ != 0) {
323  // Shift data to the left left by curr_idx_.
324  // Prefer to copy, but thrust::copy doesn't support overlapping ranges.
325  // Reverse instead, which gets sorted below.
326  // gpu_enabled::copy(sums_.begin() + curr_idx_, sums_.end(), sums_.begin());
327  // gpu_enabled::copy(counts_.begin() + curr_idx_, counts_.end(), counts_.begin());
330  }
331  // Shift VectorViews to the right by buff.curr_idx_.
332  IndexType const offset = inc_ == 1 ? 0 : buff.curr_idx_;
333  IndexType const buff_size =
334  inc_ == 1 ? buff.curr_idx_ + 1 : buff.size() - buff.curr_idx_;
335  VectorView<RealType> buff_sums(buff.sums_.begin() + offset, buff_size, buff_size);
336  VectorView<IndexType> buff_counts(buff.counts_.begin() + offset, buff_size, buff_size);
337  // Copy buff into sums_ and counts_.
338  IndexType const curr_size = inc_ == 1 ? curr_idx_ + 1 : size() - curr_idx_;
339  IndexType const total_size = curr_size + buff_sums.size();
340  assert(total_size <= sums_.capacity()); // TODO proof of inequality
341  sums_.resize(total_size);
342  gpu_enabled::copy(buff_sums.begin(), buff_sums.end(), sums_.begin() + curr_size);
343  assert(total_size <= counts_.capacity());
344  counts_.resize(total_size);
345  gpu_enabled::copy(buff_counts.begin(), buff_counts.end(), counts_.begin() + curr_size);
346 
347  // Sort sums_ and counts_ by (mean, -count).
350  gpu_enabled::sort(begin, end, OrderByMeanAscCountDesc<RealType, IndexType>());
351 }
DEVICE size_type capacity() const
Definition: VectorView.h:60
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
VectorView< RealType > sums_
Definition: quantile.h:60
DEVICE void resize(size_type const size)
Definition: VectorView.h:74
VectorView< IndexType > counts_
Definition: quantile.h:61
DEVICE size_type size() const
Definition: VectorView.h:83
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
DEVICE T * begin() const
Definition: VectorView.h:59
DEVICE size_t size() const
Definition: quantile.h:121
DEVICE void reverse(ARGS &&...args)
Definition: gpu_enabled.h:96
DEVICE T * end() const
Definition: VectorView.h:67

+ 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 77 of file quantile.h.

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

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

+ 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 79 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().

79  {
80  sums_.clear();
81  counts_.clear();
82  max_ = -infinity;
83  min_ = infinity;
84  }
static constexpr RealType infinity
Definition: quantile.h:62
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61
DEVICE void clear()
Definition: VectorView.h:63

+ 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 88 of file quantile.h.

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

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

+ 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 90 of file quantile.h.

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

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

+ 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 92 of file quantile.h.

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

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

+ 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 94 of file quantile.h.

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

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

94 { return sums_[i] / counts_[i]; }
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61

+ 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 355 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().

356  {
357  if (counts_[curr_idx_] + centroid.nextCount() <= max_count) {
358  sums_[curr_idx_] += centroid.nextSum();
359  counts_[curr_idx_] += centroid.nextCount();
360  centroid.next_idx_ += centroid.inc_;
361  return true;
362  }
363  return false;
364 }
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61

+ Here is the call graph for this function:

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

Definition at line 367 of file quantile.h.

367  {
368  curr_idx_ += inc_;
369  if (curr_idx_ != next_idx_) {
372  }
373  next_idx_ += inc_;
374 }
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61
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 107 of file quantile.h.

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

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

+ 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 114 of file quantile.h.

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

114  {
115  sums_.push_back(value);
116  counts_.push_back(count);
117  }
DEVICE void push_back(T const &value)
Definition: VectorView.h:73
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61

+ 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 377 of file quantile.h.

377  {
378  if (forward) {
379  inc_ = 1;
380  curr_idx_ = ~IndexType(0);
381  } else {
382  inc_ = -1;
383  curr_idx_ = size();
384  }
385  static_assert(std::is_unsigned<IndexType>::value,
386  "IndexType must be an unsigned type.");
388 }
DEVICE size_t size() const
Definition: quantile.h:121
template<typename RealType, typename IndexType>
DEVICE size_t quantile::detail::Centroids< RealType, IndexType >::size ( ) const
inline

Definition at line 121 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<<().

121 { return sums_.size(); }
VectorView< RealType > sums_
Definition: quantile.h:60
DEVICE size_type size() const
Definition: VectorView.h:83

+ 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 123 of file quantile.h.

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

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

+ 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 63 of file quantile.h.


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