Open Table Of Contents

numpy_support Package

numpy_support Package

slicenodes Module

AST nodes for native slicing.

class, operands, **kwargs)

Bases: numba.nodes.basenodes.ExprNode

Broadcast a bunch of operands:

  • set strides of single-sized dimensions to zero
  • find big shape

Bases: ast.NodeVisitor

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

class, 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
class, src_dim, dst_dim, **kwargs)

Bases: numba.nodes.basenodes.ExprNode

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

class, src_dim, dst_dim, **kwargs)


Array is sliced, and this dimension contains a slice., *args), 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, 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, llvm_module)

Bases: numba.utility.cbuilder.numbacdef.NumbaCDefinition

body(data, in_shape, in_strides, src_dim, index)
class, llvm_module)

Bases: numba.utility.cbuilder.numbacdef.NumbaCDefinition

body(out_shape, out_strides, dst_dim)
class*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)

slicing Module

Module that deals with NumPy array slicing.

  • normalize ellipses
  • recognize newaxes
  • track how contiguity is affected (C or Fortran), 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