Skip to content

Commit 07e8ce8

Browse files
committed
Improved constructors [skip ci]
1 parent 338bf32 commit 07e8ce8

File tree

4 files changed

+10
-44
lines changed

4 files changed

+10
-44
lines changed

include/pgvector/halfvec.hpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,18 @@ namespace pgvector {
1616
/// A half vector.
1717
class HalfVector {
1818
public:
19-
/// @private
20-
// TODO remove in 0.3.0
21-
HalfVector() = default;
22-
2319
/// Creates a half vector from a `std::vector<float>`.
24-
// TODO add explicit in 0.3.0
25-
HalfVector(const std::vector<float>& value) {
20+
explicit HalfVector(const std::vector<float>& value) {
2621
value_ = value;
2722
}
2823

2924
/// Creates a half vector from a `std::vector<float>`.
30-
// TODO add explicit in 0.3.0
31-
// TODO add noexcept in 0.3.0
32-
HalfVector(std::vector<float>&& value) {
25+
explicit HalfVector(std::vector<float>&& value) noexcept {
3326
value_ = std::move(value);
3427
}
3528

36-
/// Creates a half vector from an array.
37-
// TODO remove in 0.3.0
38-
HalfVector(const float* value, size_t n) {
39-
value_ = std::vector<float>{value, value + n};
40-
}
41-
4229
/// Creates a half vector from a span.
43-
// TODO add explicit in 0.3.0
44-
HalfVector(std::span<const float> value) {
30+
explicit HalfVector(std::span<const float> value) {
4531
value_ = std::vector<float>(value.begin(), value.end());
4632
}
4733

include/pgvector/sparsevec.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ namespace pgvector {
1818
/// A sparse vector.
1919
class SparseVector {
2020
public:
21-
/// @private
22-
// TODO remove in 0.3.0
23-
SparseVector() = default;
24-
2521
/// @private
2622
SparseVector(int dimensions, const std::vector<int>& indices, const std::vector<float>& values) {
2723
if (values.size() != indices.size()) {
@@ -33,8 +29,7 @@ class SparseVector {
3329
}
3430

3531
/// Creates a sparse vector from a dense vector.
36-
// TODO add explicit in 0.3.0
37-
SparseVector(const std::vector<float>& value) {
32+
explicit SparseVector(const std::vector<float>& value) {
3833
dimensions_ = value.size();
3934
for (size_t i = 0; i < value.size(); i++) {
4035
float v = value[i];
@@ -46,8 +41,7 @@ class SparseVector {
4641
}
4742

4843
/// Creates a sparse vector from a span.
49-
// TODO add explicit in 0.3.0
50-
SparseVector(std::span<const float> value) {
44+
explicit SparseVector(std::span<const float> value) {
5145
dimensions_ = value.size();
5246
for (size_t i = 0; i < value.size(); i++) {
5347
float v = value[i];

include/pgvector/vector.hpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,18 @@ namespace pgvector {
1616
/// A vector.
1717
class Vector {
1818
public:
19-
/// @private
20-
// TODO remove in 0.3.0
21-
Vector() = default;
22-
2319
/// Creates a vector from a `std::vector<float>`.
24-
// TODO add explicit in 0.3.0
25-
Vector(const std::vector<float>& value) {
20+
explicit Vector(const std::vector<float>& value) {
2621
value_ = value;
2722
}
2823

2924
/// Creates a vector from a `std::vector<float>`.
30-
// TODO add explicit in 0.3.0
31-
// TODO add noexcept in 0.3.0
32-
Vector(std::vector<float>&& value) {
25+
explicit Vector(std::vector<float>&& value) noexcept {
3326
value_ = std::move(value);
3427
}
3528

36-
/// Creates a vector from an array.
37-
// TODO remove in 0.3.0
38-
Vector(const float* value, size_t n) {
39-
value_ = std::vector<float>{value, value + n};
40-
}
41-
4229
/// Creates a vector from a span.
43-
// TODO add explicit in 0.3.0
44-
Vector(std::span<const float> value) {
30+
explicit Vector(std::span<const float> value) {
4531
value_ = std::vector<float>(value.begin(), value.end());
4632
}
4733

test/pqxx_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void test_vector(pqxx::connection &conn) {
2626
auto embedding = pgvector::Vector({1, 2, 3});
2727
assert(embedding.dimensions() == 3);
2828
float arr[] = {4, 5, 6};
29-
auto embedding2 = pgvector::Vector(arr, 3);
29+
auto embedding2 = pgvector::Vector(std::span{arr, 3});
3030
tx.exec("INSERT INTO items (embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
3131

3232
pqxx::result res = tx.exec("SELECT embedding FROM items ORDER BY embedding <-> $1", {embedding2});
@@ -43,7 +43,7 @@ void test_halfvec(pqxx::connection &conn) {
4343
auto embedding = pgvector::HalfVector({1, 2, 3});
4444
assert(embedding.dimensions() == 3);
4545
float arr[] = {4, 5, 6};
46-
auto embedding2 = pgvector::HalfVector(arr, 3);
46+
auto embedding2 = pgvector::HalfVector(std::span{arr, 3});
4747
tx.exec("INSERT INTO items (half_embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
4848

4949
pqxx::result res = tx.exec("SELECT half_embedding FROM items ORDER BY half_embedding <-> $1", {embedding2});

0 commit comments

Comments
 (0)