gsdecon
C++ port of the GSDecon algorithm
Loading...
Searching...
No Matches
compute.hpp
Go to the documentation of this file.
1#ifndef GSDECON_COMPUTE_HPP
2#define GSDECON_COMPUTE_HPP
3
4#include <algorithm>
5#include <numeric>
6
7#include "tatami/tatami.hpp"
8#include "irlba/irlba.hpp"
10
11#include "Options.hpp"
12#include "Results.hpp"
13#include "utils.hpp"
14
20namespace gsdecon {
21
44template<typename Value_, typename Index_, typename Float_>
45void compute(const tatami::Matrix<Value_, Index_>& matrix, const Options& options, const Buffers<Float_>& output) {
46 if (internal::check_edge_cases(matrix, options.rank, output)) {
47 return;
48 }
49
51 sopt.number = options.rank;
52 sopt.scale = options.scale;
53 sopt.realize_matrix = options.realize_matrix;
54 sopt.num_threads = options.num_threads;
55 sopt.irlba_options = options.irlba_options;
56 auto res = scran_pca::simple_pca(matrix, sopt);
57
58 double shift = std::accumulate(res.center.begin(), res.center.end(), 0.0) / matrix.nrow();
59 std::fill_n(output.scores, matrix.ncol(), shift);
60 internal::process_output(res.rotation, res.components, options.scale, res.scale, output);
61}
62
77template<typename Float_ = double, typename Value_, typename Index_>
79 Results<Float_> output;
80 output.weights.resize(matrix.nrow());
81 output.scores.resize(matrix.ncol());
82
83 Buffers<Float_> buffers;
84 buffers.weights = output.weights.data();
85 buffers.scores = output.scores.data();
86
87 compute(matrix, options, buffers);
88 return output;
89}
90
91}
92
93#endif
Classes for storing the results.
virtual Index_ ncol() const=0
virtual Index_ nrow() const=0
Gene set scoring with gsdecon.
Definition blocked.hpp:21
void compute(const tatami::Matrix< Value_, Index_ > &matrix, const Options &options, const Buffers< Float_ > &output)
Definition compute.hpp:45
void simple_pca(const tatami::Matrix< Value_, Index_ > &mat, const SimplePcaOptions &options, SimplePcaResults< EigenMatrix_, EigenVector_ > &output)
Buffers for the results of compute() and compute_blocked().
Definition Results.hpp:18
Float_ * scores
Definition Results.hpp:23
Float_ * weights
Definition Results.hpp:29
Options for compute() and compute_blocked().
Definition Options.hpp:17
bool realize_matrix
Definition Options.hpp:61
int rank
Definition Options.hpp:31
int num_threads
Definition Options.hpp:55
irlba::Options irlba_options
Definition Options.hpp:66
bool scale
Definition Options.hpp:37
Results of compute() and compute_blocked().
Definition Results.hpp:37
std::vector< double > scores
Definition Results.hpp:42
std::vector< double > weights
Definition Results.hpp:49
irlba::Options irlba_options