BroadcastArithmeticOperator
public class BroadcastArithmeticOperator: ComputableOperator
The abstract parent class for all broadcast arithmetic oeprators.
Any child class of this operator support element-wise calculation between two Tensor
objects with broadcasting support.
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Declaration
Swift
public var computationDelegate: OperatorCalculationDelegate?
-
Declaration
Swift
public var metalKernelFuncLabel: String
-
Declaration
Swift
public var operatorLabel: String
-
Declaration
Swift
public var inputTensors: [Tensor]?
-
Declaration
Swift
public var outputTensors: [Tensor]?
-
Computation logic block. First param is input tensors, seconds param is output tensors. Operator just needs override this in requried init function instead of override whole computation methods. All input tensors are already broadcasted.
Declaration
Swift
public lazy var calculationBlock: ([Tensor], [Tensor], OperatorComputationMode) -> Void = {_,_,_ in }
-
The grad compuation block. parameter: inputA, inputB, returns: An array of tensor. Should just have 2 object corresponding to two inputs
Declaration
Swift
public var gradComputationBlock: (Tensor, Tensor, OperatorComputationMode) -> [Tensor] = {(_,_,_) -> [Tensor] in
-
If
true
, operator will not check theupGrads
‘s shape. This is used inside framework to speed up in situation we know it will not be wrong. Cases like auto generated differentiation graph.Declaration
Swift
public var disableUpGradShapeCheck: Bool = false
-
If
true
, operator will not callinputOutputTensorsCheck()
before doing calculation. This is used inside framework to speed up in situation we know it will not be wrong.Declaration
Swift
public var disableInputOutputCheck: Bool = false
-
Indicate if this operator would do paramter update.
Note
BroadcastArithmeticOperator
is not trainable.Declaration
Swift
public var trainable: Bool = false
-
The mapping type of this operator.
OneToOne
for this operator.Declaration
Swift
public var mapType: OperatorMappingType
-
Broadcast operator cannot do in-place calculation
Declaration
Swift
public var inPlaceble: Bool = false
-
Initializer.
Note
In most cases this initializer should not be called directly. call one of the convenience initializers instead.
Declaration
Swift
public init(computationDelegate: OperatorCalculationDelegate?, inputTensors: [Tensor]?, outputTensors: [Tensor]?, metalKernelFuncLabel: String, operatorLabel: String)
Parameters
computationDelegate
computationDelegate
inputTensors
inputTensors
outputTensors
outputTensors
metalKernelFuncLabel
metalKernelFuncLabel
operatorLabel
operatorLabel
-
Conevnience initializer.
Note
All subclass should override this convenience initializer to setup
metalKernelFuncLabel
and defaultoperatorLabel
.Declaration
Swift
required public convenience init(computationDelegate: OperatorCalculationDelegate? = nil)
Parameters
computationDelegate
computationDelegate
-
Conenience initializer.
Declaration
Swift
public convenience init(computationDelegate: OperatorCalculationDelegate? = nil, inputTensors: [Tensor], outputTensors: [Tensor])
Parameters
computationDelegate
computationDelegate
inputTensors
inputTensors
outputTensors
outputTensors
-
Convenience initializer
Declaration
Swift
public convenience init(computationDelegate: OperatorCalculationDelegate? = nil, operatorLabel: String)
Parameters
computationDelegate
computationDelegate
operatorLabel
operatorLabel
-
Check the input shapes. Should exactly contains two shapes and the two shapes should be have same dimensions with or without broadcasting.
Declaration
Swift
public func outputShape(shapeArray shapes: [TensorShape]) -> [TensorShape]?
Parameters
shapes
input shapes
Return Value
output shapes, maybe
nil
if not valid -
Check validation of shapes mathcing between
inpuTensors
andoutputTensors
.Declaration
Swift
public func inputOutputTensorsCheck() -> (check: Bool, msg: String)
Return Value
check
indicates if validation,msg
containing error information. -
Usually, a
BroadcastArithmeticOperator
just callBroadcastOperator
and other calculation operators. This methods will first do braodcast on input tensors if needs and then callcalculationBlock
.Declaration
Swift
public func compute(_ computationMode: OperatorComputationMode = SerranoEngine.configuredEngine.defaultComputationMode)
Parameters
computationMode
computationMode
-
Declaration
Swift
public func computeAsync(_ computationMode: OperatorComputationMode = SerranoEngine.configuredEngine.defaultComputationMode)
-
Calulate grads sync.
Declaration
Swift
public func gradCompute(_ computationMode: OperatorComputationMode) -> [String: DataSymbolSupportedDataType]
Parameters
computationMode
computationMode
Return Value
return grads tensor
-
Cal grads async
Declaration
Swift
public func gradComputAsync(_ computationMode: OperatorComputationMode)
Parameters
computationMode
computationMode
upGrds
upGrds
-
Update params if possible. No update parameters for broadcast arithmetic operators.
Declaration
Swift
public func updateParams(grads: [Tensor], LR: Float)
Parameters
grads
grads tensor list
LR
learning rate
-
This operator has no parameters. Do nothing
Declaration
Swift
public func bindParamSymbols(_ symbols: [GraphSymbol])
-
This operator has no parameters.
Declaration
Swift
public func paramSymbols() -> [GraphSymbol]
Return Value
An empty array