OmniSciDB  16c4e035a1
 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 310 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_.

310  {
311  if (inc_ == -1 && curr_idx_ != 0) {
312  // Shift data to the left left by curr_idx_.
313  // Prefer to copy, but thrust::copy doesn't support overlapping ranges.
314  // Reverse instead, which gets sorted below.
315  // gpu_enabled::copy(sums_.begin() + curr_idx_, sums_.end(), sums_.begin());
316  // gpu_enabled::copy(counts_.begin() + curr_idx_, counts_.end(), counts_.begin());
319  }
320  // Shift VectorViews to the right by buff.curr_idx_.
321  IndexType const offset = inc_ == 1 ? 0 : buff.curr_idx_;
322  IndexType const buff_size =
323  inc_ == 1 ? buff.curr_idx_ + 1 : buff.size() - buff.curr_idx_;
324  VectorView<RealType> buff_sums(buff.sums_.begin() + offset, buff_size, buff_size);
325  VectorView<IndexType> buff_counts(buff.counts_.begin() + offset, buff_size, buff_size);
326  // Copy buff into sums_ and counts_.
327  IndexType const curr_size = inc_ == 1 ? curr_idx_ + 1 : size() - curr_idx_;
328  IndexType const total_size = curr_size + buff_sums.size();
329  assert(total_size <= sums_.capacity()); // TODO proof of inequality
330  sums_.resize(total_size);
331  gpu_enabled::copy(buff_sums.begin(), buff_sums.end(), sums_.begin() + curr_size);
332  assert(total_size <= counts_.capacity());
333  counts_.resize(total_size);
334  gpu_enabled::copy(buff_counts.begin(), buff_counts.end(), counts_.begin() + curr_size);
335 
336  // Sort sums_ and counts_ by (mean, -count).
339  gpu_enabled::sort(begin, end, OrderByMeanAscCountDesc<RealType, IndexType>());
340 }
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:60
DEVICE void resize(size_type const size)
Definition: VectorView.h:75
VectorView< IndexType > counts_
Definition: quantile.h:61
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:121
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 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:61
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: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 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_, i, 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 344 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().

345  {
346  if (counts_[curr_idx_] + centroid.nextCount() <= max_count) {
347  sums_[curr_idx_] += centroid.nextSum();
348  counts_[curr_idx_] += centroid.nextCount();
349  centroid.next_idx_ += centroid.inc_;
350  return true;
351  }
352  return false;
353 }
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 356 of file quantile.h.

356  {
357  curr_idx_ += inc_;
358  if (curr_idx_ != next_idx_) {
361  }
362  next_idx_ += inc_;
363 }
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);
117  }
DEVICE void push_back(T const &value)
Definition: VectorView.h:74
VectorView< RealType > sums_
Definition: quantile.h:60
VectorView< IndexType > counts_
Definition: quantile.h:61
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 366 of file quantile.h.

366  {
367  if (forward) {
368  inc_ = 1;
369  curr_idx_ = ~IndexType(0);
370  } else {
371  inc_ = -1;
372  curr_idx_ = size();
373  }
374  static_assert(std::is_unsigned<IndexType>::value,
375  "IndexType must be an unsigned type.");
377 }
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: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 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: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 63 of file quantile.h.


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