Skip to content

Commit c7fadb2

Browse files
committed
Renamed HalfType to Half
1 parent 0b94a20 commit c7fadb2

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

include/pgvector/halfvec.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,35 @@
1919
namespace pgvector {
2020

2121
#if __STDCPP_FLOAT16_T__
22-
using HalfType = std::float16_t;
22+
using Half = std::float16_t;
2323
#else
24-
using HalfType = float;
24+
using Half = float;
2525
#endif
2626

2727
/// A half vector.
2828
class HalfVector {
2929
public:
30-
/// Creates a half vector from a `std::vector<pgvector::HalfType>`.
31-
explicit HalfVector(const std::vector<HalfType>& value) : value_{value} {}
30+
/// Creates a half vector from a `std::vector<pgvector::Half>`.
31+
explicit HalfVector(const std::vector<Half>& value) : value_{value} {}
3232

33-
/// Creates a half vector from a `std::vector<pgvector::HalfType>`.
34-
explicit HalfVector(std::vector<HalfType>&& value) : value_{std::move(value)} {}
33+
/// Creates a half vector from a `std::vector<pgvector::Half>`.
34+
explicit HalfVector(std::vector<Half>&& value) : value_{std::move(value)} {}
3535

3636
/// Creates a half vector from a span.
37-
explicit HalfVector(std::span<const HalfType> value) : value_{std::vector<HalfType>(value.begin(), value.end())} {}
37+
explicit HalfVector(std::span<const Half> value) : value_{std::vector<Half>(value.begin(), value.end())} {}
3838

3939
/// Returns the number of dimensions.
4040
size_t dimensions() const {
4141
return value_.size();
4242
}
4343

44-
/// Returns the half vector as a `std::vector<pgvector::HalfType>`.
45-
operator const std::vector<HalfType>() const {
44+
/// Returns the half vector as a `std::vector<pgvector::Half>`.
45+
operator const std::vector<Half>() const {
4646
return value_;
4747
}
4848

49-
/// Returns the half vector as a `std::span<const pgvector::HalfType>`.
50-
operator const std::span<const HalfType>() const {
49+
/// Returns the half vector as a `std::span<const pgvector::Half>`.
50+
operator const std::span<const Half>() const {
5151
return value_;
5252
}
5353

@@ -68,6 +68,6 @@ class HalfVector {
6868
}
6969

7070
private:
71-
std::vector<HalfType> value_;
71+
std::vector<Half> value_;
7272
};
7373
} // namespace pgvector

include/pgvector/pqxx.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,23 @@ template <> struct string_traits<pgvector::HalfVector> {
9393
throw conversion_error("Malformed halfvec literal");
9494
}
9595

96-
std::vector<pgvector::HalfType> values;
96+
std::vector<pgvector::Half> values;
9797
if (text.size() > 2) {
9898
std::string_view inner = text.substr(1, text.size() - 2);
9999
size_t start = 0;
100100
for (size_t i = 0; i < inner.size(); i++) {
101101
if (inner[i] == ',') {
102-
values.push_back(static_cast<pgvector::HalfType>(string_traits<float>::from_string(inner.substr(start, i - start), c)));
102+
values.push_back(static_cast<pgvector::Half>(string_traits<float>::from_string(inner.substr(start, i - start), c)));
103103
start = i + 1;
104104
}
105105
}
106-
values.push_back(static_cast<pgvector::HalfType>(string_traits<float>::from_string(inner.substr(start), c)));
106+
values.push_back(static_cast<pgvector::Half>(string_traits<float>::from_string(inner.substr(start), c)));
107107
}
108108
return pgvector::HalfVector(std::move(values));
109109
}
110110

111111
static std::string_view to_buf(std::span<char> buf, const pgvector::HalfVector& value, ctx c = {}) {
112-
std::span<const pgvector::HalfType> values{value};
112+
std::span<const pgvector::Half> values{value};
113113

114114
// important! size_buffer cannot throw an exception on overflow
115115
// so perform this check before writing any data
@@ -133,7 +133,7 @@ template <> struct string_traits<pgvector::HalfVector> {
133133
}
134134

135135
static size_t size_buffer(const pgvector::HalfVector& value) noexcept {
136-
std::span<const pgvector::HalfType> values{value};
136+
std::span<const pgvector::Half> values{value};
137137

138138
// cannot throw an exception here on overflow
139139
// so throw in into_buf

test/halfvec_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static void test_constructor_vector() {
1212
}
1313

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

test/pqxx_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void test_halfvec(pqxx::connection &conn) {
4949

5050
pqxx::nontransaction tx(conn);
5151
auto embedding = pgvector::HalfVector({1, 2, 3});
52-
pgvector::HalfType arr[] = {4, 5, 6};
52+
pgvector::Half arr[] = {4, 5, 6};
5353
auto embedding2 = pgvector::HalfVector(std::span{arr, 3});
5454
tx.exec("INSERT INTO items (half_embedding) VALUES ($1), ($2), ($3)", {embedding, embedding2, std::nullopt});
5555

@@ -186,13 +186,13 @@ void test_halfvec_to_string() {
186186
#endif
187187

188188
assert_exception<pqxx::conversion_overrun>([] {
189-
pqxx::to_string(pgvector::HalfVector(std::vector<pgvector::HalfType>(16001)));
189+
pqxx::to_string(pgvector::HalfVector(std::vector<pgvector::Half>(16001)));
190190
}, "halfvec cannot have more than 16000 dimensions");
191191
}
192192

193193
void test_halfvec_from_string() {
194194
assert_equal(pqxx::from_string<pgvector::HalfVector>("[1,2,3]"), pgvector::HalfVector({1, 2, 3}));
195-
assert_equal(pqxx::from_string<pgvector::HalfVector>("[]"), pgvector::HalfVector(std::vector<pgvector::HalfType>{}));
195+
assert_equal(pqxx::from_string<pgvector::HalfVector>("[]"), pgvector::HalfVector(std::vector<pgvector::Half>{}));
196196

197197
assert_exception<pqxx::conversion_error>([] {
198198
auto _ = pqxx::from_string<pgvector::HalfVector>("");

0 commit comments

Comments
 (0)