OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
quantile::detail::TDigest< RealType, IndexType > Class Template Reference

#include <quantile.h>

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

Public Types

using Memory = CentroidsMemory< RealType, IndexType >
 

Public Member Functions

 TDigest ()=default
 
DEVICE TDigest (Memory &mem)
 
DEVICE TDigest (RealType q, SimpleAllocator *simple_allocator, IndexType buf_allocate, IndexType centroids_allocate)
 
TDigestoperator= (TDigest &&rhs)
 
DEVICE Centroids< RealType,
IndexType > & 
centroids ()
 
DEVICE void add (RealType value)
 
DEVICE void allocate ()
 
DEVICE void mergeBuffer ()
 
DEVICE void mergeBufferFinal ()
 
DEVICE void mergeSorted (RealType *sums, IndexType *counts, IndexType size)
 
DEVICE void mergeTDigest (TDigest &t_digest)
 
DEVICE VectorView< IndexType
const > 
partialSumOfCounts (IndexType *const buf) const
 
DEVICE RealType quantile (VectorView< IndexType const > const partial_sum, RealType const q) const
 
DEVICE RealType quantile (RealType const q) const
 
DEVICE RealType quantile ()
 
DEVICE void setBuffer (Memory &mem)
 
DEVICE void setCentroids (Memory &mem)
 
DEVICE void setCentroids (VectorView< RealType > const sums, VectorView< IndexType > const counts)
 
DEVICE IndexType totalWeight () const
 

Static Public Member Functions

static IndexType nbytes (IndexType buf_allocate, IndexType centroids_allocate)
 

Private Member Functions

DEVICE RealType max () const
 
DEVICE RealType min () const
 
DEVICE IndexType maxCardinality (IndexType const sum, IndexType const total_weight, RealType const c)
 
DEVICE void mergeCentroids (Centroids< RealType, IndexType > &)
 
DEVICE RealType firstCentroid (RealType const x) const
 
DEVICE RealType interiorCentroid (RealType const x, IndexType const idx1, IndexType const prefix_sum) const
 
DEVICE RealType lastCentroid (RealType const x, IndexType const N) const
 
DEVICE RealType oneCentroid (RealType const x) const
 
DEVICE RealType slope (IndexType const idx1, IndexType const idx2) const
 

Private Attributes

Centroids< RealType, IndexType > buf_
 
Centroids< RealType, IndexType > centroids_
 
bool forward_ {true}
 
std::mutex merge_buffer_final_called_mutex_
 
bool merge_buffer_final_called_ {false}
 
std::optional< RealType > q_ {std::nullopt}
 
bool use_linear_scaling_function_ {false}
 
SimpleAllocatorsimple_allocator_ {nullptr}
 
IndexType buf_allocate_ {0}
 
IndexType centroids_allocate_ {0}
 

Detailed Description

template<typename RealType, typename IndexType = size_t>
class quantile::detail::TDigest< RealType, IndexType >

Definition at line 184 of file quantile.h.

Member Typedef Documentation

template<typename RealType , typename IndexType = size_t>
using quantile::detail::TDigest< RealType, IndexType >::Memory = CentroidsMemory<RealType, IndexType>

Definition at line 227 of file quantile.h.

Constructor & Destructor Documentation

template<typename RealType , typename IndexType = size_t>
quantile::detail::TDigest< RealType, IndexType >::TDigest ( )
default
template<typename RealType , typename IndexType = size_t>
DEVICE quantile::detail::TDigest< RealType, IndexType >::TDigest ( Memory mem)
inline

Definition at line 231 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

232  : centroids_(mem.sums().data(), mem.counts().data(), mem.size()) {
233  centroids_.clear();
234  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType = size_t>
DEVICE quantile::detail::TDigest< RealType, IndexType >::TDigest ( RealType  q,
SimpleAllocator simple_allocator,
IndexType  buf_allocate,
IndexType  centroids_allocate 
)
inline

Definition at line 236 of file quantile.h.

240  : q_(q)
241  , use_linear_scaling_function_(q_ && 0.1 <= *q_ && *q_ <= 0.9)
242  , simple_allocator_(simple_allocator)
243  , buf_allocate_(buf_allocate)
244  , centroids_allocate_(centroids_allocate) {}
SimpleAllocator * simple_allocator_
Definition: quantile.h:199
std::optional< RealType > q_
Definition: quantile.h:197
IndexType centroids_allocate_
Definition: quantile.h:201

Member Function Documentation

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::add ( RealType  value)

Definition at line 623 of file quantile.h.

623  {
624  if (buf_.sums_.full()) {
625  mergeBuffer();
626  }
627  buf_.sums_.push_back(value);
628  buf_.counts_.push_back(1);
629 }
DEVICE void mergeBuffer()
Definition: quantile.h:672
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::allocate ( )

Definition at line 633 of file quantile.h.

Referenced by agg_approx_quantile().

633  {
634  if (buf_.capacity() == 0) {
635  auto* p0 = simple_allocator_->allocate(buf_allocate_ * sizeof(RealType));
636  auto* p1 = simple_allocator_->allocate(buf_allocate_ * sizeof(IndexType));
637  buf_ = Centroids<RealType, IndexType>(
638  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, buf_allocate_),
639  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, buf_allocate_));
640  p0 = simple_allocator_->allocate(centroids_allocate_ * sizeof(RealType));
641  p1 = simple_allocator_->allocate(centroids_allocate_ * sizeof(IndexType));
642  centroids_ = Centroids<RealType, IndexType>(
643  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, centroids_allocate_),
644  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, centroids_allocate_));
645  }
646 }
SimpleAllocator * simple_allocator_
Definition: quantile.h:199
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
virtual int8_t * allocate(const size_t num_bytes)=0
IndexType centroids_allocate_
Definition: quantile.h:201
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE Centroids<RealType, IndexType>& quantile::detail::TDigest< RealType, IndexType >::centroids ( )
inline

Definition at line 265 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

265  {
266  return centroids_;
267  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::firstCentroid ( RealType const  x) const
private

Definition at line 749 of file quantile.h.

749  {
750  if (x < 1) {
751  return min();
752  } else if (centroids_.size() == 1) {
753  return oneCentroid(x);
754  } else if (centroids_.counts_.front() == 2) {
755  RealType const sum = centroids_.sums_.front();
756  return x == 1 ? 0.5 * sum : sum - min();
757  } else {
758  RealType const count = centroids_.counts_.front();
759  RealType const dx = x - RealType(0.5) * (1 + count);
760  RealType const mean = (centroids_.sums_.front() - min()) / (count - 1);
761  return mean + slope(0, 0 < dx) * dx;
762  }
763 }
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:883
DEVICE RealType oneCentroid(RealType const x) const
Definition: quantile.h:827
DEVICE RealType min() const
Definition: quantile.h:206
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::interiorCentroid ( RealType const  x,
IndexType const  idx1,
IndexType const  prefix_sum 
) const
private

Definition at line 768 of file quantile.h.

References quantile::detail::anonymous_namespace{quantile.h}::isSingleton().

770  {
771  if (isSingleton(centroids_.counts_.begin() + idx1)) {
772  RealType const sum1 = centroids_.sums_[idx1];
773  if (x == prefix_sum - centroids_.counts_[idx1]) {
774  if (isSingleton(centroids_.counts_.begin() + idx1 - 1)) {
775  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
776  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
777  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
778  }
779  }
780  return sum1;
781  } else {
782  RealType const dx = x + RealType(0.5) * centroids_.counts_[idx1] - prefix_sum;
783  IndexType const idx2 = idx1 + 2 * (0 < dx) - 1;
784  return centroids_.mean(idx1) + slope(idx1, idx2) * dx;
785  }
786 }
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:883
DEVICE RealType min() const
Definition: quantile.h:206
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:742
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::lastCentroid ( RealType const  x,
IndexType const  N 
) const
private

Definition at line 790 of file quantile.h.

References quantile::detail::anonymous_namespace{quantile.h}::isSingleton().

791  {
792  if (N - 1 < x) {
793  return max();
794  }
795  IndexType const idx1 = centroids_.size() - 1;
796  RealType const sum1 = centroids_.sums_[idx1];
797  IndexType const count1 = centroids_.counts_[idx1];
798  if (count1 == 1) { // => x == N - 1
799  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
800  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
801  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
802  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
803  } else {
804  return sum1;
805  }
806  } else if (count1 == 2) { // => 3 <= N
807  if (x == N - 1) {
808  return 0.5 * sum1;
809  } else if (x == N - 2) {
810  RealType const sum2 = centroids_.sums_[idx1 - 1];
811  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
812  return 0.5 * (sum2 + sum1 - max());
813  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
814  return 0.5 * (sum2 - min() + sum1 - max());
815  }
816  }
817  return sum1 - max();
818  } else { // => 3 <= count1
819  RealType const dx = x + RealType(0.5) * (count1 + 1) - N;
820  RealType const mean = (sum1 - max()) / (count1 - 1);
821  return mean + slope(idx1, idx1 - (dx < 0)) * dx;
822  }
823 }
DEVICE RealType max() const
Definition: quantile.h:203
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:883
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:206
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:742
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::max ( ) const
inlineprivate

Definition at line 203 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

203  {
204  return centroids_.max_;
205  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE IndexType quantile::detail::TDigest< RealType, IndexType >::maxCardinality ( IndexType const  sum,
IndexType const  total_weight,
RealType const  c 
)
private

Definition at line 651 of file quantile.h.

653  {
654  IndexType const max_bins = centroids_.capacity(); // "compression parameter" delta
655  if (total_weight <= max_bins) {
656  return 0;
657  } else if (use_linear_scaling_function_) {
658  // Whitepaper scaling function k=0.
659  return 2 * total_weight / max_bins;
660  } else {
661  // Whitepaper scaling function k=1.
662  RealType const x = 2.0 * sum / total_weight - 1; // = 2 q_{i-1} - 1
663  RealType const f_inv = 0.5 + 0.5 * std::sin(c + std::asin(x));
664  constexpr RealType eps = 1e-5; // round-off epsilon for floor().
665  IndexType const dsum = static_cast<IndexType>(total_weight * f_inv + eps);
666  return dsum < sum ? 0 : dsum - sum;
667  }
668 }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeBuffer ( )

Definition at line 672 of file quantile.h.

References gpu_enabled::sort().

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

672  {
673  if (buf_.size()) {
674  gpu_enabled::sort(buf_.sums_.begin(), buf_.sums_.end());
675  buf_.min_ = buf_.sums_.front();
676  buf_.max_ = buf_.sums_.back();
678  }
679 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:719

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeBufferFinal ( )

Definition at line 683 of file quantile.h.

Referenced by ResultSet::calculateQuantile().

683  {
684 #ifndef __CUDACC__
685  std::lock_guard<std::mutex> lock_guard(merge_buffer_final_called_mutex_);
686 #endif
688  mergeBuffer();
689  assert(centroids_.size() <= buf_.capacity());
690  partialSumOfCounts(buf_.counts_.data());
692  }
693 }
std::lock_guard< T > lock_guard
DEVICE VectorView< IndexType const > partialSumOfCounts(IndexType *const buf) const
Definition: quantile.h:850
DEVICE void mergeBuffer()
Definition: quantile.h:672
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
std::mutex merge_buffer_final_called_mutex_
Definition: quantile.h:192
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeCentroids ( Centroids< RealType, IndexType > &  buf)
private

Definition at line 719 of file quantile.h.

References quantile::detail::Centroids< RealType, IndexType >::clear(), and quantile::detail::CentroidsMerger< RealType, IndexType >::merge().

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

720  {
721  constexpr RealType two_pi = 6.283185307179586476925286766559005768e+00;
722  // Hoisted constant used in maxCardinality().
723  RealType const c = two_pi / centroids_.capacity();
724  // Loop over sorted sequence of buf and centroids_.
725  // Some latter centroids may be merged into the current centroid, so the number
726  // of iterations is only at most equal to the number of initial centroids.
727  using CM = CentroidsMerger<RealType, IndexType>;
728  for (CM cm(&buf, &centroids_, forward_); cm.hasNext(); cm.next()) {
729  // cm.prefixSum() == 0 on first iteration.
730  // Max cardinality for current centroid to be fully merged based on scaling function.
731  IndexType const max_cardinality = maxCardinality(cm.prefixSum(), cm.totalWeight(), c);
732  cm.merge(max_cardinality);
733  }
734  // Combine sorted centroids buf[0..curr_idx_] + centroids_[0..curr_idx_] if forward
735  centroids_.appendAndSortCurrent(buf);
736  buf.clear();
737  forward_ ^= true; // alternate merge direction on each call
738 }
DEVICE IndexType maxCardinality(IndexType const sum, IndexType const total_weight, RealType const c)
Definition: quantile.h:651
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeSorted ( RealType *  sums,
IndexType *  counts,
IndexType  size 
)

Definition at line 696 of file quantile.h.

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

698  {
699  if (size) {
700  if (buf_.capacity() == 0) {
701  buf_ = Centroids<RealType, IndexType>(sums, counts, size); // Set capacity and size
702  } else {
703  buf_.sums_.set(sums, size); // Does not change capacity
704  buf_.counts_.set(counts, size);
705  }
706  gpu_enabled::fill(buf_.counts_.begin(), buf_.counts_.end(), IndexType(1));
707  buf_.min_ = buf_.sums_.front();
708  buf_.max_ = buf_.sums_.back();
710  }
711 }
DEVICE void fill(ARGS &&...args)
Definition: gpu_enabled.h:60
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:719

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeTDigest ( TDigest< RealType, IndexType > &  t_digest)
inline

Definition at line 283 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_, quantile::detail::TDigest< RealType, IndexType >::mergeBuffer(), and quantile::detail::TDigest< RealType, IndexType >::mergeCentroids().

283  {
284  mergeBuffer();
285  t_digest.mergeBuffer();
286  mergeCentroids(t_digest.centroids_);
287  }
DEVICE void mergeBuffer()
Definition: quantile.h:672
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:719

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::min ( ) const
inlineprivate

Definition at line 206 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

206  {
207  return centroids_.min_;
208  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType = size_t>
static IndexType quantile::detail::TDigest< RealType, IndexType >::nbytes ( IndexType  buf_allocate,
IndexType  centroids_allocate 
)
inlinestatic

Definition at line 261 of file quantile.h.

Referenced by anonymous_namespace{QueryMemoryInitializer.cpp}::AddNbytes::operator()().

261  {
262  return (buf_allocate + centroids_allocate) * (sizeof(RealType) + sizeof(IndexType));
263  }

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::oneCentroid ( RealType const  x) const
private

Definition at line 827 of file quantile.h.

References anonymous_namespace{Utm.h}::N.

827  {
828  IndexType const N = centroids_.counts_.front();
829  if (N - 1 < x) { // includes case N == 1
830  return max();
831  } else if (N == 2) { // x == 1
832  return 0.5 * centroids_.sums_.front();
833  } else if (N == 3) { // 1 <= x <= 2
834  if (x == 2) {
835  return 0.5 * (centroids_.sums_.front() - min());
836  } else {
837  RealType const s = centroids_.sums_.front() - max();
838  return x == 1 ? 0.5 * s : s - min();
839  }
840  } else { // 3 < N
841  RealType const dx = x - RealType(0.5) * N;
842  RealType const mean = (centroids_.sums_.front() - (min() + max())) / (N - 2);
843  RealType const slope = 2 * (0 < dx ? max() - mean : mean - min()) / (N - 2);
844  return mean + slope * dx;
845  }
846 }
DEVICE RealType max() const
Definition: quantile.h:203
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:883
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:206
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType = size_t>
TDigest& quantile::detail::TDigest< RealType, IndexType >::operator= ( TDigest< RealType, IndexType > &&  rhs)
inline

Definition at line 247 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::buf_, quantile::detail::TDigest< RealType, IndexType >::buf_allocate_, quantile::detail::TDigest< RealType, IndexType >::centroids_, quantile::detail::TDigest< RealType, IndexType >::centroids_allocate_, quantile::detail::TDigest< RealType, IndexType >::forward_, quantile::detail::TDigest< RealType, IndexType >::merge_buffer_final_called_, quantile::detail::TDigest< RealType, IndexType >::q_, quantile::detail::TDigest< RealType, IndexType >::simple_allocator_, and quantile::detail::TDigest< RealType, IndexType >::use_linear_scaling_function_.

247  {
248  buf_ = std::move(rhs.buf_);
249  centroids_ = std::move(rhs.centroids_);
250  forward_ = std::move(rhs.forward_);
251  merge_buffer_final_called_ = std::move(rhs.merge_buffer_final_called_);
252  q_ = std::move(rhs.q_);
253  use_linear_scaling_function_ = std::move(rhs.use_linear_scaling_function_);
254  simple_allocator_ = std::move(rhs.simple_allocator_);
255  buf_allocate_ = std::move(rhs.buf_allocate_);
256  centroids_allocate_ = std::move(rhs.centroids_allocate_);
257  return *this;
258  }
SimpleAllocator * simple_allocator_
Definition: quantile.h:199
std::optional< RealType > q_
Definition: quantile.h:197
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
IndexType centroids_allocate_
Definition: quantile.h:201
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE VectorView< IndexType const > quantile::detail::TDigest< RealType, IndexType >::partialSumOfCounts ( IndexType *const  buf) const

Definition at line 850 of file quantile.h.

References gpu_enabled::partial_sum().

851  {
852  gpu_enabled::partial_sum(centroids_.counts_.begin(), centroids_.counts_.end(), buf);
853  return {buf, centroids_.size()};
854 }
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::quantile ( VectorView< IndexType const > const  partial_sum,
RealType const  q 
) const

Definition at line 858 of file quantile.h.

References VectorView< T >::back(), VectorView< T >::begin(), VectorView< T >::end(), anonymous_namespace{Utm.h}::N, and gpu_enabled::upper_bound().

Referenced by ResultSet::calculateQuantile().

859  {
860  if (centroids_.size()) {
861  IndexType const N = partial_sum.back();
862  RealType const x = q * N;
863  auto const it1 = gpu_enabled::upper_bound(partial_sum.begin(), partial_sum.end(), x);
864  if (it1 == partial_sum.begin()) {
865  return firstCentroid(x);
866  } else if (it1 == partial_sum.end()) { // <==> 1 <= q
867  return max();
868  } else if (it1 + 1 == partial_sum.end()) {
869  return lastCentroid(x, N);
870  } else {
871  return interiorCentroid(x, it1 - partial_sum.begin(), *it1);
872  }
873  } else {
874  return centroids_.nan;
875  }
876 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
DEVICE RealType max() const
Definition: quantile.h:203
DEVICE T * begin() const
Definition: VectorView.h:59
DEVICE RealType lastCentroid(RealType const x, IndexType const N) const
Definition: quantile.h:790
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType interiorCentroid(RealType const x, IndexType const idx1, IndexType const prefix_sum) const
Definition: quantile.h:768
DEVICE T & back()
Definition: VectorView.h:57
DEVICE RealType firstCentroid(RealType const x) const
Definition: quantile.h:749
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
DEVICE T * end() const
Definition: VectorView.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::quantile ( RealType const  q) const
inline

Definition at line 296 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::buf_, quantile::detail::TDigest< RealType, IndexType >::centroids_, and quantile::detail::TDigest< RealType, IndexType >::quantile().

296  {
297  return quantile({buf_.counts_.data(), centroids_.size()}, q);
298  }
DEVICE RealType quantile()
Definition: quantile.h:300
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::quantile ( )
inline

Definition at line 300 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_, and quantile::detail::TDigest< RealType, IndexType >::q_.

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

300  {
301  return q_ ? quantile(*q_) : centroids_.nan;
302  }
DEVICE RealType quantile()
Definition: quantile.h:300
std::optional< RealType > q_
Definition: quantile.h:197
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the caller graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE void quantile::detail::TDigest< RealType, IndexType >::setBuffer ( Memory mem)
inline

Definition at line 305 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::buf_, quantile::detail::CentroidsMemory< RealType, IndexType >::counts(), VectorView< T >::data(), quantile::detail::CentroidsMemory< RealType, IndexType >::size(), and quantile::detail::CentroidsMemory< RealType, IndexType >::sums().

305  {
306  buf_ = Centroids<RealType, IndexType>(
307  mem.sums().data(), mem.counts().data(), mem.size());
308  buf_.clear();
309  }
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE void quantile::detail::TDigest< RealType, IndexType >::setCentroids ( Memory mem)
inline

Definition at line 312 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_, quantile::detail::CentroidsMemory< RealType, IndexType >::counts(), VectorView< T >::data(), quantile::detail::CentroidsMemory< RealType, IndexType >::size(), and quantile::detail::CentroidsMemory< RealType, IndexType >::sums().

312  {
313  centroids_ = Centroids<RealType, IndexType>(
314  mem.sums().data(), mem.counts().data(), mem.size());
315  centroids_.clear();
316  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

template<typename RealType , typename IndexType = size_t>
DEVICE void quantile::detail::TDigest< RealType, IndexType >::setCentroids ( VectorView< RealType > const  sums,
VectorView< IndexType > const  counts 
)
inline

Definition at line 318 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

319  {
320  centroids_ = Centroids<RealType, IndexType>(sums, counts);
321  centroids_.clear();
322  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::slope ( IndexType const  idx1,
IndexType const  idx2 
) const
private

Definition at line 883 of file quantile.h.

References quantile::detail::anonymous_namespace{quantile.h}::isSingleton(), and anonymous_namespace{Utm.h}::n.

884  {
885  IndexType const M = centroids_.size();
886  if (idx1 == idx2) { // Line segment is contained in either the first or last centroid.
887  RealType const n = static_cast<RealType>(centroids_.counts_[idx1]);
888  RealType const s = centroids_.sums_[idx1];
889  return idx1 == 0 ? 2 * (s - n * min()) / ((n - 1) * (n - 1))
890  : 2 * (n * max() - s) / ((n - 1) * (n - 1));
891  } else {
892  bool const min1 = idx1 == 0; // idx1 is the min centroid
893  bool const max1 = idx1 == M - 1; // idx1 is the max centroid
894  bool const min2 = idx2 == 0; // idx2 is the min centroid
895  bool const max2 = idx2 == M - 1; // idx2 is the max centroid
896  RealType const n1 = static_cast<RealType>(centroids_.counts_[idx1] - min1 - max1);
897  RealType const s1 = centroids_.sums_[idx1] - (min1 ? min() : max1 ? max() : 0);
898  RealType const s2 = centroids_.sums_[idx2] - (min2 ? min() : max2 ? max() : 0);
899  if (isSingleton(centroids_.counts_.begin() + idx2)) {
900  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - s1) / (n1 * n1);
901  } else {
902  RealType const n2 = static_cast<RealType>(centroids_.counts_[idx2] - min2 - max2);
903  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - n2 * s1) / (n1 * n2 * (n1 + n2));
904  }
905  }
906 }
DEVICE RealType max() const
Definition: quantile.h:203
constexpr double n
Definition: Utm.h:38
DEVICE RealType min() const
Definition: quantile.h:206
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:742
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

+ Here is the call graph for this function:

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

Definition at line 325 of file quantile.h.

References quantile::detail::TDigest< RealType, IndexType >::centroids_.

325  {
326  return centroids_.totalWeight();
327  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189

Member Data Documentation

template<typename RealType , typename IndexType = size_t>
Centroids<RealType, IndexType> quantile::detail::TDigest< RealType, IndexType >::buf_
private
template<typename RealType , typename IndexType = size_t>
IndexType quantile::detail::TDigest< RealType, IndexType >::buf_allocate_ {0}
private
template<typename RealType , typename IndexType = size_t>
IndexType quantile::detail::TDigest< RealType, IndexType >::centroids_allocate_ {0}
private
template<typename RealType , typename IndexType = size_t>
bool quantile::detail::TDigest< RealType, IndexType >::forward_ {true}
private
template<typename RealType , typename IndexType = size_t>
bool quantile::detail::TDigest< RealType, IndexType >::merge_buffer_final_called_ {false}
private
template<typename RealType , typename IndexType = size_t>
std::mutex quantile::detail::TDigest< RealType, IndexType >::merge_buffer_final_called_mutex_
private

Definition at line 192 of file quantile.h.

template<typename RealType , typename IndexType = size_t>
std::optional<RealType> quantile::detail::TDigest< RealType, IndexType >::q_ {std::nullopt}
private
template<typename RealType , typename IndexType = size_t>
SimpleAllocator* quantile::detail::TDigest< RealType, IndexType >::simple_allocator_ {nullptr}
private
template<typename RealType , typename IndexType = size_t>
bool quantile::detail::TDigest< RealType, IndexType >::use_linear_scaling_function_ {false}
private

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