knncolle
Collection of KNN methods in C++
Loading...
Searching...
No Matches
MockMatrix.hpp
Go to the documentation of this file.
1#ifndef KNNCOLLE_MOCK_MATRIX_HPP
2#define KNNCOLLE_MOCK_MATRIX_HPP
3
9namespace knncolle {
10
18public:
22 MockMatrix(int num_dim, int num_obs, const double* data) : my_num_dim(num_dim), my_num_obs(num_obs), my_data(data), my_long_num_dim(num_dim) {}
27public:
32 typedef double data_type;
33
38 typedef int index_type;
39
44 typedef int dimension_type;
45
46private:
47 dimension_type my_num_dim;
48 index_type my_num_obs;
49 const data_type* my_data;
50 size_t my_long_num_dim;
51
52public:
57 return my_num_obs;
58 }
59
64 return my_num_dim;
65 }
66
67public:
75 struct Workspace {
79 size_t at = 0;
83 };
84
89 return Workspace();
90 }
91
100 const data_type* get_observation(Workspace& workspace) const {
101 return my_data + (workspace.at++) * my_long_num_dim; // already size_t to avoid overflow during multiplication.
102 }
103};
104
115template<typename Dim_, typename Index_, typename Data_>
117public:
124 SimpleMatrix(Dim_ num_dimensions, Index_ num_observations, const Data_* data) :
125 my_num_dim(num_dimensions), my_num_obs(num_observations), my_data(data), my_long_num_dim(num_dimensions) {}
126
127private:
128 Dim_ my_num_dim;
129 Index_ my_num_obs;
130 const Data_* my_data;
131 size_t my_long_num_dim;
132
133public:
137 typedef Data_ data_type;
138
139 typedef Index_ index_type;
140
141 typedef Dim_ dimension_type;
142
143 struct Workspace{
144 size_t at = 0;
145 };
146
147public:
148 Index_ num_observations() const {
149 return my_num_obs;
150 }
151
152 dimension_type num_dimensions() const {
153 return my_num_dim;
154 }
155
156 Workspace create_workspace() const {
157 return Workspace();
158 }
159
160 const data_type* get_observation(Workspace& workspace) const {
161 return my_data + (workspace.at++) * my_long_num_dim; // already size_t's to avoid overflow during multiplication.
162 }
166};
167
168}
169
170#endif
Compile-time interface for matrix data.
Definition MockMatrix.hpp:17
double data_type
Definition MockMatrix.hpp:32
const data_type * get_observation(Workspace &workspace) const
Definition MockMatrix.hpp:100
int dimension_type
Definition MockMatrix.hpp:44
Workspace create_workspace() const
Definition MockMatrix.hpp:88
index_type num_observations() const
Definition MockMatrix.hpp:56
dimension_type num_dimensions() const
Definition MockMatrix.hpp:63
int index_type
Definition MockMatrix.hpp:38
Simple wrapper for an in-memory matrix.
Definition MockMatrix.hpp:116
SimpleMatrix(Dim_ num_dimensions, Index_ num_observations, const Data_ *data)
Definition MockMatrix.hpp:124
Collection of KNN algorithms.
Definition Bruteforce.hpp:22
Workspace for consecutive access to all observations.
Definition MockMatrix.hpp:75