99#include " helper.hpp"
1010
1111void setup (pqxx::connection &conn) {
12- pqxx::nontransaction tx ( conn) ;
12+ pqxx::nontransaction tx{ conn} ;
1313 tx.exec (" CREATE EXTENSION IF NOT EXISTS vector" );
1414 tx.exec (" DROP TABLE IF EXISTS items" );
1515 tx.exec (" CREATE TABLE items (id serial PRIMARY KEY, embedding vector(3), half_embedding halfvec(3), binary_embedding bit(3), sparse_embedding sparsevec(3))" );
1616}
1717
1818void before_each (pqxx::connection &conn) {
19- pqxx::nontransaction tx ( conn) ;
19+ pqxx::nontransaction tx{ conn} ;
2020 tx.exec (" TRUNCATE items" );
2121}
2222
@@ -31,9 +31,9 @@ std::optional<std::string_view> float_error([[maybe_unused]] std::string_view me
3131void test_vector (pqxx::connection &conn) {
3232 before_each (conn);
3333
34- pqxx::nontransaction tx ( conn) ;
35- pgvector::Vector embedding ({ 1 , 2 , 3 }) ;
36- pgvector::Vector embedding2 ({ 4 , 5 , 6 }) ;
34+ pqxx::nontransaction tx{ conn} ;
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});
@@ -46,9 +46,9 @@ void test_vector(pqxx::connection &conn) {
4646void test_halfvec (pqxx::connection &conn) {
4747 before_each (conn);
4848
49- pqxx::nontransaction tx ( conn) ;
50- pgvector::HalfVector embedding ({ 1 , 2 , 3 }) ;
51- pgvector::HalfVector embedding2 ({ 4 , 5 , 6 }) ;
49+ pqxx::nontransaction tx{ conn} ;
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});
@@ -61,7 +61,7 @@ void test_halfvec(pqxx::connection &conn) {
6161void test_bit (pqxx::connection &conn) {
6262 before_each (conn);
6363
64- pqxx::nontransaction tx ( conn) ;
64+ pqxx::nontransaction tx{ conn} ;
6565 std::string embedding{" 101" };
6666 std::string embedding2{" 111" };
6767 tx.exec (" INSERT INTO items (binary_embedding) VALUES ($1), ($2), ($3)" , {embedding, embedding2, std::nullopt });
@@ -76,9 +76,9 @@ void test_bit(pqxx::connection &conn) {
7676void test_sparsevec (pqxx::connection &conn) {
7777 before_each (conn);
7878
79- pqxx::nontransaction tx ( conn) ;
80- pgvector::SparseVector embedding ({ 1 , 2 , 3 }) ;
81- pgvector::SparseVector embedding2 ({ 4 , 5 , 6 }) ;
79+ pqxx::nontransaction tx{ conn} ;
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});
@@ -91,9 +91,9 @@ void test_sparsevec(pqxx::connection &conn) {
9191void test_sparsevec_nnz (pqxx::connection &conn) {
9292 before_each (conn);
9393
94- pqxx::nontransaction tx ( conn) ;
94+ pqxx::nontransaction tx{ conn} ;
9595 std::vector<float > vec (16001 , 1 );
96- pgvector::SparseVector embedding ( 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" );
@@ -102,7 +102,7 @@ void test_sparsevec_nnz(pqxx::connection &conn) {
102102void test_stream (pqxx::connection &conn) {
103103 before_each (conn);
104104
105- pqxx::nontransaction tx ( conn) ;
105+ pqxx::nontransaction tx{ conn} ;
106106 pgvector::Vector embedding ({1 , 2 , 3 });
107107 tx.exec (" INSERT INTO items (embedding) VALUES ($1)" , {embedding});
108108 int count = 0 ;
@@ -116,10 +116,10 @@ void test_stream(pqxx::connection &conn) {
116116void test_stream_to (pqxx::connection &conn) {
117117 before_each (conn);
118118
119- pqxx::nontransaction tx ( conn) ;
119+ pqxx::nontransaction tx{ conn} ;
120120 pqxx::stream_to stream = pqxx::stream_to::table (tx, {" items" }, {" embedding" });
121- stream.write_values (pgvector::Vector ({ 1 , 2 , 3 }) );
122- stream.write_values (pgvector::Vector ({ 4 , 5 , 6 }) );
121+ stream.write_values (pgvector::Vector{{ 1 , 2 , 3 }} );
122+ stream.write_values (pgvector::Vector{{ 4 , 5 , 6 }} );
123123 stream.complete ();
124124 pqxx::result res = tx.exec (" SELECT embedding FROM items ORDER BY id" );
125125 assert_equal (res[0 ][0 ].as <std::string>(), " [1,2,3]" );
@@ -129,26 +129,26 @@ void test_stream_to(pqxx::connection &conn) {
129129void test_precision (pqxx::connection &conn) {
130130 before_each (conn);
131131
132- pqxx::nontransaction tx ( conn) ;
133- pgvector::Vector embedding ({ 1.23456789 , 0 , 0 }) ;
132+ pqxx::nontransaction tx{ conn} ;
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" );
137137 assert_equal (res[0 ][0 ].as <pgvector::Vector>(), embedding);
138138}
139139
140140void test_vector_to_string () {
141- assert_equal (pqxx::to_string (pgvector::Vector ({ 1 , 2 , 3 }) ), " [1,2,3]" );
142- assert_equal (pqxx::to_string (pgvector::Vector ({ -1.234567890123 }) ), " [-1.2345679]" );
141+ assert_equal (pqxx::to_string (pgvector::Vector{{ 1 , 2 , 3 }} ), " [1,2,3]" );
142+ assert_equal (pqxx::to_string (pgvector::Vector{{ -1.234567890123 }} ), " [-1.2345679]" );
143143
144144 assert_exception<pqxx::conversion_overrun>([] {
145145 pqxx::to_string (pgvector::Vector (std::vector<float >(16001 )));
146146 }, " vector cannot have more than 16000 dimensions" );
147147}
148148
149149void test_vector_from_string () {
150- assert_equal (pqxx::from_string<pgvector::Vector>(" [1,2,3]" ), pgvector::Vector ({ 1 , 2 , 3 }) );
151- assert_equal (pqxx::from_string<pgvector::Vector>(" []" ), pgvector::Vector ( std::vector<float >{}) );
150+ assert_equal (pqxx::from_string<pgvector::Vector>(" [1,2,3]" ), pgvector::Vector{{ 1 , 2 , 3 }} );
151+ assert_equal (pqxx::from_string<pgvector::Vector>(" []" ), pgvector::Vector{ std::vector<float >{}} );
152152
153153 assert_exception<pqxx::conversion_error>([] {
154154 auto _ = pqxx::from_string<pgvector::Vector>(" " );
@@ -178,9 +178,9 @@ void test_vector_from_string() {
178178void test_halfvec_to_string () {
179179 assert_equal (pqxx::to_string (pgvector::HalfVector ({1 , 2 , 3 })), " [1,2,3]" );
180180#if __STDCPP_FLOAT16_T__ || defined(__FLT16_MAX__)
181- assert_equal (pqxx::to_string (pgvector::HalfVector ({ static_cast <pgvector::Half>(-1.234567890123 )}) ), " [-1.234375]" );
181+ assert_equal (pqxx::to_string (pgvector::HalfVector{{ static_cast <pgvector::Half>(-1.234567890123 )}} ), " [-1.234375]" );
182182#else
183- assert_equal (pqxx::to_string (pgvector::HalfVector ({ -1.234567890123 }) ), " [-1.2345679]" );
183+ assert_equal (pqxx::to_string (pgvector::HalfVector{{ -1.234567890123 }} ), " [-1.2345679]" );
184184#endif
185185
186186 assert_exception<pqxx::conversion_overrun>([] {
@@ -189,8 +189,8 @@ void test_halfvec_to_string() {
189189}
190190
191191void test_halfvec_from_string () {
192- assert_equal (pqxx::from_string<pgvector::HalfVector>(" [1,2,3]" ), pgvector::HalfVector ({ 1 , 2 , 3 }) );
193- assert_equal (pqxx::from_string<pgvector::HalfVector>(" []" ), pgvector::HalfVector ( std::vector<pgvector::Half>{}) );
192+ assert_equal (pqxx::from_string<pgvector::HalfVector>(" [1,2,3]" ), pgvector::HalfVector{{ 1 , 2 , 3 }} );
193+ assert_equal (pqxx::from_string<pgvector::HalfVector>(" []" ), pgvector::HalfVector{ std::vector<pgvector::Half>{}} );
194194
195195 assert_exception<pqxx::conversion_error>([] {
196196 auto _ = pqxx::from_string<pgvector::HalfVector>(" " );
@@ -218,18 +218,18 @@ void test_halfvec_from_string() {
218218}
219219
220220void test_sparsevec_to_string () {
221- assert_equal (pqxx::to_string (pgvector::SparseVector ({ 1 , 0 , 2 , 0 , 3 , 0 }) ), " {1:1,3:2,5:3}/6" );
222- std::unordered_map<int , float > map = {{999999999 , -1.234567890123 }};
223- assert_equal (pqxx::to_string (pgvector::SparseVector ( map, 1000000000 ) ), " {1000000000:-1.2345679}/1000000000" );
221+ assert_equal (pqxx::to_string (pgvector::SparseVector{{ 1 , 0 , 2 , 0 , 3 , 0 }} ), " {1:1,3:2,5:3}/6" );
222+ std::unordered_map<int , float > map{{999999999 , -1.234567890123 }};
223+ assert_equal (pqxx::to_string (pgvector::SparseVector{ map, 1000000000 } ), " {1000000000:-1.2345679}/1000000000" );
224224
225225 assert_exception<pqxx::conversion_overrun>([] {
226226 pqxx::to_string (pgvector::SparseVector (std::vector<float >(16001 , 1 )));
227227 }, " sparsevec cannot have more than 16000 dimensions" );
228228}
229229
230230void test_sparsevec_from_string () {
231- assert_equal (pqxx::from_string<pgvector::SparseVector>(" {1:1,3:2,5:3}/6" ), pgvector::SparseVector ({ 1 , 0 , 2 , 0 , 3 , 0 }) );
232- assert_equal (pqxx::from_string<pgvector::SparseVector>(" {}/6" ), pgvector::SparseVector ({ 0 , 0 , 0 , 0 , 0 , 0 }) );
231+ assert_equal (pqxx::from_string<pgvector::SparseVector>(" {1:1,3:2,5:3}/6" ), pgvector::SparseVector{{ 1 , 0 , 2 , 0 , 3 , 0 }} );
232+ assert_equal (pqxx::from_string<pgvector::SparseVector>(" {}/6" ), pgvector::SparseVector{{ 0 , 0 , 0 , 0 , 0 , 0 }} );
233233
234234 assert_exception<pqxx::conversion_error>([] {
235235 auto _ = pqxx::from_string<pgvector::SparseVector>(" " );
@@ -281,7 +281,7 @@ void test_sparsevec_from_string() {
281281}
282282
283283void test_pqxx () {
284- pqxx::connection conn ( " dbname=pgvector_cpp_test" ) ;
284+ pqxx::connection conn{ " dbname=pgvector_cpp_test" } ;
285285 setup (conn);
286286
287287 test_vector (conn);
0 commit comments