Loading...
Searching...
No Matches
OzakiScheme.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3#pragma once
4
5#include <Eigen/Core>
6#include <cmath>
7#include <limits>
8#include <vector>
9
10namespace gpr::linalg {
11
12// Slice products are accumulated as scaled integers and rounded once.
13
18int schemeISliceBits(Eigen::Index length);
19
21 int bits = 0;
22 std::vector<Eigen::VectorXd> slices;
23};
24
27SchemeISlices splitSchemeI(const Eigen::Ref<const Eigen::VectorXd>& values);
28
30double accumulateSchemeI(const SchemeISlices& left, const SchemeISlices& right);
31
33double schemeIProductRaw(const double* left, const double* right, int length);
34
37template <typename Left, typename Right>
38double schemeIProduct(const Eigen::MatrixBase<Left>& left,
39 const Eigen::MatrixBase<Right>& right)
40{
41 if (left.rows() != right.rows() || left.cols() != right.cols() ||
42 left.size() > std::numeric_limits<int>::max()) {
43 return std::numeric_limits<double>::quiet_NaN();
44 }
45 Eigen::VectorXd left_terms(left.size());
46 Eigen::VectorXd right_terms(right.size());
47 Eigen::Index term = 0;
48 for (Eigen::Index column = 0; column < left.cols(); ++column) {
49 for (Eigen::Index row = 0; row < left.rows(); ++row, ++term) {
50 left_terms(term) = left(row, column);
51 right_terms(term) = right(row, column);
52 }
53 }
54 return accumulateSchemeI(splitSchemeI(left_terms),
55 splitSchemeI(right_terms));
56}
57
58} // namespace gpr::linalg
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
double schemeIProductRaw(const double *left, const double *right, int length)
Scheme I product of two length-n factors in term order.
double schemeIProduct(const Eigen::MatrixBase< Left > &left, const Eigen::MatrixBase< Right > &right)
Definition OzakiScheme.h:38
int schemeISliceBits(Eigen::Index length)
double accumulateSchemeI(const SchemeISlices &left, const SchemeISlices &right)
Sum the exact slice products. The split and this accumulation are separate.
SchemeISlices splitSchemeI(const Eigen::Ref< const Eigen::VectorXd > &values)
std::vector< Eigen::VectorXd > slices
Definition OzakiScheme.h:22