33import pytest
44from hypothesis import given , note , assume
55from hypothesis import strategies as st
6- from hypothesis .control import assume
76
87from . import _array_module as xp
98from . import dtype_helpers as dh
@@ -351,20 +350,33 @@ def test_searchsorted_with_scalars(data):
351350 shape = hh .shapes (min_dims = 1 , min_side = 1 ),
352351 elements = {"allow_nan" : False },
353352 ),
353+ mode_kw = hh .kwargs (mode = st .sampled_from (['largest' , 'smallest' ])),
354354 data = st .data ()
355355)
356- def test_top_k (x , data ):
356+ def test_top_k (x , mode_kw , data , ):
357357
358- if dh .is_float_dtype (x .dtype ):
359- assume (not xp .any (x == - 0.0 ) and not xp .any (x == + 0.0 ))
358+ # if dh.is_float_dtype(x.dtype):
359+ # assume(not xp.any(x == -0.0) and not xp.any(x == +0.0))
360360
361- axis = data .draw (
362- st .integers (- x .ndim , x .ndim - 1 ), label = 'axis' )
361+ # XXX: default -1
362+ axis = data .draw (st .integers (- x .ndim , x .ndim - 1 ), label = 'axis' )
363+ k = data .draw (st .integers (1 , x .shape [axis ]))
364+
365+ repro_snippet = ph .format_snippet (
366+ f"xp.top_k(x, k, axis=axis, **mode_kw) with { mode_kw = } "
367+ )
368+ try :
369+ out_values , out_indices = xp .top_k (x , k , axis = axis , ** mode_kw )
370+
371+
372+ except Exception as exc :
373+ ph .add_note (exc , repro_snippet )
374+ raise
375+
376+
377+ """
363378 largest = data.draw(st.booleans(), label='largest')
364- if axis is None :
365- k = data .draw (st .integers (1 , math .prod (x .shape )))
366- else :
367- k = data .draw (st .integers (1 , x .shape [axis ]))
379+
368380
369381 kw = dict(
370382 x=x,
@@ -373,7 +385,15 @@ def test_top_k(x, data):
373385 largest=largest,
374386 )
375387
376- (out_values , out_indices ) = xp .top_k (x , k , axis , largest = largest )
388+
389+
390+
391+
392+ out_values, out_indices = xp.top_k(x, k, axis, largest=largest)
393+
394+
395+
396+
377397 if axis is None:
378398 x = xp.reshape(x, (-1,))
379399 axis = 0
@@ -440,4 +460,4 @@ def test_top_k(x, data):
440460 out_val=x[y_idx],
441461 kw=kw
442462 )
443- > >> >> >> WIP : top_k tests
463+ """
0 commit comments