public abstract class AbstractOperation extends java.lang.Object implements Operation
Operation implementation is a useful template for creating new operations.
It provides a partial implementation which consists of a simple component system for hosting Algorithm instances
as well as a set of properties which Operation implementations are expected to have. OperationBuilder instance to the constructor.
Using the factory will make the property configuration as readable as possible. | Modifier and Type | Field and Description |
|---|---|
protected int |
_arity
Arity is the number of arguments or operands
that this function or operation takes.
|
protected java.lang.String |
_function
An operation may have two ways in which it can describe itself as String within a Function AST.
|
protected boolean |
_isDifferentiable
Certain operations are not differentiable, meaning they cannot participate
in neither forward nor reverse mode differentiation.
|
protected boolean |
_isIndexer
This flag determines if this operation is auto-indexing passed input arguments.
|
protected boolean |
_isInline
Inline operations are operations which change the state of the arguments passed to them.
|
protected boolean |
_isOperator |
protected java.lang.String |
_operator
An operation may have two ways in which it can describe itself as String within a Function AST.
|
| Constructor and Description |
|---|
AbstractOperation(OperationBuilder builder) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
asDerivative(Function[] children,
int derivationIndex)
Operation implementations and Function implementations are in a tight relationship
where the Function describes an abstract syntax tree based on the syntactic information provided
by the Operation (through methods like Operation.getOperator() or Operation.getIdentifier()). |
<T extends Algorithm> |
getAlgorithm(java.lang.Class<T> type)
|
Algorithm |
getAlgorithmFor(ExecutionCall<?> call)
Alongside a component system made up of
Algorithm instances, implementations
of this interface also ought to express a routing mechanism which finds the best Algorithm
for a given ExecutionCall instance. |
Algorithm[] |
getAllAlgorithms() |
int |
getArity()
Arity is the number of arguments or operands
that this function or operation takes.
|
FallbackAlgorithm |
getDefaultAlgorithm() |
java.lang.String |
getIdentifier()
Concrete
Operation types ought to be representable by a function name. |
java.lang.String |
getOperator() |
boolean |
isDifferentiable() |
boolean |
isIndexer()
|
boolean |
isInline()
This flag indicates that the implementation of this
Operation
performs an operation which modifies the inputs to that operation. |
boolean |
isOperator()
An operator is an alternative to a function like "sum()" or "prod()".
|
protected java.lang.String |
operationName()
Override this if you want your operation to have a string representation
with a custom prefix which is something other than the simple class name!
|
<T extends Algorithm> |
setAlgorithm(java.lang.Class<T> type,
T instance)
|
java.lang.String |
stringify(java.lang.String[] children) |
<T extends Algorithm> |
supports(java.lang.Class<T> implementation) |
<T extends Algorithm> |
supportsAlgorithm(java.lang.Class<T> type)
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbuilder, calculate, execute, setAlgorithmprotected final java.lang.String _function
protected final java.lang.String _operator
protected final int _arity
protected final boolean _isIndexer
protected final boolean _isDifferentiable
protected final boolean _isInline
protected final boolean _isOperator
public AbstractOperation(OperationBuilder builder)
public final Algorithm[] getAllAlgorithms()
getAllAlgorithms in interface Operationpublic final <T extends Algorithm> T getAlgorithm(java.lang.Class<T> type)
Operation implementations embody a component system hosting unique Algorithm instances.
For a given class implementing the Algorithm class, there can only be a single
instance of it referenced (aka supported) by a given Operation instance.
This method ensures this in terms of read access by returning only a single instance or null
based on the provided class instance whose type extends the Algorithm interface.getAlgorithm in interface OperationT - The type parameter of the Algorithm type class.type - The class of the type which implements Algorithm as a key to get an existing instance.Operation.public final <T extends Algorithm> boolean supportsAlgorithm(java.lang.Class<T> type)
Operation contains an instance of the
Algorithm implementation specified via its type class.supportsAlgorithm in interface OperationT - The type parameter of the Algorithm type class.type - The class of the type which implements Algorithm.Operation contains an instance of the specified Algorithm type.public final <T extends Algorithm> Operation setAlgorithm(java.lang.Class<T> type, T instance)
Operation implementations embody a component system hosting unique Algorithm instances.
For a given class implementing the Algorithm class, there can only be a single
instance of it referenced (aka supported) by a given Operation instance.
This method enables the registration of Algorithm types in the component system of this Operation.setAlgorithm in interface OperationT - The type parameter of the Algorithm type class.type - The class of the type which implements Algorithm as key for the provided instance.instance - The instance of the provided type class which ought to be referenced (supported) by this Operation.Operation instance to enable method chaining on it.public final Algorithm getAlgorithmFor(ExecutionCall<?> call)
OperationAlgorithm instances, implementations
of this interface also ought to express a routing mechanism which finds the best Algorithm
for a given ExecutionCall instance.
This method signature describes this requirement.getAlgorithmFor in interface Operationcall - The ExecutionCall instance which needs the best Algorithm for execution.Algorithm which ought to be fir for execution the provided call.public final <T extends Algorithm> boolean supports(java.lang.Class<T> implementation)
public final boolean isOperator()
OperationisOperator in interface Operationpublic java.lang.String getIdentifier()
OperationOperation types ought to be representable by a function name.
The following ensures that this contract is met when overriding the method.getIdentifier in interface OperationFunction instances.public final java.lang.String getOperator()
getOperator in interface Operationpublic final int getArity()
Operationpublic final boolean isIndexer()
OperationFunction implementations that this Operation
ought to be viewed as something to be indexed.
The Function will use this information to iterate over all the provided inputs and
then execute the function wile also passing the index to the function AST.
The resulting array will then be available to this Operation as argument list.
This feature works alongside the Function implementation found in
FunctionVariable, which represents an input indexed
by the identifier 'j'!public final boolean isDifferentiable()
isDifferentiable in interface Operationpublic boolean isInline()
OperationOperation
performs an operation which modifies the inputs to that operation.
An example of this would be an assignment operation which copies the contents of one nd-array / tensor
into another tensor. This second tensor will then have changed its state.
This can be dangerous when auto-differentiation is involved.public final FallbackAlgorithm getDefaultAlgorithm()
public java.lang.String asDerivative(Function[] children, int derivationIndex)
Operation implementations and Function implementations are in a tight relationship
where the Function describes an abstract syntax tree based on the syntactic information provided
by the Operation (through methods like Operation.getOperator() or Operation.getIdentifier()).
One important feature of the Function is the ability to create
derivatives by calling the Function.getDerivative(int) method.
Implementations of this Function method ought to call the method defined below in order to
form the derivation based on the child nodes of the abstract syntax tree of the given Function node.asDerivative in interface Operationchildren - The child nodes of a AST node referencing this operation.derivationIndex - The index of the input node which ought to be derived.String which should be parsable into yet another AST.public java.lang.String stringify(java.lang.String[] children)
public final java.lang.String toString()
toString in class java.lang.Objectprotected java.lang.String operationName()