(a_gpu, axis, min_or_max, stream=None, keepdims=False)
return target, idx
Returns both max and argmax (min/argmin) along an axis.
Returns both max and argmax (min/argmin) along an axis.
Returns both max and argmax ( min / argmin ) along an axis .
def _minmax_impl(a_gpu, axis, min_or_max, stream=None, keepdims=False):
    ''' Returns both max and argmax (min/argmin) along an axis.'''
    assert len(a_gpu.shape) < 3
    if iscomplextype(a_gpu.dtype):
        raise ValueError("Cannot compute min/max of complex values")

    if axis is None or len(a_gpu.shape) <= 1:  ## Note: PyCUDA doesn't have an overall argmax/argmin!
        out_shape = (1,) * len(a_gpu.shape)
        if min_or_max == 'max':
            return gpuarray.max(a_gpu).reshape(out_shape), None
        else:
            return gpuarray.min(a_gpu).reshape(out_shape), None
    else:
        if axis < 0:
            axis += 2
    assert axis in (0, 1)

    global _global_cublas_allocator
    alloc = _global_cublas_allocator

    n, m = a_gpu.shape if a_gpu.flags.c_contiguous else (a_gpu.shape[1], a_gpu.shape[0])
    col_kernel, row_kernel = _get_minmax_kernel(a_gpu.dtype, min_or_max)
    if (axis == 0 and a_gpu.flags.c_contiguous) or (axis == 1 and a_gpu.flags.f_contiguous):
        if keepdims:
            out_shape = (1, m) if axis == 0 else (m, 1)
        else:
            out_shape = (m,)
        target = gpuarray.empty(out_shape, dtype=a_gpu.dtype, allocator=alloc)
        idx = gpuarray.empty(out_shape, dtype=np.uint32, allocator=alloc)
        col_kernel(a_gpu, target, idx, np.uint32(m), np.uint32(n),
                   block=(32, 1, 1), grid=(m, 1, 1), stream=stream)
    else:
        if keepdims:
            out_shape = (1, n) if axis == 0 else (n, 1)
        else:
            out_shape = (n,)
        target = gpuarray.empty(out_shape, dtype=a_gpu, allocator=alloc)
        idx = gpuarray.empty(out_shape, dtype=np.uint32, allocator=alloc)
        row_kernel(a_gpu, target, idx, np.uint32(m), np.uint32(n),
                block=(32, 1, 1), grid=(n, 1, 1), stream=stream)
    return target, idx
def _minmax_impl ( a_gpu , axis , min_or_max , stream = None , keepdims = False ) : assert len ( a_gpu . shape ) < 3 if iscomplextype ( a_gpu . dtype ) : raise ValueError ( "Cannot compute min/max of complex values" ) if axis is None or len ( a_gpu . shape ) <= 1 : ## Note: PyCUDA doesn't have an overall argmax/argmin! out_shape = ( 1 , ) * len ( a_gpu . shape ) if min_or_max == 'max' : return gpuarray . max ( a_gpu ) . reshape ( out_shape ) , None else : return gpuarray . min ( a_gpu ) . reshape ( out_shape ) , None else : if axis < 0 : axis += 2 assert axis in ( 0 , 1 ) global _global_cublas_allocator alloc = _global_cublas_allocator n , m = a_gpu . shape if a_gpu . flags . c_contiguous else ( a_gpu . shape [ 1 ] , a_gpu . shape [ 0 ] ) col_kernel , row_kernel = _get_minmax_kernel ( a_gpu . dtype , min_or_max ) if ( axis == 0 and a_gpu . flags . c_contiguous ) or ( axis == 1 and a_gpu . flags . f_contiguous ) : if keepdims : out_shape = ( 1 , m ) if axis == 0 else ( m , 1 ) else : out_shape = ( m , ) target = gpuarray . empty ( out_shape , dtype = a_gpu . dtype , allocator = alloc ) idx = gpuarray . empty ( out_shape , dtype = np . uint32 , allocator = alloc ) col_kernel ( a_gpu , target , idx , np . uint32 ( m ) , np . uint32 ( n ) , block = ( 32 , 1 , 1 ) , grid = ( m , 1 , 1 ) , stream = stream ) else : if keepdims : out_shape = ( 1 , n ) if axis == 0 else ( n , 1 ) else : out_shape = ( n , ) target = gpuarray . empty ( out_shape , dtype = a_gpu , allocator = alloc ) idx = gpuarray . empty ( out_shape , dtype = np . uint32 , allocator = alloc ) row_kernel ( a_gpu , target , idx , np . uint32 ( m ) , np . uint32 ( n ) , block = ( 32 , 1 , 1 ) , grid = ( n , 1 , 1 ) , stream = stream ) return target , idx