180 const std::size_t num_dim,
181 const Index_ num_obs,
183 const Batch_*
const batch,
188 auto batches = sanisizer::create<std::vector<Batch<Index_> > >(num_batches);
189 Index_ non_contiguous = 0;
190 for (Index_ o = 0; o < num_obs; ++o) {
191 auto& curbatch = batches[batch[o]];
192 if (curbatch.size == 0) {
196 non_contiguous += (o != curbatch.start + curbatch.size);
201 if (non_contiguous == 0) {
202 compute_internal(num_dim, num_obs, batches, data, options);
207 Index_ accumulated = 0;
208 auto offsets = sanisizer::create<std::vector<Index_> >(num_batches);
209 for (
BatchIndex b = 0; b < num_batches; ++b) {
210 offsets[b] = accumulated;
211 batches[b].start = accumulated;
212 accumulated += batches[b].size;
215 auto reordered = sanisizer::create<std::vector<Index_> >(num_obs);
216 for (Index_ o = 0; o < num_obs; ++o) {
217 auto& offset = offsets[batch[o]];
218 reordered[offset] = o;
221 auto mbuffer = sanisizer::create<std::vector<Float_> >(num_dim);
222 reorder_matrix_in_place(num_dim, num_obs, reordered, data, mbuffer);
224 compute_internal(num_dim, num_obs, batches, data, options);
227 for (
BatchIndex b = 0; b < num_batches; ++b) {
228 offsets[b] = batches[b].start;
230 for (Index_ o = 0; o < num_obs; ++o) {
231 auto& offset = offsets[batch[o]];
232 reordered[o] = offset;
235 reorder_matrix_in_place(num_dim, num_obs, reordered, data, mbuffer);
void compute(const std::size_t num_dim, const std::vector< Batch< Index_ > > &batches, Float_ *const data, const Options< Index_, Float_, Matrix_ > &options)
Definition mnncorrect.hpp:149
std::shared_ptr< knncolle::Builder< Index_, Float_, Float_, Matrix_ > > builder
Definition mnncorrect.hpp:57