ReduceOperator
public class ReduceOperator: ComputableOperator
The abstract class for all reduce operators. Should not be used directly. A reduce operator do some aggregate calculation along given axes. An example given by TensorFlow is here.
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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]?
-
The axes to do the computation
Declaration
Swift
public var axis: [Int]
-
Indicate if keep dimensions in result tensor. This just affects result tensor’s
shape
attributes. Defaultfalse
Declaration
Swift
public var keepDim: Bool = false
-
The element compuation block in CPU mode. In most cases, subclass should just override this part in
init
method instead overriding the wholecpu()
method. The firat pointer is the input tensor, / the second is the output tensorDeclaration
-
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
AllUnaryOperators
are 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
-
Reduce operator cannot do in-place calculation
Declaration
Swift
public var inPlaceble: Bool = false
-
Undocumented
Declaration
Swift
init(computationDelegate: OperatorCalculationDelegate?, operatorLabel: String = "NEED OVERRIDE", metalKernelFuncLabel kernelLabel: String = "NEED OVERRIDE", inputTensors: [Tensor]?, outputTensors: [Tensor]?, axis: [Int])
-
Conenience init.
Declaration
Parameters
inputTensors
inputTensors description
outputTensors
outputTensors description
axis
axis description
-
Conenience init.
Declaration
Swift
public convenience init(axis: [Int], keepDim: Bool)
Parameters
axis
axis
keepDim
keepDim
-
Check if for each input shape operator could do reduce operation with
axis
attribute value.Declaration
Swift
public func outputShape(shapeArray shapes: [TensorShape]) -> [TensorShape]?
Parameters
shapes
shapes description
Return Value
return value description
-
Validate shapes
inputTensors
andoutputTensors
.Declaration
Swift
public func inputOutputTensorsCheck() -> (check: Bool, msg: String)
Return Value
check passing and message if not passing
-
Comput sync
Declaration
Swift
public func compute(_ computationMode: OperatorComputationMode = SerranoEngine.configuredEngine.defaultComputationMode)
Parameters
computationMode
computationMode description
-
Comput async
Declaration
Swift
public func computeAsync(_ computationMode: OperatorComputationMode = SerranoEngine.configuredEngine.defaultComputationMode)
Parameters
computationMode
computationMode description
-
Calulate grads sync. All unary operator return grads tensor with same number and shape as attribute
inputTensors
.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
-
Update params if possible. No update parameters for binary 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
-
Undocumented
Declaration
Swift
internal func cpu()
-
Undocumented
Declaration
Swift
internal func gpu()