kmeans
A C++ library for k-means
Loading...
Searching...
No Matches
Matrix.hpp
Go to the documentation of this file.
1#ifndef KMEANS_MATRIX_HPP
2#define KMEANS_MATRIX_HPP
3
4#include <memory>
5#include <utility>
6
12namespace kmeans {
13
23template<typename Index_, typename Data_>
25public:
29 RandomAccessExtractor() = default;
32 RandomAccessExtractor& operator=(const RandomAccessExtractor&) = default;
33 RandomAccessExtractor& operator=(RandomAccessExtractor&&) = default;
34 virtual ~RandomAccessExtractor() = default;
45 virtual const Data_* get_observation(Index_ i) = 0;
46};
47
57template<typename Index_, typename Data_>
83
93template<typename Index_, typename Data_>
95public:
99 IndexedAccessExtractor() = default;
102 IndexedAccessExtractor& operator=(const IndexedAccessExtractor&) = default;
103 IndexedAccessExtractor& operator=(IndexedAccessExtractor&&) = default;
104 virtual ~IndexedAccessExtractor() = default;
117 virtual const Data_* get_observation() = 0;
118};
119
129template<typename Index_, typename Data_>
130class Matrix {
131public:
135 Matrix() = default;
136 Matrix(const Matrix&) = default;
137 Matrix(Matrix&&) = default;
138 Matrix& operator=(const Matrix&) = default;
139 Matrix& operator=(Matrix&&) = default;
140 virtual ~Matrix() = default;
145public:
149 virtual Index_ num_observations() const = 0;
150
154 virtual size_t num_dimensions() const = 0;
155
156public:
160 virtual std::unique_ptr<RandomAccessExtractor<Index_, Data_> > new_extractor() const = 0;
161
167 virtual std::unique_ptr<ConsecutiveAccessExtractor<Index_, Data_> > new_extractor(Index_ start, Index_ length) const = 0;
168
175 virtual std::unique_ptr<IndexedAccessExtractor<Index_, Data_> > new_extractor(const Index_* sequence, size_t length) const = 0;
176};
177
181// A simple alias to help determine the Index_ inside a Matrix_ instance.
182template<class Matrix_>
183using Index = decltype(std::declval<Matrix_>().num_observations());
187}
188
189#endif
Extractor for accessing consecutive observations.
Definition Matrix.hpp:58
virtual const Data_ * get_observation()=0
Extractor for accessing indexed observations.
Definition Matrix.hpp:94
virtual const Data_ * get_observation()=0
Interface for matrix data.
Definition Matrix.hpp:130
virtual std::unique_ptr< IndexedAccessExtractor< Index_, Data_ > > new_extractor(const Index_ *sequence, size_t length) const =0
virtual std::unique_ptr< ConsecutiveAccessExtractor< Index_, Data_ > > new_extractor(Index_ start, Index_ length) const =0
virtual std::unique_ptr< RandomAccessExtractor< Index_, Data_ > > new_extractor() const =0
virtual size_t num_dimensions() const =0
virtual Index_ num_observations() const =0
Extractor for accessing random observations.
Definition Matrix.hpp:24
virtual const Data_ * get_observation(Index_ i)=0
Namespace for k-means clustering.
Definition compute_wcss.hpp:12