1#ifndef IRLBA_TATAMI_NORMAL_HPP
2#define IRLBA_TATAMI_NORMAL_HPP
5#include "tatami_mult/tatami_mult.hpp"
6#include "irlba/irlba.hpp"
7#include "sanisizer/sanisizer.hpp"
22template<
class EigenVector_,
typename TValue_,
typename TIndex_,
class TMatrix_ = tatami::Matrix<TValue_, TIndex_> >
25 NormalWorkspace(
const TMatrix_& mat,
int num_threads) : my_mat(mat) {
26 opt.num_threads = num_threads;
30 const TMatrix_& my_mat;
31 tatami_mult::Options opt;
34 void multiply(
const EigenVector_& right, EigenVector_& out) {
35 tatami_mult::multiply(my_mat, right.data(), out.data(), opt);
39template<
class EigenVector_,
typename TValue_,
typename TIndex_,
class TMatrix_ = tatami::Matrix<TValue_, TIndex_> >
42 NormalAdjointWorkspace(
const TMatrix_& mat,
int num_threads) : my_mat(mat) {
43 opt.num_threads = num_threads;
47 const TMatrix_& my_mat;
48 tatami_mult::Options opt;
51 void multiply(
const EigenVector_& right, EigenVector_& out) {
52 tatami_mult::multiply(right.data(), my_mat, out.data(), opt);
56template<
class EigenMatrix_,
typename TValue_,
typename TIndex_,
class TMatrix_ = tatami::Matrix<TValue_, TIndex_> >
59 NormalRealizeWorkspace(
const TMatrix_& mat,
int num_threads) : my_mat(mat), my_num_threads(num_threads) {}
62 const TMatrix_& my_mat;
66 const EigenMatrix_& realize(EigenMatrix_& buffer) {
69 buffer.resize(my_mat.nrow(), my_mat.ncol());
76 tatami::ConvertToDenseOptions opt;
77 opt.num_threads = my_num_threads;
103template<
class EigenVector_,
class EigenMatrix_,
typename TValue_,
typename TIndex_,
class TMatrixPo
inter_ = std::shared_ptr<const tatami::Matrix<TValue_, TIndex_> > >
111 Normal(TMatrixPointer_ mat,
int num_threads) : my_mat(std::move(mat)), my_num_threads(num_threads) {
113 sanisizer::cast<Eigen::Index>(tatami::attest_for_Index(my_mat->nrow()));
114 sanisizer::cast<Eigen::Index>(tatami::attest_for_Index(my_mat->ncol()));
118 Eigen::Index rows()
const {
119 return my_mat->nrow();
122 Eigen::Index cols()
const {
123 return my_mat->ncol();
127 TMatrixPointer_ my_mat;
130 typedef std::remove_cv_t<std::remove_reference_t<
decltype(*my_mat)> > TMatrix;
133 std::unique_ptr<irlba::Workspace<EigenVector_> > new_workspace()
const {
137 std::unique_ptr<irlba::AdjointWorkspace<EigenVector_> > new_adjoint_workspace()
const {
141 std::unique_ptr<irlba::RealizeWorkspace<EigenMatrix_> > new_realize_workspace()
const {
150 return std::make_unique<NormalWorkspace<EigenVector_, TValue_, TIndex_, TMatrix> >(*my_mat, my_num_threads);
157 return std::make_unique<NormalAdjointWorkspace<EigenVector_, TValue_, TIndex_, TMatrix> >(*my_mat, my_num_threads);
164 return std::make_unique<NormalRealizeWorkspace<EigenMatrix_, TValue_, TIndex_, TMatrix> >(*my_mat, my_num_threads);
Wrap a tatami matrix for irlba.
Definition normal.hpp:104
auto new_known_adjoint_workspace() const
Definition normal.hpp:156
Normal(TMatrixPointer_ mat, int num_threads)
Definition normal.hpp:111
auto new_known_realize_workspace() const
Definition normal.hpp:163
auto new_known_workspace() const
Definition normal.hpp:149
void convert_to_dense(const Matrix< InputValue_, InputIndex_ > &matrix, const bool row_major, StoredValue_ *const store, const ConvertToDenseOptions &options)