The following structures are available globally.
PythonObjectrepresents an object in Python and supports dynamic member lookup. Any member access like
object.foowill dynamically request the Python runtime for a member with the specified name in this object.
PythonObjectis passed to and returned from all Python function calls and member references. It supports standard Python arithmetic and comparison operators.
PythonObjectis implemented as a reference-counted pointer to a Python C API
@dynamicMemberLookup public struct PythonObject
PythonObjectwrapper that enables throwing method calls. Exceptions produced by Python functions are reflected as Swift errors and thrown.
NoteIt is intentional that
ThrowingPythonObjectdoes not have the
@dynamicCallableattribute because the call syntax is unintuitive:
x.throwing(arg1, arg2, ...). The methods will still be named
dynamicallyCalluntil further discussion/design.
public struct ThrowingPythonObject
PythonObjectwrapper that enables member accesses. Member access operations return an
Optionalresult. When member access fails,
@dynamicMemberLookup public struct CheckingPythonObject
An interface for Python.
PythonInterfaceallows interaction with Python. It can be used to import modules and dynamically access Python builtin types and functions.
NoteIt is not intended for
PythonInterfaceto be initialized directly. Instead, please use the global instance of
@dynamicMemberLookup public struct PythonInterface
ShapedArrayis a multi-dimensional array. It has a shape, which has type
[Int]and defines the array dimensions, and uses a
TensorBufferinternally as storage.
public struct ShapedArray<Scalar> : _ShapedArrayProtocol
A contiguous slice of a
ShapedArraySliceenables fast, efficient operations on contiguous slices of
ShapedArraySliceinstances do not have their own storage. Instead, they provides a view onto the storage of their base
ShapedArraySlicecan represent two different kinds of slices: element arrays and subarrays.
Element arrays are subdimensional elements of a
ShapedArray: their rank is one less than that of their base. Element array slices are obtained by indexing a
ShapedArrayinstance with a singular
let matrix = ShapedArray(shape: [2, 2], scalars: [0, 1, 2, 3]) // `matrix` represents [[0, 1], [2, 3]]. let element = matrix // `element` is a `ShapedArraySlice` with shape . It is an element // array, specifically the first element in `matrix`: [0, 1]. matrix = ShapedArraySlice(shape: , scalars: [4, 8]) // The second element in `matrix` has been mutated. // `matrix` now represents [[0, 1, 4, 8]].
Subarrays are a contiguous range of the elements in a
ShapedArray. The rank of a subarray is the same as that of its base, but its leading dimension is the count of the slice range. Subarray slices are obtained by indexing a
Range<Int32>that represents a range of elements (in the leading dimension). Methods like
suffix(:)that internally index with a range also produce subarray.
let zeros = ShapedArray(shape: [3, 2], repeating: 0) var matrix = ShapedArray(shape: [3, 2], scalars: Array(0..<6)) // `zeros` represents [[0, 0], [0, 0], [0, 0]]. // `matrix` represents [[0, 1], [2, 3], [4, 5]]. let subarray = matrix.prefix(2) // `subarray` is a `ShapedArraySlice` with shape [2, 2]. It is a slice // of the first 2 elements in `matrix` and represents [[0, 1], [2, 3]]. matrix[0..<2] = zeros.prefix(2) // The first 2 elements in `matrix` have been mutated. // `matrix` now represents [[0, 0], [0, 0], [4, 5]].
public struct ShapedArraySlice<Scalar> : _ShapedArrayProtocol
A struct representing the shape of a tensor.
TensorShapeis a thin wrapper around an array of integers that represent shape dimensions. All tensor types use
TensorShapeto represent their shape.
public struct TensorShape : ExpressibleByArrayLiteral
A sequence of pseudorandom numbers.
public struct RandomNumberSequence : Sequence