Loading...
Searching...
No Matches
gpr::linalg::PredictProduct Class Reference

#include <gpr/linalg/CompensatedSum.h>

Public Member Functions

 PredictProduct (ProductMode mode=productMode())
 PredictProduct (const PredictProduct &other)
PredictProduct & operator= (const PredictProduct &other)
 PredictProduct (PredictProduct &&) noexcept=default
PredictProduct & operator= (PredictProduct &&) noexcept=default
void addProduct (double left, double right)
void clear ()
double value () const

Static Public Member Functions

static void evaluateTogether (const std::vector< const PredictProduct * > &products, std::vector< double > &values)

Detailed Description

Definition at line 120 of file CompensatedSum.h.

Constructor & Destructor Documentation

◆ PredictProduct() [1/3]

gpr::linalg::PredictProduct::PredictProduct ( ProductMode mode = productMode())
inlineexplicit

Definition at line 136 of file CompensatedSum.h.

136: mode_(mode) { }

◆ PredictProduct() [2/3]

gpr::linalg::PredictProduct::PredictProduct ( const PredictProduct & other)
inline

Definition at line 137 of file CompensatedSum.h.

138 : mode_(other.mode_),
139 exact_(other.exact_),
140 terms_(other.terms_ ? std::make_unique<StoredTerms>(*other.terms_)
141 : nullptr)
142 {
143 }

◆ PredictProduct() [3/3]

gpr::linalg::PredictProduct::PredictProduct ( PredictProduct && )
defaultnoexcept

Member Function Documentation

◆ addProduct()

void gpr::linalg::PredictProduct::addProduct ( double left,
double right )
inline

Definition at line 157 of file CompensatedSum.h.

158 {
159 if (mode_ == ProductMode::Compensated) {
160 exact_.addProduct(left, right);
161 } else {
162 if (!terms_) terms_ = std::make_unique<StoredTerms>();
163 terms_->left.push_back(left);
164 terms_->right.push_back(right);
165 }
166 }

◆ clear()

void gpr::linalg::PredictProduct::clear ( )
inline

Definition at line 168 of file CompensatedSum.h.

169 {
170 exact_ = {};
171 if (terms_) {
172 terms_->left.clear();
173 terms_->right.clear();
174 }
175 }

◆ evaluateTogether()

void gpr::linalg::PredictProduct::evaluateTogether ( const std::vector< const PredictProduct * > & products,
std::vector< double > & values )
static

Definition at line 214 of file PredictProduct.cpp.

217{
218 if (products.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
219 throw std::length_error("too many prediction products");
220 bool device_batch = true;
221 for (const auto* product: products) {
222 if (product == nullptr)
223 throw std::invalid_argument("null prediction product");
224 device_batch =
225 device_batch && product->mode_ == ProductMode::KernelFloat;
226 }
227 values.resize(products.size());
228 if (!device_batch) {
229 for (size_t i = 0; i < products.size(); ++i)
230 values[i] = products[i]->value();
231 return;
232 }
233 std::vector<StoredProduct> operands;
234 operands.reserve(products.size());
235 for (const auto* product: products) {
236 const auto* terms = product->terms_.get();
237 if (!terms) {
238 operands.push_back({nullptr, nullptr, 0});
239 continue;
240 }
241 if (terms->left.size() >
242 static_cast<size_t>(std::numeric_limits<int>::max()))
243 throw std::length_error("prediction product is too long");
244 operands.push_back({terms->left.data(), terms->right.data(),
245 static_cast<int>(terms->left.size())});
246 }
247 evaluateStoredProducts(operands.data(), static_cast<int>(operands.size()),
248 ProductMode::KernelFloat, values.data());
249}
void evaluateStoredProducts(const StoredProduct *products, int count, ProductMode mode, double *values)

◆ operator=() [1/2]

PredictProduct & gpr::linalg::PredictProduct::operator= ( const PredictProduct & other)
inline

Definition at line 144 of file CompensatedSum.h.

145 {
146 if (this != &other) {
147 mode_ = other.mode_;
148 exact_ = other.exact_;
149 terms_ = other.terms_ ? std::make_unique<StoredTerms>(*other.terms_)
150 : nullptr;
151 }
152 return *this;
153 }

◆ operator=() [2/2]

PredictProduct & gpr::linalg::PredictProduct::operator= ( PredictProduct && )
defaultnoexcept

◆ value()

double gpr::linalg::PredictProduct::value ( ) const
inline

Definition at line 177 of file CompensatedSum.h.

178 {
179 if (!terms_ || terms_->left.empty()) return exact_.value();
180 return evaluateStoredProduct(terms_->left.data(), terms_->right.data(),
181 static_cast<int>(terms_->left.size()),
182 mode_);
183 }
double evaluateStoredProduct(const double *left, const double *right, int length, ProductMode mode)

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