OmniSciDB  72c90bc290
 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 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
 

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::once_flag merge_buffer_final_once_
 
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 226 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 230 of file quantile.h.

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

231  : centroids_(mem.sums().data(), mem.counts().data(), mem.size()) {
232  centroids_.clear();
233  }
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 235 of file quantile.h.

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

Member Function Documentation

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

Definition at line 603 of file quantile.h.

603  {
604  if (buf_.sums_.full()) {
605  mergeBuffer();
606  }
607  buf_.sums_.push_back(value);
608  buf_.counts_.push_back(1);
609 }
DEVICE void mergeBuffer()
Definition: quantile.h:652
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::allocate ( )

Definition at line 613 of file quantile.h.

Referenced by agg_approx_quantile(), and approx_quantile_jit_rt().

613  {
614  if (buf_.capacity() == 0) {
615  auto* p0 = simple_allocator_->allocate(buf_allocate_ * sizeof(RealType));
616  auto* p1 = simple_allocator_->allocate(buf_allocate_ * sizeof(IndexType));
617  buf_ = Centroids<RealType, IndexType>(
618  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, buf_allocate_),
619  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, buf_allocate_));
620  p0 = simple_allocator_->allocate(centroids_allocate_ * sizeof(RealType));
621  p1 = simple_allocator_->allocate(centroids_allocate_ * sizeof(IndexType));
622  centroids_ = Centroids<RealType, IndexType>(
623  VectorView<RealType>(reinterpret_cast<RealType*>(p0), 0, centroids_allocate_),
624  VectorView<IndexType>(reinterpret_cast<IndexType*>(p1), 0, centroids_allocate_));
625  }
626 }
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
IndexType const buf_allocate_
Definition: quantile.h:199
virtual int8_t * allocate(const size_t num_bytes, const size_t thread_idx=0)=0
SimpleAllocator *const simple_allocator_
Definition: quantile.h:198
IndexType const centroids_allocate_
Definition: quantile.h:200
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 245 of file quantile.h.

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

245  {
246  return centroids_;
247  }
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 730 of file quantile.h.

730  {
731  if (x < 1) {
732  return min();
733  } else if (centroids_.size() == 1) {
734  return oneCentroid(x);
735  } else if (centroids_.counts_.front() == 2) {
736  RealType const sum = centroids_.sums_.front();
737  return x == 1 ? 0.5 * sum : sum - min();
738  } else {
739  RealType const count = centroids_.counts_.front();
740  RealType const dx = x - RealType(0.5) * (1 + count);
741  RealType const mean = (centroids_.sums_.front() - min()) / (count - 1);
742  return mean + slope(0, 0 < dx) * dx;
743  }
744 }
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:864
DEVICE RealType oneCentroid(RealType const x) const
Definition: quantile.h:808
DEVICE RealType min() const
Definition: quantile.h:205
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 749 of file quantile.h.

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

751  {
752  if (isSingleton(centroids_.counts_.begin() + idx1)) {
753  RealType const sum1 = centroids_.sums_[idx1];
754  if (x == prefix_sum - centroids_.counts_[idx1]) {
755  if (isSingleton(centroids_.counts_.begin() + idx1 - 1)) {
756  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
757  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
758  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
759  }
760  }
761  return sum1;
762  } else {
763  RealType const dx = x + RealType(0.5) * centroids_.counts_[idx1] - prefix_sum;
764  IndexType const idx2 = idx1 + 2 * (0 < dx) - 1;
765  return centroids_.mean(idx1) + slope(idx1, idx2) * dx;
766  }
767 }
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:864
DEVICE RealType min() const
Definition: quantile.h:205
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:723
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 771 of file quantile.h.

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

772  {
773  if (N - 1 < x) {
774  return max();
775  }
776  IndexType const idx1 = centroids_.size() - 1;
777  RealType const sum1 = centroids_.sums_[idx1];
778  IndexType const count1 = centroids_.counts_[idx1];
779  if (count1 == 1) { // => x == N - 1
780  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
781  return 0.5 * (centroids_.sums_[idx1 - 1] + sum1);
782  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
783  return 0.5 * (centroids_.sums_[idx1 - 1] - min() + sum1);
784  } else {
785  return sum1;
786  }
787  } else if (count1 == 2) { // => 3 <= N
788  if (x == N - 1) {
789  return 0.5 * sum1;
790  } else if (x == N - 2) {
791  RealType const sum2 = centroids_.sums_[idx1 - 1];
792  if (isSingleton(centroids_.counts_.begin() + (idx1 - 1))) {
793  return 0.5 * (sum2 + sum1 - max());
794  } else if (idx1 == 1 && centroids_.counts_[0] == 2) {
795  return 0.5 * (sum2 - min() + sum1 - max());
796  }
797  }
798  return sum1 - max();
799  } else { // => 3 <= count1
800  RealType const dx = x + RealType(0.5) * (count1 + 1) - N;
801  RealType const mean = (sum1 - max()) / (count1 - 1);
802  return mean + slope(idx1, idx1 - (dx < 0)) * dx;
803  }
804 }
DEVICE RealType max() const
Definition: quantile.h:202
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:864
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:205
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:723
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 202 of file quantile.h.

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

202  {
203  return centroids_.max_;
204  }
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 631 of file quantile.h.

633  {
634  IndexType const max_bins = centroids_.capacity(); // "compression parameter" delta
635  if (total_weight <= max_bins) {
636  return 0;
637  } else if (use_linear_scaling_function_) {
638  // Whitepaper scaling function k=0.
639  return 2 * total_weight / max_bins;
640  } else {
641  // Whitepaper scaling function k=1.
642  RealType const x = 2.0 * sum / total_weight - 1; // = 2 q_{i-1} - 1
643  RealType const f_inv = 0.5 + 0.5 * std::sin(c + std::asin(x));
644  constexpr RealType eps = 1e-5; // round-off epsilon for floor().
645  IndexType const dsum = static_cast<IndexType>(total_weight * f_inv + eps);
646  return dsum < sum ? 0 : dsum - sum;
647  }
648 }
bool const use_linear_scaling_function_
Definition: quantile.h:197
Centroids< RealType, IndexType > centroids_
Definition: quantile.h:189
template<typename RealType , typename IndexType >
DEVICE void quantile::detail::TDigest< RealType, IndexType >::mergeBuffer ( )

Definition at line 652 of file quantile.h.

References gpu_enabled::sort().

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

652  {
653  if (buf_.size()) {
654  gpu_enabled::sort(buf_.sums_.begin(), buf_.sums_.end());
655  buf_.min_ = buf_.sums_.front();
656  buf_.max_ = buf_.sums_.back();
658  }
659 }
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:700

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

Referenced by ResultSet::calculateQuantile().

663  {
664  auto const call_once = [this] {
665  mergeBuffer();
666  assert(centroids_.size() <= buf_.capacity());
667  partialSumOfCounts(buf_.counts_.data());
668  };
669 #ifdef __CUDACC__
670  call_once();
671 #else
672  std::call_once(merge_buffer_final_once_, call_once);
673 #endif
674 }
DEVICE VectorView< IndexType const > partialSumOfCounts(IndexType *const buf) const
Definition: quantile.h:831
std::once_flag merge_buffer_final_once_
Definition: quantile.h:192
DEVICE void mergeBuffer()
Definition: quantile.h:652
Centroids< RealType, IndexType > buf_
Definition: quantile.h:188
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 700 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().

701  {
702  constexpr RealType two_pi = 6.283185307179586476925286766559005768e+00;
703  // Hoisted constant used in maxCardinality().
704  RealType const c = two_pi / centroids_.capacity();
705  // Loop over sorted sequence of buf and centroids_.
706  // Some latter centroids may be merged into the current centroid, so the number
707  // of iterations is only at most equal to the number of initial centroids.
708  using CM = CentroidsMerger<RealType, IndexType>;
709  for (CM cm(&buf, &centroids_, forward_); cm.hasNext(); cm.next()) {
710  // cm.prefixSum() == 0 on first iteration.
711  // Max cardinality for current centroid to be fully merged based on scaling function.
712  IndexType const max_cardinality = maxCardinality(cm.prefixSum(), cm.totalWeight(), c);
713  cm.merge(max_cardinality);
714  }
715  // Combine sorted centroids buf[0..curr_idx_] + centroids_[0..curr_idx_] if forward
716  centroids_.appendAndSortCurrent(buf);
717  buf.clear();
718  forward_ ^= true; // alternate merge direction on each call
719 }
DEVICE IndexType maxCardinality(IndexType const sum, IndexType const total_weight, RealType const c)
Definition: quantile.h:631
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 677 of file quantile.h.

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

679  {
680  if (size) {
681  if (buf_.capacity() == 0) {
682  buf_ = Centroids<RealType, IndexType>(sums, counts, size); // Set capacity and size
683  } else {
684  buf_.sums_.set(sums, size); // Does not change capacity
685  buf_.counts_.set(counts, size);
686  }
687  gpu_enabled::fill(buf_.counts_.begin(), buf_.counts_.end(), IndexType(1));
688  buf_.min_ = buf_.sums_.front();
689  buf_.max_ = buf_.sums_.back();
691  }
692 }
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:700

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

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

263  {
264  mergeBuffer();
265  t_digest.mergeBuffer();
266  mergeCentroids(t_digest.centroids_);
267  }
DEVICE void mergeBuffer()
Definition: quantile.h:652
DEVICE void mergeCentroids(Centroids< RealType, IndexType > &)
Definition: quantile.h:700

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

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

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

Definition at line 808 of file quantile.h.

References anonymous_namespace{Utm.h}::N.

808  {
809  IndexType const N = centroids_.counts_.front();
810  if (N - 1 < x) { // includes case N == 1
811  return max();
812  } else if (N == 2) { // x == 1
813  return 0.5 * centroids_.sums_.front();
814  } else if (N == 3) { // 1 <= x <= 2
815  if (x == 2) {
816  return 0.5 * (centroids_.sums_.front() - min());
817  } else {
818  RealType const s = centroids_.sums_.front() - max();
819  return x == 1 ? 0.5 * s : s - min();
820  }
821  } else { // 3 < N
822  RealType const dx = x - RealType(0.5) * N;
823  RealType const mean = (centroids_.sums_.front() - (min() + max())) / (N - 2);
824  RealType const slope = 2 * (0 < dx ? max() - mean : mean - min()) / (N - 2);
825  return mean + slope * dx;
826  }
827 }
DEVICE RealType max() const
Definition: quantile.h:202
DEVICE RealType slope(IndexType const idx1, IndexType const idx2) const
Definition: quantile.h:864
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType min() const
Definition: quantile.h:205
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 831 of file quantile.h.

References gpu_enabled::partial_sum().

832  {
833  gpu_enabled::partial_sum(centroids_.counts_.begin(), centroids_.counts_.end(), buf);
834  return {buf, centroids_.size()};
835 }
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 839 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().

840  {
841  if (centroids_.size()) {
842  IndexType const N = partial_sum.back();
843  RealType const x = q * N;
844  auto const it1 = gpu_enabled::upper_bound(partial_sum.begin(), partial_sum.end(), x);
845  if (it1 == partial_sum.begin()) {
846  return firstCentroid(x);
847  } else if (it1 == partial_sum.end()) { // <==> 1 <= q
848  return max();
849  } else if (it1 + 1 == partial_sum.end()) {
850  return lastCentroid(x, N);
851  } else {
852  return interiorCentroid(x, it1 - partial_sum.begin(), *it1);
853  }
854  } else {
855  return centroids_.nan;
856  }
857 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
DEVICE RealType max() const
Definition: quantile.h:202
DEVICE T * begin() const
Definition: VectorView.h:59
DEVICE RealType lastCentroid(RealType const x, IndexType const N) const
Definition: quantile.h:771
constexpr unsigned N
Definition: Utm.h:110
DEVICE RealType interiorCentroid(RealType const x, IndexType const idx1, IndexType const prefix_sum) const
Definition: quantile.h:749
DEVICE T & back()
Definition: VectorView.h:57
DEVICE RealType firstCentroid(RealType const x) const
Definition: quantile.h:730
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 276 of file quantile.h.

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

276  {
277  return quantile({buf_.counts_.data(), centroids_.size()}, q);
278  }
DEVICE RealType quantile()
Definition: quantile.h:280
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 280 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().

280  {
281  return q_ ? quantile(*q_) : centroids_.nan;
282  }
DEVICE RealType quantile()
Definition: quantile.h:280
std::optional< RealType > const q_
Definition: quantile.h:196
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 285 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().

285  {
286  buf_ = Centroids<RealType, IndexType>(
287  mem.sums().data(), mem.counts().data(), mem.size());
288  buf_.clear();
289  }
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 292 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().

292  {
293  centroids_ = Centroids<RealType, IndexType>(
294  mem.sums().data(), mem.counts().data(), mem.size());
295  centroids_.clear();
296  }
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 298 of file quantile.h.

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

299  {
300  centroids_ = Centroids<RealType, IndexType>(sums, counts);
301  centroids_.clear();
302  }
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 864 of file quantile.h.

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

865  {
866  IndexType const M = centroids_.size();
867  if (idx1 == idx2) { // Line segment is contained in either the first or last centroid.
868  RealType const n = static_cast<RealType>(centroids_.counts_[idx1]);
869  RealType const s = centroids_.sums_[idx1];
870  return idx1 == 0 ? 2 * (s - n * min()) / ((n - 1) * (n - 1))
871  : 2 * (n * max() - s) / ((n - 1) * (n - 1));
872  } else {
873  bool const min1 = idx1 == 0; // idx1 is the min centroid
874  bool const max1 = idx1 == M - 1; // idx1 is the max centroid
875  bool const min2 = idx2 == 0; // idx2 is the min centroid
876  bool const max2 = idx2 == M - 1; // idx2 is the max centroid
877  RealType const n1 = static_cast<RealType>(centroids_.counts_[idx1] - min1 - max1);
878  RealType const s1 = centroids_.sums_[idx1] - (min1 ? min() : max1 ? max() : 0);
879  RealType const s2 = centroids_.sums_[idx2] - (min2 ? min() : max2 ? max() : 0);
880  if (isSingleton(centroids_.counts_.begin() + idx2)) {
881  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - s1) / (n1 * n1);
882  } else {
883  RealType const n2 = static_cast<RealType>(centroids_.counts_[idx2] - min2 - max2);
884  return (idx1 < idx2 ? 2 : -2) * (n1 * s2 - n2 * s1) / (n1 * n2 * (n1 + n2));
885  }
886  }
887 }
DEVICE RealType max() const
Definition: quantile.h:202
constexpr double n
Definition: Utm.h:38
DEVICE RealType min() const
Definition: quantile.h:205
DEVICE bool isSingleton(CountsIterator itr)
Definition: quantile.h:723
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 305 of file quantile.h.

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

305  {
306  return centroids_.totalWeight();
307  }
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 const quantile::detail::TDigest< RealType, IndexType >::buf_allocate_ {0}
private

Definition at line 199 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 200 of file quantile.h.

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

Definition at line 190 of file quantile.h.

template<typename RealType , typename IndexType = size_t>
std::once_flag quantile::detail::TDigest< RealType, IndexType >::merge_buffer_final_once_
private

Definition at line 192 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 198 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 197 of file quantile.h.


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