Skip to content

Commit 0ca74f7

Browse files
lums658ihnorton
authored andcommitted
Cleanup and clang-format [skip ci]
1 parent b984fe2 commit 0ca74f7

File tree

14 files changed

+160
-146
lines changed

14 files changed

+160
-146
lines changed

src/include/detail/ivf/qv.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@
4141
#include "flat_query.h"
4242
#include "linalg.h"
4343

44-
4544
namespace detail::ivf {
4645

4746
/**
48-
* Overload for already opened arrays. Since the array is already opened, we don't need
49-
* to specify its type with a template parameter.
47+
* Overload for already opened arrays. Since the array is already opened, we
48+
* don't need to specify its type with a template parameter.
5049
*/
5150
auto qv_query_heap_infinite_ram(
5251
auto&& shuffled_db,
@@ -77,7 +76,6 @@ auto qv_query_heap_infinite_ram(
7776
bool nth,
7877
size_t nthreads);
7978

80-
8179
/**
8280
* @brief Query a (small) set of query vectors against a vector database.
8381
* This version loads the entire partition array into memory and then
@@ -99,7 +97,6 @@ auto qv_query_heap_infinite_ram(
9997
size_t nthreads) {
10098
scoped_timer _{tdb_func__};
10199

102-
103100
// Read the shuffled database and ids
104101
// @todo To this more systematically
105102
auto shuffled_db = tdbColMajorMatrix<T>(ctx, part_uri);
@@ -117,7 +114,6 @@ auto qv_query_heap_infinite_ram(
117114
nthreads);
118115
}
119116

120-
121117
auto qv_query_heap_infinite_ram(
122118
const std::string& part_uri,
123119
auto&& centroids,
@@ -233,8 +229,10 @@ auto qv_query_heap_finite_ram(
233229
size_t nthreads) {
234230
scoped_timer _{tdb_func__};
235231

236-
using parts_type = typename std::remove_reference_t<decltype(centroids)>::value_type;
237-
using indices_type = typename std::remove_reference_t<decltype(indices)>::value_type;
232+
using parts_type =
233+
typename std::remove_reference_t<decltype(centroids)>::value_type;
234+
using indices_type =
235+
typename std::remove_reference_t<decltype(indices)>::value_type;
238236

239237
size_t num_queries = size(q);
240238

@@ -287,7 +285,11 @@ auto qv_query_heap_finite_ram(
287285
indices[active_partitions[i]];
288286
}
289287

290-
auto shuffled_db = tdbColMajorPartitionedMatrix<T, shuffled_ids_type, indices_type, parts_type>(
288+
auto shuffled_db = tdbColMajorPartitionedMatrix<
289+
T,
290+
shuffled_ids_type,
291+
indices_type,
292+
parts_type>(
291293
ctx,
292294
part_uri,
293295
std::move(indices),
@@ -300,10 +302,13 @@ auto qv_query_heap_finite_ram(
300302
for (size_t i = 0; i < size(new_indices) - 1; ++i) {
301303
auto partition_size = new_indices[i + 1] - new_indices[i];
302304
max_partition_size = std::max<size_t>(max_partition_size, partition_size);
303-
_memory_data.insert_entry(tdb_func__ + " (predicted)", partition_size * sizeof(T) * shuffled_db.num_rows());
305+
_memory_data.insert_entry(
306+
tdb_func__ + " (predicted)",
307+
partition_size * sizeof(T) * shuffled_db.num_rows());
304308
}
305-
_memory_data.insert_entry(tdb_func__ + " (upper bound)", nprobe * num_queries * sizeof(T) * max_partition_size);
306-
309+
_memory_data.insert_entry(
310+
tdb_func__ + " (upper bound)",
311+
nprobe * num_queries * sizeof(T) * max_partition_size);
307312

308313
assert(shuffled_db.num_cols() == size(shuffled_db.ids()));
309314

src/include/detail/linalg/matrix.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ std::string matrix_info(const Matrix& A, const std::string& msg = "") {
272272
return str;
273273
}
274274

275-
276-
277-
/**********************************************************************
275+
/**********************************************************************
278276
*
279277
* Some debugging utilities.
280278
*

src/include/detail/linalg/tdb_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
#include <tiledb/tiledb>
3636
#include "detail/linalg/matrix.h"
37-
#include "utils/timer.h"
3837
#include "utils/logging.h"
38+
#include "utils/timer.h"
3939

4040
/**
4141
* Write the contents of a Matrix to a TileDB array.

src/include/detail/linalg/tdb_matrix.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
6969
constexpr static auto matrix_order_{order_v<LayoutPolicy>};
7070

7171
private:
72-
7372
log_timer constructor_timer{"tdbMatrix constructor"};
7473

7574
std::reference_wrapper<const tiledb::Context> ctx_;
@@ -101,10 +100,8 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
101100
tdbMatrix(
102101
const tiledb::Context& ctx,
103102
const std::string& uri,
104-
size_t num_elts) noexcept requires(std::
105-
is_same_v<
106-
LayoutPolicy,
107-
stdx::layout_right>)
103+
size_t num_elts) noexcept
104+
requires(std::is_same_v<LayoutPolicy, stdx::layout_right>)
108105
: tdbMatrix(ctx, uri, num_elts, 0) {
109106
}
110107

@@ -120,10 +117,8 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
120117
tdbMatrix(
121118
const tiledb::Context& ctx,
122119
const std::string& uri,
123-
size_t num_elts) noexcept requires(std::
124-
is_same_v<
125-
LayoutPolicy,
126-
stdx::layout_left>)
120+
size_t num_elts) noexcept
121+
requires(std::is_same_v<LayoutPolicy, stdx::layout_left>)
127122
: tdbMatrix(ctx, uri, 0, num_elts) {
128123
}
129124

@@ -206,7 +201,6 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
206201
: ctx_{ctx}
207202
, array_{ctx, uri, TILEDB_READ}
208203
, schema_{array_.schema()} {
209-
210204
constructor_timer.stop();
211205
scoped_timer _{tdb_func__ + uri};
212206

@@ -273,10 +267,11 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
273267
}
274268

275269
// Create a subarray that reads the array up to the specified subset.
276-
std::vector<int32_t> subarray_vals = {(int32_t)row_begin,
277-
(int32_t)row_end - 1,
278-
(int32_t)col_begin,
279-
(int32_t)col_end - 1};
270+
std::vector<int32_t> subarray_vals = {
271+
(int32_t)row_begin,
272+
(int32_t)row_end - 1,
273+
(int32_t)col_begin,
274+
(int32_t)col_end - 1};
280275
tiledb::Subarray subarray(ctx_, array_);
281276
subarray.set_subarray(subarray_vals);
282277

@@ -290,7 +285,6 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
290285
query.submit();
291286
_memory_data.insert_entry(tdb_func__, num_rows * num_cols * sizeof(T));
292287

293-
294288
// assert(tiledb::Query::Status::COMPLETE == query.query_status());
295289
if (tiledb::Query::Status::COMPLETE != query.query_status()) {
296290
throw std::runtime_error("Query status is not complete -- fix me");
@@ -385,10 +379,11 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
385379
size_t num_elements = len * dimension;
386380

387381
// Create a subarray that reads the array up to the specified subset.
388-
std::vector<int32_t> subarray_vals = {(int32_t)0,
389-
(int32_t)dimension - 1,
390-
(int32_t)start,
391-
(int32_t)stop - 1};
382+
std::vector<int32_t> subarray_vals = {
383+
(int32_t)0,
384+
(int32_t)dimension - 1,
385+
(int32_t)start,
386+
(int32_t)stop - 1};
392387
tiledb::Subarray subarray(ctx_, array_);
393388
subarray.set_subarray(subarray_vals);
394389

@@ -403,7 +398,6 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
403398
query.submit();
404399
_memory_data.insert_entry(tdb_func__, num_elements * sizeof(T));
405400

406-
407401
// assert(tiledb::Query::Status::COMPLETE == query.query_status());
408402
if (tiledb::Query::Status::COMPLETE != query.query_status()) {
409403
throw std::runtime_error("Query status is not complete -- fix me");
@@ -446,8 +440,8 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
446440
size_t num_elements = len;
447441

448442
// Create a subarray that reads the array up to the specified subset.
449-
std::vector<int32_t> subarray_vals = {(int32_t)start,
450-
(int32_t)stop - 1};
443+
std::vector<int32_t> subarray_vals = {
444+
(int32_t)start, (int32_t)stop - 1};
451445
tiledb::Subarray subarray(ctx_, ids_array_);
452446
subarray.set_subarray(subarray_vals);
453447

@@ -458,7 +452,6 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
458452
query.submit();
459453
_memory_data.insert_entry(tdb_func__, num_elements * sizeof(T));
460454

461-
462455
if (tiledb::Query::Status::COMPLETE != query.query_status()) {
463456
throw std::runtime_error("Query status is not complete -- fix me");
464457
}
@@ -538,10 +531,11 @@ class tdbMatrix : public Matrix<T, LayoutPolicy, I> {
538531
}
539532

540533
// Create a subarray that reads the array with the specified view
541-
std::vector<int32_t> subarray_vals = {(int32_t)std::get<0>(row_view_),
542-
(int32_t)std::get<1>(row_view_) - 1,
543-
(int32_t)std::get<0>(col_view_),
544-
(int32_t)std::get<1>(col_view_) - 1};
534+
std::vector<int32_t> subarray_vals = {
535+
(int32_t)std::get<0>(row_view_),
536+
(int32_t)std::get<1>(row_view_) - 1,
537+
(int32_t)std::get<0>(col_view_),
538+
(int32_t)std::get<1>(col_view_) - 1};
545539
tiledb::Subarray subarray(ctx_, array_);
546540
subarray.set_subarray(subarray_vals);
547541

src/include/detail/linalg/tdb_partitioned_matrix.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class tdbPartitionedMatrix : public Matrix<T, LayoutPolicy, I> {
279279
*/
280280
std::get<0>(col_view_) = std::get<1>(col_view_); // # columns
281281
std::get<0>(col_part_view_) =
282-
std::get<1>(col_part_view_); // # partitions
282+
std::get<1>(col_part_view_); // # partitions
283283

284284
std::get<1>(col_part_view_) = std::get<0>(col_part_view_);
285285
for (size_t i = std::get<0>(col_part_view_); i < total_num_parts_; ++i) {
@@ -437,8 +437,13 @@ template <
437437
class indices_type,
438438
class parts_type,
439439
class I = size_t>
440-
using tdbRowMajorPartitionedMatrix =
441-
tdbPartitionedMatrix<T, shuffled_ids_type, indices_type, parts_type, stdx::layout_right, I>;
440+
using tdbRowMajorPartitionedMatrix = tdbPartitionedMatrix<
441+
T,
442+
shuffled_ids_type,
443+
indices_type,
444+
parts_type,
445+
stdx::layout_right,
446+
I>;
442447

443448
/**
444449
* Convenience class for column-major matrices.
@@ -449,7 +454,12 @@ template <
449454
class indices_type,
450455
class parts_type,
451456
class I = size_t>
452-
using tdbColMajorPartitionedMatrix =
453-
tdbPartitionedMatrix<T, shuffled_ids_type, indices_type, parts_type, stdx::layout_left, I>;
457+
using tdbColMajorPartitionedMatrix = tdbPartitionedMatrix<
458+
T,
459+
shuffled_ids_type,
460+
indices_type,
461+
parts_type,
462+
stdx::layout_left,
463+
I>;
454464

455465
#endif // TILEDB_PARTITIONED_MATRIX_H

src/include/fixed_min_queues.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
*
2828
* @section DESCRIPTION
2929
*
30-
* Contains two implementations of a fixed-size min-heap (to experiment with potential performance differences).
31-
* Also contains an implementation of a fixed_size min-heap for pairs.
30+
* Contains two implementations of a fixed-size min-heap (to experiment with
31+
* potential performance differences). Also contains an implementation of a
32+
* fixed_size min-heap for pairs.
3233
*
3334
* This type of heap is used to maintain the top k small scores as we compute
3435
* scores during similarity search.
@@ -149,7 +150,8 @@ class fixed_min_pair_heap : public std::vector<std::tuple<T, U>> {
149150
template <class T>
150151
using fixed_min_heap = fixed_min_set_heap_1<T>;
151152

152-
#ifdef ALLHEAPS // Kept here for historical comparison reasons. They are really slow.
153+
#ifdef ALLHEAPS // Kept here for historical comparison reasons. They are
154+
// really slow.
153155
template <class T, class Compare = std::less<T>>
154156
class fixed_min_set_heap_3 : public std::vector<T> {
155157
using Base = std::vector<T>;

src/include/ivf_index.h

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,12 @@
5353
#include <thread>
5454

5555
#include "algorithm.h"
56-
#include "array_types.h"
5756
#include "defs.h"
5857
#include "linalg.h"
5958

6059
#include "detail/flat/qv.h"
6160

62-
template <class T = shuffled_db_type>
61+
template <class T, class shuffled_ids_type, class indices_type>
6362
class kmeans_index {
6463
// Random device to seed the random number generator
6564
std::random_device rd;
@@ -73,7 +72,7 @@ class kmeans_index {
7372

7473
ColMajorMatrix<T> centroids_;
7574
std::vector<indices_type> indices_;
76-
std::vector<indices_type> shuffled_ids_;
75+
std::vector<shuffled_ids_type> shuffled_ids_;
7776
ColMajorMatrix<T> shuffled_db_;
7877

7978
public:
@@ -258,7 +257,6 @@ class kmeans_index {
258257

259258
// @todo parallelize
260259

261-
262260
for (size_t j = 0; j < nlist_; ++j) {
263261
auto centroid = centroids_[j];
264262
for (size_t k = 0; k < dimension_; ++k) {
@@ -271,32 +269,32 @@ class kmeans_index {
271269

272270
// Debugging
273271
#ifdef _SAVE_PARTITIONS
274-
{
275-
char tempFileName[L_tmpnam];
276-
tmpnam(tempFileName);
277-
278-
std::ofstream file(tempFileName);
279-
if (!file) {
280-
std::cout << "Error opening the file." << std::endl;
281-
return;
282-
}
272+
{
273+
char tempFileName[L_tmpnam];
274+
tmpnam(tempFileName);
275+
276+
std::ofstream file(tempFileName);
277+
if (!file) {
278+
std::cout << "Error opening the file." << std::endl;
279+
return;
280+
}
283281

284-
for (const auto& element : degrees) {
285-
file << element << ',';
286-
}
287-
file << std::endl;
282+
for (const auto& element : degrees) {
283+
file << element << ',';
284+
}
285+
file << std::endl;
288286

289-
file.close();
287+
file.close();
290288

291-
std::cout << "Data written to file: " << tempFileName << std::endl;
292-
}
293-
#endif
289+
std::cout << "Data written to file: " << tempFileName << std::endl;
294290
}
291+
#endif
292+
}
295293

296-
void train(const ColMajorMatrix<T>& training_set) {
297-
kmeans_pp(training_set);
298-
train_no_init(training_set);
299-
}
294+
void train(const ColMajorMatrix<T>& training_set) {
295+
kmeans_pp(training_set);
296+
train_no_init(training_set);
297+
}
300298

301299
#if 0
302300
// @todo WIP
@@ -338,9 +336,9 @@ class kmeans_index {
338336
}
339337
#endif
340338

341-
auto& get_centroids() {
342-
return centroids_;
343-
}
344-
};
339+
auto& get_centroids() {
340+
return centroids_;
341+
}
342+
};
345343

346-
#endif // TILEDB_IVF_INDEX_H
344+
#endif // TILEDB_IVF_INDEX_H

src/include/ivf_query.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#ifndef TDB_IVF_QUERY_H
3535
#define TDB_IVF_QUERY_H
3636

37-
3837
#include "detail/ivf/gemm.h"
3938
#include "detail/ivf/qv.h"
4039
#include "detail/ivf/vq.h"

0 commit comments

Comments
 (0)