1#ifndef KMEANS_SIMPLE_MATRIX_HPP
2#define KMEANS_SIMPLE_MATRIX_HPP
16template<
typename Index_,
typename Data_>
19template<
typename Index_,
typename Data_>
20class SimpleMatrixRandomAccessExtractor final :
public RandomAccessExtractor<Index_, Data_> {
22 SimpleMatrixRandomAccessExtractor(
const SimpleMatrix<Index_, Data_>& parent) : my_parent(parent) {}
25 const SimpleMatrix<Index_, Data_>& my_parent;
28 const Data_* get_observation(Index_ i) {
29 return my_parent.my_data +
static_cast<size_t>(i) * my_parent.my_num_dim;
33template<
typename Index_,
typename Data_>
34class SimpleMatrixConsecutiveAccessExtractor final :
public ConsecutiveAccessExtractor<Index_, Data_> {
36 SimpleMatrixConsecutiveAccessExtractor(
const SimpleMatrix<Index_, Data_>& parent,
size_t start) : my_parent(parent), my_position(start) {}
39 const SimpleMatrix<Index_, Data_>& my_parent;
43 const Data_* get_observation() {
44 return my_parent.my_data + (my_position++) * my_parent.my_num_dim;
48template<
typename Index_,
typename Data_>
49class SimpleMatrixIndexedAccessExtractor final :
public IndexedAccessExtractor<Index_, Data_> {
51 SimpleMatrixIndexedAccessExtractor(
const SimpleMatrix<Index_, Data_>& parent,
const Index_* sequence) : my_parent(parent), my_sequence(sequence) {}
54 const SimpleMatrix<Index_, Data_>& my_parent;
55 const Index_* my_sequence;
56 size_t my_position = 0;
59 const Data_* get_observation() {
60 return my_parent.my_data +
static_cast<size_t>(my_sequence[my_position++]) * my_parent.my_num_dim;
75template<
typename Index_,
typename Data_>
91 friend class SimpleMatrixRandomAccessExtractor<Index_, Data_>;
92 friend class SimpleMatrixConsecutiveAccessExtractor<Index_, Data_>;
93 friend class SimpleMatrixIndexedAccessExtractor<Index_, Data_>;
108 std::unique_ptr<RandomAccessExtractor<Index_, Data_> >
new_extractor()
const {
109 return std::make_unique<SimpleMatrixRandomAccessExtractor<Index_, Data_> >(*this);
112 std::unique_ptr<ConsecutiveAccessExtractor<Index_, Data_> >
new_extractor(Index_ start, Index_)
const {
113 return std::make_unique<SimpleMatrixConsecutiveAccessExtractor<Index_, Data_> >(*
this, start);
116 std::unique_ptr<IndexedAccessExtractor<Index_, Data_> >
new_extractor(
const Index_* sequence,
size_t)
const {
117 return std::make_unique<SimpleMatrixIndexedAccessExtractor<Index_, Data_> >(*
this, sequence);
Interface for matrix inputs.
Interface for matrix data.
Definition Matrix.hpp:130
virtual std::unique_ptr< RandomAccessExtractor< Index_, Data_ > > new_extractor() const =0
virtual size_t num_dimensions() const =0
virtual Index_ num_observations() const =0
A simple matrix of observations.
Definition SimpleMatrix.hpp:76
SimpleMatrix(size_t num_dimensions, Index_ num_observations, const Data_ *data)
Definition SimpleMatrix.hpp:84
Namespace for k-means clustering.
Definition compute_wcss.hpp:12