@@ -167,12 +167,15 @@ static float[][] randomVectors(final int n, final int dimensions) {
167
167
}
168
168
169
169
static DTLV .usearch_init_options_t createOpts (final long dimensions ) {
170
+ DTLV .usearch_metric_t nullMetric = new DTLV .usearch_metric_t ();
171
+ nullMetric .zero ();
172
+ nullMetric .setNull ();
170
173
171
174
DTLV .usearch_init_options_t opts = new DTLV .usearch_init_options_t ();
172
175
opts .zero ();
173
176
174
177
opts .metric_kind (DTLV .usearch_metric_ip_k )
175
- .metric ((usearch_metric_t ) null )
178
+ .metric ((usearch_metric_t ) nullMetric )
176
179
.quantization (DTLV .usearch_scalar_f32_k )
177
180
.dimensions (dimensions )
178
181
.connectivity (3 )
@@ -202,87 +205,83 @@ static void expectNoError(PointerPointer<BytePointer> error, String message) {
202
205
}
203
206
204
207
static void testUsearchInit (int collSize , int dimensions ) {
205
- try {
206
- DTLV .usearch_init_options_t opts = createOpts (dimensions );
207
208
208
- expect (opts .metric_kind () == DTLV .usearch_metric_ip_k , "fail to get metric_kind" );
209
- expect (opts .quantization () == DTLV .usearch_scalar_f32_k , "fail to get quantization" );
210
- expect (opts .connectivity () == 3 , "fail to get connectivity" );
211
- expect (opts .dimensions () == dimensions , "fail to get dimensions" );
212
- expect (opts .expansion_add () == 40 , "fail to get expansion_add" );
213
- expect (opts .expansion_search () == 16 , "fail to get expansion_search" );
214
- expect (opts .multi () == false , "fail to get multi" );
209
+ DTLV .usearch_init_options_t opts = createOpts (dimensions );
215
210
216
- PointerPointer <BytePointer > error = new PointerPointer <BytePointer >(1 ).put ((BytePointer )null );
211
+ expect (opts .metric_kind () == DTLV .usearch_metric_ip_k , "fail to get metric_kind" );
212
+ expect (opts .quantization () == DTLV .usearch_scalar_f32_k , "fail to get quantization" );
213
+ expect (opts .connectivity () == 3 , "fail to get connectivity" );
214
+ expect (opts .dimensions () == dimensions , "fail to get dimensions" );
215
+ expect (opts .expansion_add () == 40 , "fail to get expansion_add" );
216
+ expect (opts .expansion_search () == 16 , "fail to get expansion_search" );
217
+ expect (opts .multi () == false , "fail to get multi" );
217
218
218
- System .out .println ("About to call usearch_init" );
219
- DTLV .usearch_index_t index = DTLV .usearch_init (opts , error );
220
- expect (index != null , "Failed to init index" );
221
- System .out .println ("Successfully called init" );
219
+ PointerPointer <BytePointer > error = new PointerPointer <>(1 );
222
220
223
- error .put (0 , (BytePointer ) null );
224
- DTLV .usearch_free (index , error );
225
- expectNoError (error , "Fail to free index" );
221
+ error .put (0 , (BytePointer ) null );
222
+ DTLV .usearch_index_t index = DTLV .usearch_init (opts , error );
223
+ System .out .println ("called init" );
224
+ expect (index != null , "Failed to init index" );
226
225
227
- error .put (0 , (BytePointer ) null );
228
- index = DTLV .usearch_init ( opts , error );
229
- expect ( index != null , "Failed to init index" );
226
+ error .put (0 , (BytePointer ) null );
227
+ DTLV .usearch_free ( index , error );
228
+ expectNoError ( error , "Fail to free index" );
230
229
231
- error .put (0 , (BytePointer ) null );
232
- long size = DTLV .usearch_size ( index , error );
233
- expect (size == 0 , "Failed to get index size " );
230
+ error .put (0 , (BytePointer ) null );
231
+ index = DTLV .usearch_init ( opts , error );
232
+ expect (index != null , "Failed to init index" );
234
233
235
- error .put (0 , (BytePointer ) null );
236
- long capacity = DTLV .usearch_capacity (index , error );
237
- expect (capacity == 0 , "Failed to get index capacity " );
234
+ error .put (0 , (BytePointer ) null );
235
+ long size = DTLV .usearch_size (index , error );
236
+ expect (size == 0 , "Failed to get index size " );
238
237
239
- error .put (0 , (BytePointer ) null );
240
- long dims = DTLV .usearch_dimensions (index , error );
241
- expect (dimensions == dims , "Failed to get index dimensions " );
238
+ error .put (0 , (BytePointer ) null );
239
+ long capacity = DTLV .usearch_capacity (index , error );
240
+ expect (capacity == 0 , "Failed to get index capacity " );
242
241
243
- error .put (0 , (BytePointer ) null );
244
- long connectivity = DTLV .usearch_connectivity (index , error );
245
- expect (connectivity == opts .connectivity (),
246
- "Failed to get index connectivity" );
242
+ error .put (0 , (BytePointer ) null );
243
+ long dims = DTLV .usearch_dimensions (index , error );
244
+ expect (dimensions == dims , "Failed to get index dimensions" );
247
245
248
- error .put (0 , (BytePointer ) null );
249
- DTLV .usearch_reserve (index , collSize , error );
250
- expectNoError (error , "Fail to reserve" );
246
+ error .put (0 , (BytePointer ) null );
247
+ long connectivity = DTLV .usearch_connectivity (index , error );
248
+ expect (connectivity == opts .connectivity (),
249
+ "Failed to get index connectivity" );
251
250
252
- error .put (0 , (BytePointer ) null );
253
- size = DTLV .usearch_size (index , error );
254
- expect ( size == 0 , "Failed to get index size " );
251
+ error .put (0 , (BytePointer ) null );
252
+ DTLV .usearch_reserve (index , collSize , error );
253
+ expectNoError ( error , "Fail to reserve " );
255
254
256
- error .put (0 , (BytePointer ) null );
257
- capacity = DTLV .usearch_capacity (index , error );
258
- expect (capacity >= collSize , "Failed to get index capacity " );
255
+ error .put (0 , (BytePointer ) null );
256
+ size = DTLV .usearch_size (index , error );
257
+ expect (size == 0 , "Failed to get index size " );
259
258
260
- error .put (0 , (BytePointer ) null );
261
- dims = DTLV .usearch_dimensions (index , error );
262
- expect (dimensions == dims , "Failed to get index dimensions " );
259
+ error .put (0 , (BytePointer ) null );
260
+ capacity = DTLV .usearch_capacity (index , error );
261
+ expect (capacity >= collSize , "Failed to get index capacity " );
263
262
264
- error .put (0 , (BytePointer ) null );
265
- connectivity = DTLV .usearch_connectivity (index , error );
266
- expect (connectivity == opts .connectivity (),
267
- "Failed to get index connectivity" );
263
+ error .put (0 , (BytePointer ) null );
264
+ dims = DTLV .usearch_dimensions (index , error );
265
+ expect (dimensions == dims , "Failed to get index dimensions" );
268
266
269
- error .put (0 , (BytePointer ) null );
270
- BytePointer hardware = DTLV .usearch_hardware_acceleration (index , error );
271
- expectNoError ( error , "Fail to get hardware" );
272
- System . out . println ( "SIMD Hardware ISA Name is: " + hardware . getString () );
267
+ error .put (0 , (BytePointer ) null );
268
+ connectivity = DTLV .usearch_connectivity (index , error );
269
+ expect ( connectivity == opts . connectivity (),
270
+ "Failed to get index connectivity" );
273
271
274
- error .put (0 , (BytePointer ) null );
275
- long memory = DTLV .usearch_memory_usage (index , error );
276
- expect ( memory > 0 , "Failed to get memory usage " );
277
- System .out .println ("Memory Usage is: " + memory );
272
+ error .put (0 , (BytePointer ) null );
273
+ BytePointer hardware = DTLV .usearch_hardware_acceleration (index , error );
274
+ expectNoError ( error , "Fail to get hardware " );
275
+ System .out .println ("SIMD Hardware ISA Name is: " + hardware . getString () );
278
276
279
- error .put (0 , (BytePointer ) null );
280
- DTLV .usearch_free (index , error );
281
- expectNoError (error , "Fail to free index" );
282
- } catch (Exception e ) {
283
- System .out .println ("Java exception: " + e .getMessage ());
284
- e .printStackTrace ();
285
- }
277
+ error .put (0 , (BytePointer ) null );
278
+ long memory = DTLV .usearch_memory_usage (index , error );
279
+ expect (memory > 0 , "Failed to get memory usage" );
280
+ System .out .println ("Memory Usage is: " + memory );
281
+
282
+ error .put (0 , (BytePointer ) null );
283
+ DTLV .usearch_free (index , error );
284
+ expectNoError (error , "Fail to free index" );
286
285
287
286
System .out .println ("Passed init." );
288
287
}
0 commit comments