@@ -342,8 +342,7 @@ def test_searchsorted_with_scalars(data):
342342 raise
343343
344344
345- @pytest .mark .unvectorized
346- # TODO: Test with signed zeros and NaNs (and ignore them somehow)
345+ # TODO: min_version
347346@given (
348347 x = hh .arrays (
349348 dtype = hh .real_dtypes ,
@@ -354,23 +353,16 @@ def test_searchsorted_with_scalars(data):
354353 data = st .data ()
355354)
356355def test_top_k (x , mode_kw , data ,):
357-
358- # if dh.is_float_dtype(x.dtype):
359- # assume(not xp.any(x == -0.0) and not xp.any(x == +0.0))
360-
361356 # default axis=-1
362357 axis_kw = data .draw (hh .kwargs (axis = st .integers (- x .ndim , x .ndim - 1 )))
363358 axis = axis_kw .get ('axis' , - 1 )
364359
365360 k = data .draw (st .integers (1 , x .shape [axis ]))
366361
367362 repro_snippet = ph .format_snippet (
368- f"xp.top_k(x, k , **axis_kw, **mode_kw) with { axis_kw = } and { mode_kw = } "
363+ f"xp.top_k({ x !r } , { k } , **axis_kw, **mode_kw) with { axis_kw = } and { mode_kw = } "
369364 )
370365 try :
371-
372- print (x .dtype , k , axis , axis_kw , mode_kw )
373-
374366 out_values , out_indices = xp .top_k (x , k , ** axis_kw , ** mode_kw )
375367
376368 ph .assert_dtype ("top_k" , in_dtype = x .dtype , out_dtype = out_values .dtype )
@@ -388,60 +380,7 @@ def test_top_k(x, mode_kw, data,):
388380 out_shape = arr .shape ,
389381 expected = x .shape [:axes ] + (k ,) + x .shape [axes + 1 :],
390382 )
391-
392- # TODO: test values
393-
394-
383+ # TODO: values testing, test with signed zeros and NaNs
395384 except Exception as exc :
396385 ph .add_note (exc , repro_snippet )
397386 raise
398-
399-
400- """
401- scalar_type = dh.get_scalar_type(x.dtype)
402-
403- for indices in sh.axes_ndindex(x.shape, (axes,)):
404-
405- # Test if the values indexed by out_indices corresponds to
406- # the correct top_k values.
407- elements = [scalar_type(x[idx]) for idx in indices]
408- size = len(elements)
409- correct_order = sorted(
410- range(size),
411- key=elements.__getitem__,
412- reverse=largest
413- )
414- correct_order = correct_order[:k]
415- test_order = [out_indices[idx] for idx in indices[:k]]
416- # Sort because top_k does not necessarily return the values in
417- # sorted order.
418- test_sorted_order = sorted(
419- test_order,
420- key=elements.__getitem__,
421- reverse=largest
422- )
423-
424- for y_o, x_o in zip(correct_order, test_sorted_order):
425- y_idx = indices[y_o]
426- x_idx = indices[x_o]
427- ph.assert_0d_equals(
428- "top_k",
429- x_repr=f"x[{x_idx}]",
430- x_val=x[x_idx],
431- out_repr=f"x[{y_idx}]",
432- out_val=x[y_idx],
433- kw=kw,
434- )
435-
436- # Test if the values indexed by out_indices corresponds to out_values.
437- for y_o, x_idx in zip(test_order, indices[:k]):
438- y_idx = indices[y_o]
439- ph.assert_0d_equals(
440- "top_k",
441- x_repr=f"out_values[{x_idx}]",
442- x_val=scalar_type(out_values[x_idx]),
443- out_repr=f"x[{y_idx}]",
444- out_val=x[y_idx],
445- kw=kw
446- )
447- """
0 commit comments