Functions#

Introduction#

Every operation performed on an array object creates a new Function object. The returned Function object implements the same interface as array, but also adds a record of the operation to the computational graph.

Math operations#

Loupe defines functions for many common math operations. These functions are generally applied elementwise to an array. For example:

>>> import loupe
>>> a = loupe.array([1,2,3])
>>> b = loupe.array([4,5,6])
>>> c = loupe.add(a, b)
>>> c
array([5., 7., 9.])

Common infix notation for +, -, *, and ** is also supported:

>>> d = a + b
>>> d
array([5., 7., 9.])

The available math operations are provided below:

add(x1, x2)

Add arrays element-wise.

subtract(x1, x2)

Subtract arrays element-wise.

multiply(x1, x2)

Multiply arrays element-wise.

power(x1, x2)

First array elements raised to powers from second array, element-wise.

exp(x)

Calculate the exponential of the input array.

expc(x)

Calculate the exponential of the input array * 1j.

sum(x)

Sum of array elements.

absolute_square(x)

Calculate the absolute value squared, element-wise.

dft2(x, alpha[, shape, shift, offset, ...])

Compute the 2-dimensional discrete Fourier Transform.

einsum(subscripts, *operands[, dtype])

Evaluates the Einstein summation convention on the operands.

tensordot(a, b[, axes])

Compute tensor dot product along specified axes.

Array manipulation#

slice(x, slc)

Return a slice of the input array.

Broadcasting#

Broadcasting allows functions to operate on arrays that do not have exactly the same shape. Subject to certain constraints, the smaller array is “broadcast” across the larger array so that the resulting arrays have compatible shapes. This operation is done without making needless copies of the underlying data.

See Numpy’s page on broadcasting for more details, examples, and a description of the broadcasting rules.