@@ -358,62 +358,46 @@ def test_top_k(x, mode_kw, data,):
358358# if dh.is_float_dtype(x.dtype):
359359# assume(not xp.any(x == -0.0) and not xp.any(x == +0.0))
360360
361- # XXX: default -1
362- axis = data .draw (st .integers (- x .ndim , x .ndim - 1 ), label = 'axis' )
361+ # default axis=-1
362+ axis_kw = data .draw (hh .kwargs (axis = st .integers (- x .ndim , x .ndim - 1 )))
363+ axis = axis_kw .get ('axis' , - 1 )
364+
363365 k = data .draw (st .integers (1 , x .shape [axis ]))
364366
365367 repro_snippet = ph .format_snippet (
366- f"xp.top_k(x, k, axis=axis , **mode_kw) with { mode_kw = } "
368+ f"xp.top_k(x, k, **axis_kw , **mode_kw) with { axis_kw = } and { mode_kw = } "
367369 )
368370 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- """
378- largest = data.draw(st.booleans(), label='largest')
379-
380-
381- kw = dict(
382- x=x,
383- k=k,
384- axis=axis,
385- largest=largest,
386- )
387-
388371
372+ print (x .dtype , k , axis , axis_kw )
389373
374+ out_values , out_indices = xp .top_k (x , k , ** axis_kw , ** mode_kw )
390375
376+ ph .assert_dtype ("top_k" , in_dtype = x .dtype , out_dtype = out_values .dtype )
377+ ph .assert_dtype (
378+ "top_k" ,
379+ in_dtype = x .dtype ,
380+ out_dtype = out_indices .dtype ,
381+ expected = dh .default_int
382+ )
391383
392- out_values, out_indices = xp.top_k(x, k, axis, largest=largest)
393-
384+ axes , = sh .normalize_axis (axis , x .ndim )
385+ for arr in [out_values , out_indices ]:
386+ ph .assert_shape (
387+ "top_k" ,
388+ out_shape = arr .shape ,
389+ expected = x .shape [:axes ] + (k ,) + x .shape [axes + 1 :],
390+ )
394391
392+ # TODO: test values
395393
396394
397- if axis is None :
398- x = xp.reshape(x, (-1,) )
399- axis = 0
395+ except Exception as exc :
396+ ph . add_note ( exc , repro_snippet )
397+ raise
400398
401- ph.assert_dtype("top_k", in_dtype=x.dtype, out_dtype=out_values.dtype)
402- ph.assert_dtype(
403- "top_k",
404- in_dtype=x.dtype,
405- out_dtype=out_indices.dtype,
406- expected=dh.default_int
407- )
408- axes, = sh.normalise_axis(axis, x.ndim)
409- for arr in [out_values, out_indices]:
410- ph.assert_shape(
411- "top_k",
412- out_shape=arr.shape,
413- expected=x.shape[:axes] + (k,) + x.shape[axes + 1:],
414- kw=kw
415- )
416399
400+ """
417401 scalar_type = dh.get_scalar_type(x.dtype)
418402
419403 for indices in sh.axes_ndindex(x.shape, (axes,)):
0 commit comments