Skip to content

Commit cc35e6f

Browse files
committed
Updated style [skip ci]
1 parent 15fd0f3 commit cc35e6f

5 files changed

Lines changed: 28 additions & 28 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ tx.exec("CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))");
6161
Insert a vector
6262

6363
```cpp
64-
auto embedding = pgvector::Vector({1, 2, 3});
64+
pgvector::Vector embedding({1, 2, 3});
6565
tx.exec("INSERT INTO items (embedding) VALUES ($1)", {embedding});
6666
```
6767
@@ -87,7 +87,7 @@ Use `std::optional<pgvector::Vector>` if the value could be `NULL`
8787
Create a vector from a `std::vector<float>`
8888

8989
```cpp
90-
auto vec = pgvector::Vector({1, 2, 3});
90+
pgvector::Vector vec(std::vector<float>{1, 2, 3});
9191
```
9292
9393
Convert to a `std::vector<float>`
@@ -101,7 +101,7 @@ auto float_vec = static_cast<std::vector<float>>(vec);
101101
Create a half vector from a `std::vector<float>`
102102

103103
```cpp
104-
auto vec = pgvector::HalfVector({1, 2, 3});
104+
pgvector::HalfVector vec(std::vector<float>{1, 2, 3});
105105
```
106106
107107
Convert to a `std::vector<float>`
@@ -115,14 +115,14 @@ auto float_vec = static_cast<std::vector<float>>(vec);
115115
Create a sparse vector from a `std::vector<float>`
116116

117117
```cpp
118-
auto vec = pgvector::SparseVector({1, 0, 2, 0, 3, 0});
118+
pgvector::SparseVector vec({1, 0, 2, 0, 3, 0});
119119
```
120120
121121
Or a map of non-zero elements
122122
123123
```cpp
124-
std::unordered_map<int, float> map = {{0, 1}, {2, 2}, {4, 3}};
125-
auto vec = pgvector::SparseVector(map, 6);
124+
std::unordered_map<int, float> map{{0, 1}, {2, 2}, {4, 3}};
125+
pgvector::SparseVector vec(map, 6);
126126
```
127127

128128
Note: Indices start at 0

test/halfvec_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
using pgvector::HalfVector;
88

99
static void test_constructor_vector() {
10-
auto vec = HalfVector(std::vector<pgvector::Half>{1, 2, 3});
10+
HalfVector vec(std::vector<pgvector::Half>{1, 2, 3});
1111
assert_equal(vec.dimensions(), 3u);
1212
}
1313

1414
static void test_constructor_span() {
15-
auto vec = HalfVector(std::span<const pgvector::Half>({1, 2, 3}));
15+
HalfVector vec(std::span<const pgvector::Half>{{1, 2, 3}});
1616
assert_equal(vec.dimensions(), 3u);
1717
}
1818

1919
static void test_as_vector() {
20-
auto vec = HalfVector({1, 2, 3});
20+
HalfVector vec({1, 2, 3});
2121
assert_equal(vec.as_vector() == std::vector<pgvector::Half>{1, 2, 3}, true);
2222
}
2323

test/pqxx_test.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ void test_vector(pqxx::connection &conn) {
3232
before_each(conn);
3333

3434
pqxx::nontransaction tx(conn);
35-
auto embedding = pgvector::Vector({1, 2, 3});
36-
auto embedding2 = pgvector::Vector({4, 5, 6});
35+
pgvector::Vector embedding({1, 2, 3});
36+
pgvector::Vector embedding2({4, 5, 6});
3737
tx.exec("INSERT INTO items (embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
3838

3939
pqxx::result res = tx.exec("SELECT embedding FROM items ORDER BY embedding <-> $1", {embedding2});
@@ -47,8 +47,8 @@ void test_halfvec(pqxx::connection &conn) {
4747
before_each(conn);
4848

4949
pqxx::nontransaction tx(conn);
50-
auto embedding = pgvector::HalfVector({1, 2, 3});
51-
auto embedding2 = pgvector::HalfVector({4, 5, 6});
50+
pgvector::HalfVector embedding({1, 2, 3});
51+
pgvector::HalfVector embedding2({4, 5, 6});
5252
tx.exec("INSERT INTO items (half_embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
5353

5454
pqxx::result res = tx.exec("SELECT half_embedding FROM items ORDER BY half_embedding <-> $1", {embedding2});
@@ -62,8 +62,8 @@ void test_bit(pqxx::connection &conn) {
6262
before_each(conn);
6363

6464
pqxx::nontransaction tx(conn);
65-
std::string embedding = "101";
66-
std::string embedding2 = "111";
65+
std::string embedding{"101"};
66+
std::string embedding2{"111"};
6767
tx.exec("INSERT INTO items (binary_embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
6868

6969
pqxx::result res = tx.exec("SELECT binary_embedding FROM items ORDER BY binary_embedding <~> $1", pqxx::params{embedding2});
@@ -77,8 +77,8 @@ void test_sparsevec(pqxx::connection &conn) {
7777
before_each(conn);
7878

7979
pqxx::nontransaction tx(conn);
80-
auto embedding = pgvector::SparseVector({1, 2, 3});
81-
auto embedding2 = pgvector::SparseVector({4, 5, 6});
80+
pgvector::SparseVector embedding({1, 2, 3});
81+
pgvector::SparseVector embedding2({4, 5, 6});
8282
tx.exec("INSERT INTO items (sparse_embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
8383

8484
pqxx::result res = tx.exec("SELECT sparse_embedding FROM items ORDER BY sparse_embedding <-> $1", {embedding2});
@@ -93,7 +93,7 @@ void test_sparsevec_nnz(pqxx::connection &conn) {
9393

9494
pqxx::nontransaction tx(conn);
9595
std::vector<float> vec(16001, 1);
96-
auto embedding = pgvector::SparseVector(vec);
96+
pgvector::SparseVector embedding(vec);
9797
assert_exception<pqxx::conversion_overrun>([&] {
9898
tx.exec("INSERT INTO items (sparse_embedding) VALUES ($1)", {embedding});
9999
}, "sparsevec cannot have more than 16000 dimensions");
@@ -103,7 +103,7 @@ void test_stream(pqxx::connection &conn) {
103103
before_each(conn);
104104

105105
pqxx::nontransaction tx(conn);
106-
auto embedding = pgvector::Vector({1, 2, 3});
106+
pgvector::Vector embedding({1, 2, 3});
107107
tx.exec("INSERT INTO items (embedding) VALUES ($1)", {embedding});
108108
int count = 0;
109109
for (auto [id, embedding2] : tx.stream<int, pgvector::Vector>("SELECT id, embedding FROM items WHERE embedding IS NOT NULL")) {
@@ -117,7 +117,7 @@ void test_stream_to(pqxx::connection &conn) {
117117
before_each(conn);
118118

119119
pqxx::nontransaction tx(conn);
120-
auto stream = pqxx::stream_to::table(tx, {"items"}, {"embedding"});
120+
pqxx::stream_to stream = pqxx::stream_to::table(tx, {"items"}, {"embedding"});
121121
stream.write_values(pgvector::Vector({1, 2, 3}));
122122
stream.write_values(pgvector::Vector({4, 5, 6}));
123123
stream.complete();
@@ -130,7 +130,7 @@ void test_precision(pqxx::connection &conn) {
130130
before_each(conn);
131131

132132
pqxx::nontransaction tx(conn);
133-
auto embedding = pgvector::Vector({1.23456789, 0, 0});
133+
pgvector::Vector embedding({1.23456789, 0, 0});
134134
tx.exec("INSERT INTO items (embedding) VALUES ($1)", {embedding});
135135
tx.exec("SET extra_float_digits = 3");
136136
pqxx::result res = tx.exec("SELECT embedding FROM items ORDER BY id DESC LIMIT 1");

test/sparsevec_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
using pgvector::SparseVector;
99

1010
static void test_constructor_vector() {
11-
auto vec = SparseVector(std::vector<float>{1, 0, 2, 0, 3, 0});
11+
SparseVector vec(std::vector<float>{1, 0, 2, 0, 3, 0});
1212
assert_equal(vec.dimensions(), 6);
1313
assert_equal(vec.indices() == std::vector<int>{0, 2, 4}, true);
1414
assert_equal(vec.values() == std::vector<float>{1, 2, 3}, true);
1515
}
1616

1717
static void test_constructor_span() {
18-
auto vec = SparseVector(std::span<const float>({1, 0, 2, 0, 3, 0}));
18+
SparseVector vec(std::span<const float>{{1, 0, 2, 0, 3, 0}});
1919
assert_equal(vec.dimensions(), 6);
2020
}
2121

2222
static void test_constructor_map() {
23-
std::unordered_map<int, float> map = {{2, 2}, {4, 3}, {3, 0}, {0, 1}};
24-
auto vec = SparseVector(map, 6);
23+
std::unordered_map<int, float> map{{2, 2}, {4, 3}, {3, 0}, {0, 1}};
24+
SparseVector vec(map, 6);
2525
assert_equal(vec.dimensions(), 6);
2626
assert_equal(vec.indices() == std::vector<int>{0, 2, 4}, true);
2727
assert_equal(vec.values() == std::vector<float>{1, 2, 3}, true);

test/vector_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
using pgvector::Vector;
88

99
static void test_constructor_vector() {
10-
auto vec = Vector(std::vector<float>{1, 2, 3});
10+
Vector vec(std::vector<float>{1, 2, 3});
1111
assert_equal(vec.dimensions(), 3u);
1212
}
1313

1414
static void test_constructor_span() {
15-
auto vec = Vector(std::span<const float>({1, 2, 3}));
15+
Vector vec(std::span<const float>{{1, 2, 3}});
1616
assert_equal(vec.dimensions(), 3u);
1717
}
1818

1919
static void test_as_vector() {
20-
auto vec = Vector({1, 2, 3});
20+
Vector vec({1, 2, 3});
2121
assert_equal(vec.as_vector() == std::vector<float>{1, 2, 3}, true);
2222
}
2323

0 commit comments

Comments
 (0)