OmniSciDB  a5dc49c757
 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 351 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_.

351  {
352  if (inc_ == -1 && curr_idx_ != 0) {
353  // Shift data to the left left by curr_idx_.
354  // Prefer to copy, but thrust::copy doesn't support overlapping ranges.
355  // Reverse instead, which gets sorted below.
356  // gpu_enabled::copy(sums_.begin() + curr_idx_, sums_.end(), sums_.begin());
357  // gpu_enabled::copy(counts_.begin() + curr_idx_, counts_.end(), counts_.begin());
360  }
361  // Shift VectorViews to the right by buff.curr_idx_.
362  IndexType const offset = inc_ == 1 ? 0 : buff.curr_idx_;
363  IndexType const buff_size =
364  inc_ == 1 ? buff.curr_idx_ + 1 : buff.size() - buff.curr_idx_;
365  VectorView<RealType> buff_sums(buff.sums_.begin() + offset, buff_size, buff_size);
366  VectorView<IndexType> buff_counts(buff.counts_.begin() + offset, buff_size, buff_size);
367  // Copy buff into sums_ and counts_.
368  IndexType const curr_size = inc_ == 1 ? curr_idx_ + 1 : size() - curr_idx_;
369  IndexType const total_size = curr_size + buff_sums.size();
370  assert(total_size <= sums_.capacity()); // TODO proof of inequality
371  sums_.resize(total_size);
372  gpu_enabled::copy(buff_sums.begin(), buff_sums.end(), sums_.begin() + curr_size);
373  assert(total_size <= counts_.capacity());
374  counts_.resize(total_size);
375  gpu_enabled::copy(buff_counts.begin(), buff_counts.end(), counts_.begin() + curr_size);
376 
377  // Sort sums_ and counts_ by (mean, -count).
380  gpu_enabled::sort(begin, end, OrderByMeanAscCountDesc<RealType, IndexType>());
381 }
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 385 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().

386  {
387  if (counts_[curr_idx_] + centroid.nextCount() <= max_count) {
388  sums_[curr_idx_] += centroid.nextSum();
389  counts_[curr_idx_] += centroid.nextCount();
390  centroid.next_idx_ += centroid.inc_;
391  return true;
392  }
393  return false;
394 }
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 397 of file quantile.h.

397  {
398  curr_idx_ += inc_;
399  if (curr_idx_ != next_idx_) {
402  }
403  next_idx_ += inc_;
404 }
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 407 of file quantile.h.

407  {
408  if (forward) {
409  inc_ = 1;
410  curr_idx_ = ~IndexType(0);
411  } else {
412  inc_ = -1;
413  curr_idx_ = size();
414  }
415  static_assert(std::is_unsigned<IndexType>::value,
416  "IndexType must be an unsigned type.");
418 }
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: