1#ifndef IRLBA_MATRIX_CENTERED_HPP
2#define IRLBA_MATRIX_CENTERED_HPP
21template<
class EigenVector_,
class Matrix_,
class Center_>
22class CenteredWorkspace final :
public Workspace<EigenVector_> {
24 CenteredWorkspace(
const Matrix_& matrix,
const Center_& center) :
25 my_work(matrix.new_known_workspace()),
30 I<decltype(std::declval<Matrix_>().new_known_workspace())> my_work;
31 const Center_& my_center;
34 void multiply(
const EigenVector_& right, EigenVector_& out) {
35 my_work->multiply(right, out);
36 const auto beta = right.dot(my_center);
43template<
class EigenVector_,
class Matrix_,
class Center_>
44class CenteredAdjointWorkspace final :
public AdjointWorkspace<EigenVector_> {
46 CenteredAdjointWorkspace(
const Matrix_& matrix,
const Center_& center) :
47 my_work(matrix.new_known_adjoint_workspace()),
52 I<decltype(std::declval<Matrix_>().new_known_adjoint_workspace())> my_work;
53 const Center_& my_center;
56 void multiply(
const EigenVector_& right, EigenVector_& out) {
57 my_work->multiply(right, out);
58 const auto beta = right.sum();
59 out -= beta * my_center;
63template<
class EigenMatrix_,
class Matrix_,
class Center_>
64class CenteredRealizeWorkspace final :
public RealizeWorkspace<EigenMatrix_> {
66 CenteredRealizeWorkspace(
const Matrix_& matrix,
const Center_& center) :
67 my_work(matrix.new_known_realize_workspace()),
72 I<decltype(std::declval<Matrix_>().new_known_realize_workspace())> my_work;
73 const Center_& my_center;
76 const EigenMatrix_& realize(EigenMatrix_& buffer) {
77 my_work->realize_copy(buffer);
78 buffer.array().rowwise() -= my_center.adjoint().array();
103 class MatrixPointer_ =
const Matrix<EigenVector_, EigenMatrix_>*,
104 class CenterPointer_ =
const EigenVector_*
114 my_matrix(std::move(matrix)),
115 my_center(std::move(center))
119 MatrixPointer_ my_matrix;
120 CenterPointer_ my_center;
124 return my_matrix->rows();
128 return my_matrix->cols();
149 return std::make_unique<CenteredWorkspace<EigenVector_, I<
decltype(*my_matrix)>, I<
decltype(*my_center)> > >(*my_matrix, *my_center);
156 return std::make_unique<CenteredAdjointWorkspace<EigenVector_, I<
decltype(*my_matrix)>, I<
decltype(*my_center)> > >(*my_matrix, *my_center);
163 return std::make_unique<CenteredRealizeWorkspace<EigenMatrix_, I<
decltype(*my_matrix)>, I<
decltype(*my_center)> > >(*my_matrix, *my_center);
Deferred centering of a matrix.
Definition centered.hpp:106
auto new_known_workspace() const
Definition centered.hpp:148
Eigen::Index cols() const
Definition centered.hpp:127
auto new_known_adjoint_workspace() const
Definition centered.hpp:155
auto new_known_realize_workspace() const
Definition centered.hpp:162
Eigen::Index rows() const
Definition centered.hpp:123
std::unique_ptr< Workspace< EigenVector_ > > new_workspace() const
Definition centered.hpp:132
CenteredMatrix(MatrixPointer_ matrix, CenterPointer_ center)
Definition centered.hpp:113
std::unique_ptr< RealizeWorkspace< EigenMatrix_ > > new_realize_workspace() const
Definition centered.hpp:140
std::unique_ptr< AdjointWorkspace< EigenVector_ > > new_adjoint_workspace() const
Definition centered.hpp:136
Interface for a matrix to use in compute().
Definition interface.hpp:142
Interfaces for matrix inputs.