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 : NumericTypeParameters
valueValue to fill the buffer with
resultBuffer to fill
countNumber 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 : NumericTypeParameters
valVector to negate
resultResult buffer
countNumber of elements to negate
-
Element-wise Vector-vector subtract
Declaration
Parameters
lhsLeft-hand side vector
rhsRight-hand side vector
resultResult bufffer
countNumber 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 : NumericTypeParameters
valuesValues to fill the diagonal with
targetMatrix to be filled
-
Matrix diagonal fill in-place
Declaration
Swift
static func fillDiagonal<N>(value: N, target: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valueValue to fill the diagonal with
targetMatrix 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 : NumericTypeParameters
valueMatrix to extract diagonal from
targetVector 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 : NumericTypeParameters
lhsLeft-hand side matrix
rhsRight-hand side matrix
resultSummand and result buffer
alphaMatrix multiplication scale
betaAdd scale
transposeFirstWhether to transpose the first matrix
transposeSecondWhether 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 : NumericTypeParameters
bufferSource matrix
resultResult buffer
belowDiagonalNumber of elements below diagonal to keep, nil for all elements
aboveDiagonalNumber 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 : NumericTypeParameters
lhsFirst summand
rhsSecond summand
resultSum 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 : NumericTypeParameters
lhsLeft-hand side vector
rhsVector to subtact from lhs
resultResult 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 : NumericTypeParameters
lhsFirst factor
rhsSecond factor
resultProduct 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 : NumericTypeParameters
lhsLeft-hand side vector
rhsVector to divide lhs with
resultResult 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
axisAxis 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
contextContext vector that stores the argmax
axisAxis 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
contextContext vector that stores the argmin
axisAxis 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
axisAxis 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
axesAxes 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
contextContext buffer that stores the argmax
axesAxes 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
contextContext buffer that stores the argmin
axesAxes 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 : NumericTypeParameters
valuesBuffer to reduce
resultResult buffer
axesAxes 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 : NumericTypeParameters
valuesBuffer to sum up
resultResult buffer
-
Computes the mean of a buffer
Declaration
Swift
static func mean<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer to compute the mean of
resultResult 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 : NumericTypeParameters
valuesValue buffer
resultResult 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 : NumericTypeParameters
valuesValue buffer
resultResult buffer
-
Computes the argmax of a buffer
Declaration
Swift
static func argmax<N>(values: Buffer<N, Device>, count: Int) -> (Int, N) where N : NumericTypeParameters
valuesBuffer to compute the argmax of
countNumber of elements in the buffer
-
Element-wise exponentiate
Declaration
Swift
static func exp<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to exponentiate
resultResult buffer
-
Element-wise log
Declaration
Swift
static func log<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the log of
resultResult buffer
-
Element-wise square root
Declaration
Swift
static func sqrt<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the square root of
resultResult buffer
-
Element-wise recitified linear unit
Declaration
Swift
static func relu<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the relu of
resultResult buffer
-
Element-wise heaviside step function
Declaration
Swift
static func heaviside<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the heaviside step function of
resultResult buffer
-
Element-wise sine
Declaration
Swift
static func sin<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the sine of
resultResult buffer
-
Element-wise cosine
Declaration
Swift
static func cos<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the cosine of
resultResult buffer
-
Element-wise tangent
Declaration
Swift
static func tan<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the tangent of
resultResult buffer
-
Element-wise hyperbolic sine
Declaration
Swift
static func sinh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the hyperbolic sine of
resultResult buffer
-
Element-wise hyperbolic cosine
Declaration
Swift
static func cosh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the hyperbolic cosine of
resultResult buffer
-
Element-wise hyperbolic tangent
Declaration
Swift
static func tanh<N>(values: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
valuesBuffer of values to compute the hyperbolic tangent of
resultResult buffer
-
Element-wise maximum
Declaration
Swift
static func max<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
lhsFirst buffer
rhsSecond buffer
resultResult 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 : NumericTypeParameters
lhsFirst buffer
rhsSecond buffer
resultResult buffer
contextContext buffer
-
Element-wise minimum
Declaration
Swift
static func min<N>(_ lhs: ShapedBuffer<N, Device>, _ rhs: ShapedBuffer<N, Device>, result: ShapedBuffer<N, Device>) where N : NumericTypeParameters
lhsFirst buffer
rhsSecond buffer
resultResult 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 : NumericTypeParameters
lhsFirst buffer
rhsSecond buffer
resultResult buffer
contextContext 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 : NumericTypeParameters
reducedValues to scatter
contextIndex vector
resultBuffer to scatter to
axisAxis 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 : NumericTypeParameters
expandedBuffer to gather elements from
contextIndex vector
resultResult buffer
axisAxis 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 : NumericTypeParameters
valuesBuffer of values to permute
resultResult buffer
arangementArangement 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 : NumericTypeParameters
valuesBuffer of values to permute
addBuffer of values to add to the result
resultResult buffer
arangementArangement 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
valuesBuffer of values to read
resultBuffer to write the values to
indexIndex 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
valuesValues to write
resultBuffer to write to
indexIndex 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 : NumericTypeParameters
valuesBuffer of values to read
addBuffer to add
resultBuffer to write the values to
indexIndex 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 : NumericTypeParameters
valuesValues to write
addBuffer to add
resultBuffer to write to
indexIndex 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
valuesBuffer to reverse
resultResult 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 : NumericTypeParameters
valuesBuffer to reverse
addBuffer to add
resultResult 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
buffersBuffers to stack
resultResult buffer
axisAxis 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 : NumericTypeParameters
stackedBuffer that stores elements of stacked buffers
addBuffers to add to the corresponding result buffers
resultBuffers to write the result to
axisAxis 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 : NumericTypeParameters
stackedBuffer that stores elements of stacked buffers
resultBuffers to write the result to
axisAxis 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 : NumericTypeParameters
lowerBoundStart value
upperBoundEnd value
resultResult 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 : NumericTypeParameters
valuesImage buffer, shape [batchSize, channels, height, width]
resultResult buffer, shape [channels * kernelWidth * kernelHeight, number of windows]
kernelWidthWidth of the convolution kernel
kernelHeightHeight of the convolution kernel
paddingZero padding applied around the input image
strideStride, 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 : NumericTypeParameters
valuesBuffer, shape [channels * kernelWidth * kernelHeight, number of windows]
resultImage buffer, shape [batchSize, channels, height, width]
kernelWidthWidth of the convolution kernel
kernelHeightHeight of the convolution kernel
paddingZero padding applied around the input image
strideStride, with which the window is moved over the input image
View on GitHub
EngineType Protocol Reference