OmniSciDB  16c4e035a1
 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)
 
DEVICE Centroids< RealType,
IndexType > & 
centroids ()
 
DEVICE void add (RealType value)
 
DEVICE void allocate ()
 
DEVICE void mergeBuffer ()
 
DEVICE void mergeSorted (RealType *sums, IndexType *counts, IndexType size)
 
DEVICE void mergeTDigest (TDigest &t_digest)
 
DEVICE RealType quantile (IndexType *buf, RealType const q)
 
DEVICE RealType quantile (RealType const q)
 
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
 

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)
 
DEVICE RealType interiorCentroid (RealType const x, IndexType const idx1, IndexType const prefix_sum)
 
DEVICE RealType lastCentroid (RealType const x, IndexType const N)
 
DEVICE RealType oneCentroid (RealType const x)
 
DEVICE RealType slope (IndexType const idx1, IndexType const idx2)
 

Private Attributes

Centroids< RealType, IndexType > buf_
 
Centroids< RealType, IndexType > centroids_
 
bool forward_ {true}
 
std::optional< RealType > const q_ {std::nullopt}
 
bool const use_linear_scaling_function_ {false}
 
SimpleAllocator *const simple_allocator_ {nullptr}
 
IndexType const buf_allocate_ {0}
 
IndexType const 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 216 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 220 of file quantile.h.

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

221  : centroids_(mem.sums().data(), mem.counts().data(), mem.size()) {
222  centroids_.clear();
223  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
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 225 of file quantile.h.

229  : q_(q)
230  , use_linear_scaling_function_(q_ && 0.1 <= *q_ && *q_ <= 0.9)
231  , simple_allocator_(simple_allocator)
232  , buf_allocate_(buf_allocate)
233  , centroids_allocate_(centroids_allocate) {}
bool const use_linear_scaling_function_
Definition: quantile.h:191
IndexType const buf_allocate_
Definition: quantile.h:193
std::optional< RealType > const q_
Definition: quantile.h:190
SimpleAllocator *const simple_allocator_
Definition: quantile.h:192
IndexType const centroids_allocate_
Definition: quantile.h:194

Member Function Documentation

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

Definition at line 580 of file quantile.h.

580  {
581  if (buf_.sums_.full()) {
582  mergeBuffer();
583  }
584  buf_.sums_.push_back(value);
585  buf_.counts_.push_back(1);
586 }
DEVICE void mergeBuffer()
Definition: quantile.h:629
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::allocate ( )

Definition at line 590 of file quantile.h.

Referenced by agg_approx_quantile(), and approx_quantile_jit_rt().

590  {
591  if (buf_.capacity() == 0) {
592  auto* p0 = simple_allocator_->allocate(buf_allocate_ * sizeof(RealType));
593  auto* p1 = simple_allocator_->allocate(buf_allocate_ * sizeof(IndexType));
594  buf_ = Centroids<RealType, IndexType>(
595  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, buf_allocate_),
596  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, buf_allocate_));
597  p0 = simple_allocator_->allocate(centroids_allocate_ * sizeof(RealType));
598  p1 = simple_allocator_->allocate(centroids_allocate_ * sizeof(IndexType));
599  centroids_ = Centroids<RealType, IndexType>(
600  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, centroids_allocate_),
601  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, centroids_allocate_));
602  }
603 }
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185
IndexType const buf_allocate_
Definition: quantile.h:193
virtual int8_t * allocate(const size_t num_bytes, const size_t thread_idx=0)=0
SimpleAllocator *const simple_allocator_
Definition: quantile.h:192
IndexType const centroids_allocate_
Definition: quantile.h:194
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

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

Definition at line 692 of file quantile.h.

References count.

692  {
693  if (x < 1) {
694  return min();
695  } else if (centroids_.size() == 1) {
696  return oneCentroid(x);
697  } else if (centroids_.counts_.front() == 2) {
698  RealType const sum = centroids_.sums_.front();
699  return x == 1 ? 0.5 * sum : sum - min();
700  } else {
701  RealType const count = centroids_.counts_.front();
702  RealType const dx = x - RealType(0.5) * (1 + count);
703  RealType const mean = (centroids_.sums_.front() - min()) / (count - 1);
704  return mean + slope(0, 0 < dx) * dx;
705  }
706 }
DEVICE RealType oneCentroid(RealType const x)
Definition: quantile.h:770
int count
DEVICE RealType slope(IndexType const idx1, IndexType const idx2)
Definition: quantile.h:820
DEVICE RealType min() const
Definition: quantile.h:197
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::interiorCentroid ( RealType const  x,
IndexType const  idx1,
IndexType const  prefix_sum 
)
private

Definition at line 711 of file quantile.h.

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

713  {
714  if (isSingleton(centroids_.counts_.begin() + idx1)) {
715  RealType const sum1 = centroids_.sums_[idx1];
716  if (x == prefix_sum - centroids_.counts_[idx1]) {
717  if (isSingleton(centroids_.counts_.begin() + idx1 - 1)) {
718  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
719  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
720  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
721  }
722  }
723  return sum1;
724  } else {
725  RealType const dx = x + RealType(0.5) * centroids_.counts_[idx1] - prefix_sum;
726  IndexType const idx2 = idx1 + 2 * (0 < dx) - 1;
727  return centroids_.mean(idx1) + slope(idx1, idx2) * dx;
728  }
729 }
DEVICE RealType slope(IndexType const idx1, IndexType const idx2)
Definition: quantile.h:820
DEVICE RealType min() const
Definition: quantile.h:197
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:685
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

+ 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 
)
private

Definition at line 733 of file quantile.h.

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

734  {
735  if (N - 1 < x) {
736  return max();
737  }
738  IndexType const idx1 = centroids_.size() - 1;
739  RealType const sum1 = centroids_.sums_[idx1];
740  IndexType const count1 = centroids_.counts_[idx1];
741  if (count1 == 1) { // => x == N - 1
742  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
743  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
744  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
745  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
746  } else {
747  return sum1;
748  }
749  } else if (count1 == 2) { // => 3 <= N
750  if (x == N - 1) {
751  return 0.5 * sum1;
752  } else if (x == N - 2) {
753  RealType const sum2 = centroids_.sums_[idx1 - 1];
754  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
755  return 0.5 * (sum2 + sum1 - max());
756  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
757  return 0.5 * (sum2 - min() + sum1 - max());
758  }
759  }
760  return sum1 - max();
761  } else { // => 3 <= count1
762  RealType const dx = x + RealType(0.5) * (count1 + 1) - N;
763  RealType const mean = (sum1 - max()) / (count1 - 1);
764  return mean + slope(idx1, idx1 - (dx < 0)) * dx;
765  }
766 }
DEVICE RealType max() const
Definition: quantile.h:196
DEVICE RealType slope(IndexType const idx1, IndexType const idx2)
Definition: quantile.h:820
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:197
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:685
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

196 { return centroids_.max_; }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
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 608 of file quantile.h.

610  {
611  IndexType const max_bins = centroids_.capacity(); // "compression parameter" delta
612  if (total_weight <= max_bins) {
613  return 0;
614  } else if (use_linear_scaling_function_) {
615  // Whitepaper scaling function k=0.
616  return 2 * total_weight / max_bins;
617  } else {
618  // Whitepaper scaling function k=1.
619  RealType const x = 2.0 * sum / total_weight - 1; // = 2 q_{i-1} - 1
620  RealType const f_inv = 0.5 + 0.5 * std::sin(c + std::asin(x));
621  constexpr RealType eps = 1e-5; // round-off epsilon for floor().
622  IndexType const dsum = static_cast<IndexType>(total_weight * f_inv + eps);
623  return dsum < sum ? 0 : dsum - sum;
624  }
625 }
bool const use_linear_scaling_function_
Definition: quantile.h:191
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeBuffer ( )

Definition at line 629 of file quantile.h.

References gpu_enabled::sort().

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

629  {
630  if (buf_.size()) {
631  gpu_enabled::sort(buf_.sums_.begin(), buf_.sums_.end());
632  buf_.min_ = buf_.sums_.front();
633  buf_.max_ = buf_.sums_.back();
635  }
636 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:662

+ 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 >::mergeCentroids ( Centroids< RealType, IndexType > &  buf)
private

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

663  {
664  constexpr RealType two_pi = 6.283185307179586476925286766559005768e+00;
665  // Hoisted constant used in maxCardinality().
666  RealType const c = two_pi / centroids_.capacity();
667  // Loop over sorted sequence of buf and centroids_.
668  // Some latter centroids may be merged into the current centroid, so the number
669  // of iterations is only at most equal to the number of initial centroids.
670  using CM = CentroidsMerger<RealType, IndexType>;
671  for (CM cm(&buf, &centroids_, forward_); cm.hasNext(); cm.next()) {
672  // cm.prefixSum() == 0 on first iteration.
673  // Max cardinality for current centroid to be fully merged based on scaling function.
674  IndexType const max_cardinality = maxCardinality(cm.prefixSum(), cm.totalWeight(), c);
675  cm.merge(max_cardinality);
676  }
677  // Combine sorted centroids buf[0..curr_idx_] + centroids_[0..curr_idx_] if forward
678  centroids_.appendAndSortCurrent(buf);
679  buf.clear();
680  forward_ ^= true; // alternate merge direction on each call
681 }
DEVICE IndexType maxCardinality(IndexType const sum, IndexType const total_weight, RealType const c)
Definition: quantile.h:608
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

641  {
642  if (size) {
643  if (buf_.capacity() == 0) {
644  buf_ = Centroids<RealType, IndexType>(sums, counts, size); // Set capacity and size
645  } else {
646  buf_.sums_.set(sums, size); // Does not change capacity
647  buf_.counts_.set(counts, size);
648  }
649  gpu_enabled::fill(buf_.counts_.begin(), buf_.counts_.end(), IndexType(1));
650  buf_.min_ = buf_.sums_.front();
651  buf_.max_ = buf_.sums_.back();
653  }
654 }
DEVICE void fill(ARGS &&...args)
Definition: gpu_enabled.h:60
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:662

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

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

248  {
249  mergeBuffer();
250  t_digest.mergeBuffer();
251  mergeCentroids(t_digest.centroids_);
252  }
DEVICE void mergeBuffer()
Definition: quantile.h:629
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:662

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

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

197 { return centroids_.min_; }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::oneCentroid ( RealType const  x)
private

Definition at line 770 of file quantile.h.

References anonymous_namespace{Utm.h}::N.

770  {
771  IndexType const N = centroids_.counts_.front();
772  if (N - 1 < x) { // includes case N == 1
773  return max();
774  } else if (N == 2) { // x == 1
775  return 0.5 * centroids_.sums_.front();
776  } else if (N == 3) { // 1 <= x <= 2
777  if (x == 2) {
778  return 0.5 * (centroids_.sums_.front() - min());
779  } else {
780  RealType const s = centroids_.sums_.front() - max();
781  return x == 1 ? 0.5 * s : s - min();
782  }
783  } else { // 3 < N
784  RealType const dx = x - RealType(0.5) * N;
785  RealType const mean = (centroids_.sums_.front() - (min() + max())) / (N - 2);
786  RealType const slope = 2 * (0 < dx ? max() - mean : mean - min()) / (N - 2);
787  return mean + slope * dx;
788  }
789 }
DEVICE RealType max() const
Definition: quantile.h:196
DEVICE RealType slope(IndexType const idx1, IndexType const idx2)
Definition: quantile.h:820
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:197
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::quantile ( IndexType *  buf,
RealType const  q 
)

Definition at line 793 of file quantile.h.

References anonymous_namespace{Utm.h}::N, gpu_enabled::partial_sum(), and gpu_enabled::upper_bound().

Referenced by ResultSet::calculateQuantile().

793  {
794  if (centroids_.size()) {
797  centroids_.counts_.begin(), centroids_.counts_.end(), partial_sum.begin());
798  IndexType const N = partial_sum.back();
799  RealType const x = q * N;
800  auto const it1 = gpu_enabled::upper_bound(partial_sum.begin(), partial_sum.end(), x);
801  if (it1 == partial_sum.begin()) {
802  return firstCentroid(x);
803  } else if (it1 == partial_sum.end()) { // <==> 1 <= q
804  return max();
805  } else if (it1 + 1 == partial_sum.end()) {
806  return lastCentroid(x, N);
807  } else {
808  return interiorCentroid(x, it1 - partial_sum.begin(), *it1);
809  }
810  } else {
811  return centroids_.nan;
812  }
813 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
DEVICE RealType lastCentroid(RealType const x, IndexType const N)
Definition: quantile.h:733
DEVICE RealType firstCentroid(RealType const x)
Definition: quantile.h:692
DEVICE RealType max() const
Definition: quantile.h:196
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
DEVICE RealType interiorCentroid(RealType const x, IndexType const idx1, IndexType const prefix_sum)
Definition: quantile.h:711
constexpr unsigned N
Definition: Utm.h:110
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

+ 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)
inline

Definition at line 258 of file quantile.h.

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

258  {
259  assert(centroids_.size() <= buf_.capacity());
260  return quantile(buf_.counts_.data(), q);
261  }
DEVICE RealType quantile()
Definition: quantile.h:263
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

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

263 { return q_ ? quantile(*q_) : centroids_.nan; }
DEVICE RealType quantile()
Definition: quantile.h:263
std::optional< RealType > const q_
Definition: quantile.h:190
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

+ Here is the call graph for this function:

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

266  {
267  buf_ = Centroids<RealType, IndexType>(
268  mem.sums().data(), mem.counts().data(), mem.size());
269  buf_.clear();
270  }
Centroids< RealType, IndexType > buf_
Definition: quantile.h:185

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

273  {
274  centroids_ = Centroids<RealType, IndexType>(
275  mem.sums().data(), mem.counts().data(), mem.size());
276  centroids_.clear();
277  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

280  {
281  centroids_ = Centroids<RealType, IndexType>(sums, counts);
282  centroids_.clear();
283  }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186
template<typename RealType , typename IndexType >
DEVICE RealType quantile::detail::TDigest< RealType, IndexType >::slope ( IndexType const  idx1,
IndexType const  idx2 
)
private

Definition at line 820 of file quantile.h.

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

820  {
821  IndexType const M = centroids_.size();
822  if (idx1 == idx2) { // Line segment is contained in either the first or last centroid.
823  RealType const n = static_cast<RealType>(centroids_.counts_[idx1]);
824  RealType const s = centroids_.sums_[idx1];
825  return idx1 == 0 ? 2 * (s - n * min()) / ((n - 1) * (n - 1))
826  : 2 * (n * max() - s) / ((n - 1) * (n - 1));
827  } else {
828  bool const min1 = idx1 == 0; // idx1 is the min centroid
829  bool const max1 = idx1 == M - 1; // idx1 is the max centroid
830  bool const min2 = idx2 == 0; // idx2 is the min centroid
831  bool const max2 = idx2 == M - 1; // idx2 is the max centroid
832  RealType const n1 = static_cast<RealType>(centroids_.counts_[idx1] - min1 - max1);
833  RealType const s1 = centroids_.sums_[idx1] - (min1 ? min() : max1 ? max() : 0);
834  RealType const s2 = centroids_.sums_[idx2] - (min2 ? min() : max2 ? max() : 0);
835  if (isSingleton(centroids_.counts_.begin() + idx2)) {
836  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - s1) / (n1 * n1);
837  } else {
838  RealType const n2 = static_cast<RealType>(centroids_.counts_[idx2] - min2 - max2);
839  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - n2 * s1) / (n1 * n2 * (n1 + n2));
840  }
841  }
842 }
DEVICE RealType max() const
Definition: quantile.h:196
constexpr double n
Definition: Utm.h:38
DEVICE RealType min() const
Definition: quantile.h:197
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:685
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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

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

286 { return centroids_.totalWeight(); }
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:186

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 const quantile::detail::TDigest< RealType, IndexType >::buf_allocate_ {0}
private

Definition at line 193 of file quantile.h.

template<typename RealType , typename IndexType = size_t>
IndexType const quantile::detail::TDigest< RealType, IndexType >::centroids_allocate_ {0}
private

Definition at line 194 of file quantile.h.

template<typename RealType , typename IndexType = size_t>
bool quantile::detail::TDigest< RealType, IndexType >::forward_ {true}
private

Definition at line 187 of file quantile.h.

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

Definition at line 192 of file quantile.h.

template<typename RealType , typename IndexType = size_t>
bool const quantile::detail::TDigest< RealType, IndexType >::use_linear_scaling_function_ {false}
private

Definition at line 191 of file quantile.h.


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