EngineType
public protocol EngineType
Tensor operation engine for a device
-
Undocumented
Declaration
Swift
associatedtype Device : DeviceType where Self == Self.Device.Engine
-
Fills a buffer with a given value
Declaration
Swift
static func fill<N>(value: N, result: Buffer<N, Device>, count: Int) where N : NumericType
Parameters
value
Value to fill the buffer with
result
Buffer to fill
count
Number of elements to write
-
Element-wise Vector negate
Declaration
Swift
static func vNeg<N>(val: Buffer<N, Device>, result: Buffer<N, Device>, count: Int) where N : NumericType
Parameters
val
Vector to negate
result
Result buffer
count
Number of elements to negate
-
Element-wise Vector-vector subtract
Declaration
Parameters
lhs
Left-hand side vector
rhs
Right-hand side vector
result
Result bufffer
count
Number of elements to subtract
-
Matrix diagonal fill in-place
Declaration
Swift
static func fillDiagonal<N>(values: ShapedBuffer<N, Device>, target: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Values to fill the diagonal with
target
Matrix to be filled
-
Matrix diagonal fill in-place
Declaration
Swift
static func fillDiagonal<N>(value: N, target: ShapedBuffer<N, Device>) where N : NumericType
Parameters
value
Value to fill the diagonal with
target
Matrix to be filled
-
Extracts the diagonal of a matrix
Declaration
Swift
static func extractDiagonal<N>(values: ShapedBuffer<N, Device>, target: ShapedBuffer<N, Device>) where N : NumericType
Parameters
value
Matrix to extract diagonal from
target
Vector to write diagonal values to
-
Matrix multiply add in-place
Declaration
Swift
static func gemm<N>(lhs: ShapedBuffer<N, Device>, rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, alpha: N, beta: N, transposeFirst: Bool, transposeSecond: Bool) where N : NumericType
Parameters
lhs
Left-hand side matrix
rhs
Right-hand side matrix
result
Summand and result buffer
alpha
Matrix multiplication scale
beta
Add scale
transposeFirst
Whether to transpose the first matrix
transposeSecond
Whether to transpose the second matrix
-
Band matrix extraction
Declaration
Swift
static func band<N>(buffer: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, belowDiagonal: Int?, aboveDiagonal: Int?) where N : NumericType
Parameters
buffer
Source matrix
result
Result buffer
belowDiagonal
Number of elements below diagonal to keep, nil for all elements
aboveDiagonal
Number of elements above diagonal to keep, nil for all elements
-
Broadcast adds two buffers
Declaration
Swift
static func broadcastAdd<N>(lhs: ShapedBuffer<N, Device>, rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First summand
rhs
Second summand
result
Sum vector
-
Broadcast subtracts one vector from another
Declaration
Swift
static func broadcastSub<N>(lhs: ShapedBuffer<N, Device>, rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
Left-hand side vector
rhs
Vector to subtact from lhs
result
Result buffer
-
Broadcast multiplies two buffers
Declaration
Swift
static func broadcastMul<N>(lhs: ShapedBuffer<N, Device>, rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First factor
rhs
Second factor
result
Product vector
-
Broadcast divides one vector by another
Declaration
Swift
static func broadcastDiv<N>(lhs: ShapedBuffer<N, Device>, rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
Left-hand side vector
rhs
Vector to divide lhs with
result
Result buffer
-
Reduces one buffer into another along one axis by computing the sum.
Declaration
Swift
static func reduceSum<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, axis: Int) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
axis
Axis to reduce along
-
Reduces one buffer into another along one axis by computing the maximum.
Declaration
Swift
static func reduceMax<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>?, axis: Int) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
context
Context vector that stores the argmax
axis
Axis to reduce along
-
Reduces one buffer into another along one axis by computing the minimum.
Declaration
Swift
static func reduceMin<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>?, axis: Int) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
context
Context vector that stores the argmin
axis
Axis to reduce along
-
Reduces one buffer into another along one axis by computing the mean.
Declaration
Swift
static func reduceMean<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, axis: Int) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
axis
Axis to reduce along
-
Reduces one buffer into another along multiple axes by computing the sum.
Declaration
Swift
static func reduceSum<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, axes: [Int]) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
axes
Axes to reduce along
-
Reduces one buffer into another along multiple axes by computing the maximum.
Declaration
Swift
static func reduceMax<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>?, axes: [Int]) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
context
Context buffer that stores the argmax
axes
Axes to reduce along
-
Reduces one buffer into another along multiple axes by computing the minimum.
Declaration
Swift
static func reduceMin<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>?, axes: [Int]) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
context
Context buffer that stores the argmin
axes
Axes to reduce along
-
Reduces one buffer into another along multiple axes by computing the mean.
Declaration
Swift
static func reduceMean<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, axes: [Int]) where N : NumericType
Parameters
values
Buffer to reduce
result
Result buffer
axes
Axes to reduce along
-
Computes the sum of a buffer
Declaration
Swift
static func sum<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer to sum up
result
Result buffer
-
Computes the mean of a buffer
Declaration
Swift
static func mean<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer to compute the mean of
result
Result buffer
-
Stores the maximum value in result and returns the argmax
Declaration
Swift
@discardableResult static func max<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) -> Int where N : NumericType
Parameters
values
Value buffer
result
Result buffer
-
Stores the minimum value in result and returns the argmin
Declaration
Swift
@discardableResult static func min<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) -> Int where N : NumericType
Parameters
values
Value buffer
result
Result buffer
-
Computes the argmax of a buffer
Declaration
Swift
static func argmax<N>(values: Buffer<N, Device>, count: Int) -> (Int, N) where N : NumericType
Parameters
values
Buffer to compute the argmax of
count
Number of elements in the buffer
-
Element-wise exponentiate
Declaration
Swift
static func exp<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to exponentiate
result
Result buffer
-
Element-wise log
Declaration
Swift
static func log<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the log of
result
Result buffer
-
Element-wise square root
Declaration
Swift
static func sqrt<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the square root of
result
Result buffer
-
Element-wise recitified linear unit
Declaration
Swift
static func relu<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the relu of
result
Result buffer
-
Element-wise heaviside step function
Declaration
Swift
static func heaviside<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the heaviside step function of
result
Result buffer
-
Element-wise sine
Declaration
Swift
static func sin<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the sine of
result
Result buffer
-
Element-wise cosine
Declaration
Swift
static func cos<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the cosine of
result
Result buffer
-
Element-wise tangent
Declaration
Swift
static func tan<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the tangent of
result
Result buffer
-
Element-wise hyperbolic sine
Declaration
Swift
static func sinh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the hyperbolic sine of
result
Result buffer
-
Element-wise hyperbolic cosine
Declaration
Swift
static func cosh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the hyperbolic cosine of
result
Result buffer
-
Element-wise hyperbolic tangent
Declaration
Swift
static func tanh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer of values to compute the hyperbolic tangent of
result
Result buffer
-
Element-wise maximum
Declaration
Swift
static func max<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First buffer
rhs
Second buffer
result
Result buffer
-
Element-wise maximum
Declaration
Swift
static func max<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First buffer
rhs
Second buffer
result
Result buffer
context
Context buffer
-
Element-wise minimum
Declaration
Swift
static func min<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First buffer
rhs
Second buffer
result
Result buffer
-
Element-wise minimum
Declaration
Swift
static func min<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, context: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lhs
First buffer
rhs
Second buffer
result
Result buffer
context
Context buffer
-
Scatters elements to indices determined by the context along the specified axis.
Declaration
Swift
static func scatter<N>(reduced: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>, result: ShapedBuffer<N, Device>, axis: Int, ignoreIndex: Int32) where N : NumericType
Parameters
reduced
Values to scatter
context
Index vector
result
Buffer to scatter to
axis
Axis to scatter along
-
Gathers elements from indices determined by the context along the specified axis
Declaration
Swift
static func gather<N>(expanded: ShapedBuffer<N, Device>, context: ShapedBuffer<Int32, Device>, result: ShapedBuffer<N, Device>, axis: Int, ignoreIndex: Int32) where N : NumericType
Parameters
expanded
Buffer to gather elements from
context
Index vector
result
Result buffer
axis
Axis to gather along
-
Performs an axis permutation / transpose oepration
Declaration
Swift
static func permuteAxes<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, arangement: [Int]) where N : NumericType
Parameters
values
Buffer of values to permute
result
Result buffer
arangement
Arangement of axes.
-
Performs an axis permutation / transpose oepration and adds another value vector
Declaration
Swift
static func permuteAxesAdd<N>(values: ShapedBuffer<N, Device>, add: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, arangement: [Int]) where N : NumericType
Parameters
values
Buffer of values to permute
add
Buffer of values to add to the result
result
Result buffer
arangement
Arangement of axes.
-
Reads elements from the given index
Declaration
Swift
static func subscriptRead<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, index: [Int?])
Parameters
values
Buffer of values to read
result
Buffer to write the values to
index
Index to read from, nil values indicate that all values along the corresponding axis should be read
-
Writes elements to the result tensor at the given index
Declaration
Swift
static func subscriptWrite<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, index: [Int?])
Parameters
values
Values to write
result
Buffer to write to
index
Index to write to, nil values indicate that all values along the corresponding axis should be written
-
Reads elements from the given index and adds a second vector
Declaration
Swift
static func subscriptReadAdd<N>(values: ShapedBuffer<N, Device>, add: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, index: [Int?]) where N : NumericType
Parameters
values
Buffer of values to read
add
Buffer to add
result
Buffer to write the values to
index
Index to read from, nil values indicate that all values along the corresponding axis should be read
-
Writes elements to the result tensor at the given index and adds a second vector
Declaration
Swift
static func subscriptWriteAdd<N>(values: ShapedBuffer<N, Device>, add: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, index: [Int?]) where N : NumericType
Parameters
values
Values to write
add
Buffer to add
result
Buffer to write to
index
Index to write to, nil values indicate that all values along the corresponding axis should be written
-
Reverses the order of elements along the first dimension of the buffer
Declaration
Swift
static func reverse<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>)
Parameters
values
Buffer to reverse
result
Result buffer
-
Reverses the order of elements along the first dimension of the buffer and adds a second buffer
Declaration
Swift
static func reverseAdd<N>(values: ShapedBuffer<N, Device>, add: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
values
Buffer to reverse
add
Buffer to add
result
Result buffer
-
Stacks the given array of buffers along the stacking axis into the result buffer.
Declaration
Swift
static func stack<N>(buffers: [ShapedBuffer<N, Device>], result: ShapedBuffer<N, Device>, axis: Int)
Parameters
buffers
Buffers to stack
result
Result buffer
axis
Axis to stack the buffers along
-
Reverses the stacking operation and adds a list of buffers to the unstacked results
Declaration
Swift
static func unstackAdd<N>(stacked: ShapedBuffer<N, Device>, add: [ShapedBuffer<N, Device>], result: [ShapedBuffer<N, Device>], axis: Int) where N : NumericType
Parameters
stacked
Buffer that stores elements of stacked buffers
add
Buffers to add to the corresponding result buffers
result
Buffers to write the result to
axis
Axis to unstack along
-
Reverses the stacking operation
Declaration
Swift
static func unstack<N>(stacked: ShapedBuffer<N, Device>, result: [ShapedBuffer<N, Device>], axis: Int) where N : NumericType
Parameters
stacked
Buffer that stores elements of stacked buffers
result
Buffers to write the result to
axis
Axis to unstack along
-
Writes linear interpolation values from lowerBound to upperBound into the result buffer.
Declaration
Swift
static func arange<N>(lowerBound: N, upperBound: N, result: ShapedBuffer<N, Device>) where N : NumericType
Parameters
lowerBound
Start value
upperBound
End value
result
Result buffer
-
Performs an img2col transformation that extracts all windows for a convolution into a matrix.
Declaration
Swift
static func img2col<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>, kernelWidth: Int, kernelHeight: Int, padding: Int, stride: Int) where N : NumericType
Parameters
values
Image buffer, shape [batchSize, channels, height, width]
result
Result buffer, shape [channels * kernelWidth * kernelHeight, number of windows]
kernelWidth
Width of the convolution kernel
kernelHeight
Height of the convolution kernel
padding
Zero padding applied around the input image
stride
Stride, with which the window is moved over the input image
-
Performs an col2img transformation that aggregates all windows from a convolution matrix into an image tensor.
Declaration
Swift
static func col2img<N>(matrix: ShapedBuffer<N, Device>, image: ShapedBuffer<N, Device>, kernelWidth: Int, kernelHeight: Int, padding: Int, stride: Int) where N : NumericType
Parameters
values
Buffer, shape [channels * kernelWidth * kernelHeight, number of windows]
result
Image buffer, shape [batchSize, channels, height, width]
kernelWidth
Width of the convolution kernel
kernelHeight
Height of the convolution kernel
padding
Zero padding applied around the input image
stride
Stride, with which the window is moved over the input image