Open Table Of Contents

numpy_support Package

numpy_support Package

slicenodes Module

AST nodes for native slicing.

class numba.support.numpy_support.slicenodes.BroadcastNode(array_type, operands, **kwargs)

Bases: numba.nodes.basenodes.ExprNode

Broadcast a bunch of operands:

  • set strides of single-sized dimensions to zero
  • find big shape
class numba.support.numpy_support.slicenodes.MarkNoPython

Bases: ast.NodeVisitor

Mark array slicing nodes as nopython, which allows them to use stack-allocated fake arrays.

visit_NativeSliceNode(node)
class numba.support.numpy_support.slicenodes.NativeSliceNode(type, value, subslices, nopython, **kwargs)

Bases: numba.nodes.basenodes.ExprNode

Aggregate of slices in all dimensions.

In nopython context, uses a fake stack-allocated PyArray struct.

In python context, it builds an actual heap-allocated numpy array. In this case, the following attributes are patched during code generation time that sets the llvm values:

dst_data, dst_shape, dst_strides
build_array()
mark_nopython()
class numba.support.numpy_support.slicenodes.SliceDimNode(subslice, src_dim, dst_dim, **kwargs)

Bases: numba.nodes.basenodes.ExprNode

Array is sliced, and this dimension contains an integer index or newaxis.

class numba.support.numpy_support.slicenodes.SliceSliceNode(subslice, src_dim, dst_dim, **kwargs)

Bases: numba.support.numpy_support.slicenodes.SliceDimNode

Array is sliced, and this dimension contains a slice.

numba.support.numpy_support.slicenodes.create_slice_dim_node(subslice, *args)
numba.support.numpy_support.slicenodes.mark_nopython(ast)
numba.support.numpy_support.slicenodes.rewrite_slice(node, nopython)

Rewrites array slices to its native equivalent without using the Python API.

node: ast.Subscript with an array type as result nopython: whether the node is encountered in a nopython context

sliceutils Module

class numba.support.numpy_support.sliceutils.Broadcast(env, llvm_module)

Bases: numba.utility.cbuilder.numbacdef.NumbaCDefinition

Transliteration of

@cname(‘__pyx_memoryview_broadcast’) cdef bint __pyx_broadcast(Py_ssize_t *dst_shape,

Py_ssize_t *input_shape, Py_ssize_t *strides, int max_ndim, int ndim, bint *p_broadcast) nogil except -1:

cdef Py_ssize_t i cdef int dim_offset = max_ndim - ndim

for i in range(ndim):

src_extent = input_shape[i] dst_extent = dst_shape[i + dim_offset]

if src_extent == 1:
p_broadcast[0] = True strides[i] = 0
elif dst_extent == 1:
dst_shape[i + dim_offset] = src_extent
elif src_extent != dst_extent:
__pyx_err_extents(i, dst_shape[i], input_shape[i])
body(dst_shape, src_shape, src_strides, max_ndim, ndim)
class numba.support.numpy_support.sliceutils.IndexAxis(env, llvm_module)

Bases: numba.utility.cbuilder.numbacdef.NumbaCDefinition

body(data, in_shape, in_strides, src_dim, index)
class numba.support.numpy_support.sliceutils.NewAxis(env, llvm_module)

Bases: numba.utility.cbuilder.numbacdef.NumbaCDefinition

body(out_shape, out_strides, dst_dim)
class numba.support.numpy_support.sliceutils.SliceArray(*args, **kwargs)

Bases: llvm_cbuilder.builder.CDefinition

adjust_index(extent, negative_step, index, default1, default2, is_start=False, have_index=True)
body(data, in_shape, in_strides, out_shape, out_strides, start, stop, step, src_dim, dst_dim)
specialize(context, have_start, have_stop, have_step)
numba.support.numpy_support.sliceutils.get_constants(cbuilder)

slicing Module

Module that deals with NumPy array slicing.

  • normalize ellipses
  • recognize newaxes
  • track how contiguity is affected (C or Fortran)
numba.support.numpy_support.slicing.unellipsify(node, slices, subscript_node)

Given an array node node, process all AST slices and create the final type:

  • process newaxes (None or numpy.newaxis)
  • replace Ellipsis with a bunch of ast.Slice objects
  • process integer indices
  • append any missing slices in trailing dimensions