91 randomType & rng, Matrix
const & matrix,
93 bool const keep_corners =
true
96 if(matrix.size1() <= n){
99 Matrix sampledMatrix(n, matrix.size2());
100 std::set<std::size_t> added_rows;
103 for(std::size_t row = 0; row < matrix.size1(); ++row){
104 if(detail::isLatticeCorner(matrix.major_begin(row), matrix.major_end(row))){
105 added_rows.insert(row);
109 while(added_rows.size() < n){
111 added_rows.insert(
random::discrete(rng, std::size_t(0), matrix.size1() - 1));
114 for(std::size_t major_idx : added_rows)
117 matrix.major_begin(major_idx), matrix.major_end(major_idx),
118 sampledMatrix.major_begin(i)
122 return sampledMatrix;
176 Matrix
const & m, std::size_t
const n){
177 const RealMatrix distances = distanceSqr(m, m);
178 UIntMatrix neighbourIndices(m.size1(), n);
180 for(std::size_t i = 0; i < m.size1(); ++i)
183 std::vector<std::size_t> indices(distances.size2());
184 std::iota(indices.begin(), indices.end(), 0);
186 std::sort(indices.begin(), indices.end(),
187 [&](std::size_t a, std::size_t b)
189 return distances(i, a) < distances(i, b);
192 std::copy_n(indices.begin(), n, neighbourIndices.major_begin(i));
194 return neighbourIndices;