1#ifndef KMEANS_TATAMI_HPP
2#define KMEANS_TATAMI_HPP
25template<
typename KIndex_,
typename KData_,
typename TValue_,
typename TIndex_,
class Extractor_ = tatami::MyopicDenseExtractor<TValue_, TIndex_> >
28 Random(std::unique_ptr<Extractor_> ext, TIndex_ ndim) : my_ext(std::move(ext)) {
30 if constexpr(!same_type) {
36 std::unique_ptr<Extractor_> my_ext;
37 std::vector<TValue_> my_buffer;
38 static constexpr bool same_type = std::is_same<TValue_, KData_>::value;
39 typename std::conditional<same_type, bool, std::vector<KData_> > my_output;
42 const KData_* get_observation(KIndex_ i) {
43 auto ptr = my_ext->fetch(i, my_buffer.data());
44 if constexpr(same_type) {
47 std::copy_n(ptr, my_buffer.size(), my_output.data());
48 return my_output.data();
53template<
typename KIndex_,
typename KData_,
typename TValue_,
typename TIndex_,
class Extractor_ = tatami::OracularDenseExtractor<TValue_, TIndex_> >
56 Consecutive(std::unique_ptr<Extractor_> ext, TIndex_ ndim) : my_ext(std::move(ext)) {
58 if constexpr(!same_type) {
64 std::unique_ptr<Extractor_> my_ext;
65 std::vector<TValue_> my_buffer;
66 static constexpr bool same_type = std::is_same<TValue_, KData_>::value;
67 typename std::conditional<same_type, bool, std::vector<KData_> > my_output;
70 const KData_* get_observation() {
71 auto ptr = my_ext->fetch(my_buffer.data());
72 if constexpr(same_type) {
75 std::copy_n(ptr, my_buffer.size(), my_output.data());
76 return my_output.data();
81template<
typename KIndex_,
typename KData_,
typename TValue_,
typename TIndex_,
class Extractor_ = tatami::OracularDenseExtractor<TValue_, TIndex_> >
84 Indexed(std::unique_ptr<Extractor_> ext, TIndex_ ndim) : my_ext(std::move(ext)) {
86 if constexpr(!same_type) {
92 std::unique_ptr<Extractor_> my_ext;
93 std::vector<TValue_> my_buffer;
94 static constexpr bool same_type = std::is_same<TValue_, KData_>::value;
95 typename std::conditional<same_type, bool, std::vector<KData_> > my_output;
98 const KData_* get_observation() {
99 auto ptr = my_ext->fetch(my_buffer.data());
100 if constexpr(same_type) {
103 std::copy_n(ptr, my_buffer.size(), my_output.data());
104 return my_output.data();
126template<
typename KIndex_,
typename KData_,
typename TValue_,
typename TIndex_,
class MatrixPo
inter_ = std::shared_ptr<const tatami::Matrix<TValue_, TIndex_> > >
129 MatrixPointer_ my_matrix;
140 Matrix(MatrixPointer_ matrix,
bool transposed =
false) : my_matrix(std::move(matrix)), my_transposed(transposed) {
143 cur_nobs = my_matrix->nrow();
144 my_ndim = my_matrix->ncol();
146 cur_nobs = my_matrix->ncol();
147 my_ndim = my_matrix->nrow();
152 my_nobs = sanisizer::cast<KIndex_>(sanisizer::attest_gez(sanisizer::attest_max_by_type<std::size_t>(cur_nobs)));
155 KIndex_ num_observations()
const {
159 std::size_t num_dimensions()
const {
164 std::unique_ptr<kmeans::RandomAccessExtractor<KIndex_, KData_> > new_extractor()
const {
165 return std::make_unique<Random<KIndex_, KData_, TValue_, TIndex_> >(my_matrix->dense(my_transposed, {}), my_ndim);
168 std::unique_ptr<kmeans::ConsecutiveAccessExtractor<KIndex_, KData_> > new_extractor(KIndex_ start, KIndex_ length)
const {
170 auto optr = std::make_shared<tatami::ConsecutiveOracle<TIndex_> >(start, length);
171 return std::make_unique<Consecutive<KIndex_, KData_, TValue_, TIndex_> >(my_matrix->dense(my_transposed, std::move(optr), {}), my_ndim);
174 std::unique_ptr<kmeans::IndexedAccessExtractor<KIndex_, KData_> > new_extractor(
const KIndex_* sequence, std::size_t length)
const {
175 auto optr = std::make_shared<tatami::FixedViewOracle<TIndex_, const KIndex_*> >(sequence, length);
176 return std::make_unique<Indexed<KIndex_, KData_, TValue_, TIndex_> >(my_matrix->dense(my_transposed, std::move(optr), {}), my_ndim);
kmeans-compatible wrapper around a tatami matrix.
Definition kmeans_tatami.hpp:127
Matrix(MatrixPointer_ matrix, bool transposed=false)
Definition kmeans_tatami.hpp:140
Wrapper around a tatami matrix.
void resize_container_to_Index_size(Container_ &container, const Index_ x, Args_ &&... args)