public interface Operation
ExecutionCall arguments.
An Operation implementation ought to consist of a component system
containing multiple Algorithm instances, which themselves ought to contain device specific implementations
capable of processing ExecutionCall instances, or rather their state. neureka.math package in order to serve as part of an Function AST.
This means that the operation should have a function name
and optionally also an operator in the form of String instances.
Alongside there must be an implementation of the stringify(String[]) method,
which ought to generate a String view as part of a Function-AST.| 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 getOperator() or getIdentifier()). |
static OperationBuilder |
builder() |
double |
calculate(double[] inputs,
int j,
int d,
Function[] src)
This method mainly ought to serve as a reference- and fallback- implementation for tensor backends and also
as the backend for handling the calculation of scalar inputs passed to a given abstract syntax tree of
Function instances... |
default Result |
execute(Function caller,
ExecutionCall<?> call) |
<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.
|
java.lang.String |
getIdentifier()
Concrete
Operation types ought to be representable by a function name. |
java.lang.String |
getOperator() |
boolean |
isDifferentiable()
Deprecated.
|
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()".
|
<T extends Algorithm> |
setAlgorithm(java.lang.Class<T> type,
T instance)
|
default <T extends Algorithm> |
setAlgorithm(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)
|
static OperationBuilder builder()
Algorithm[] getAllAlgorithms()
Algorithm getAlgorithmFor(ExecutionCall<?> call)
Algorithm 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.call - The ExecutionCall instance which needs the best Algorithm for execution.Algorithm which ought to be fir for execution the provided call.<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.T - 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.<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.<T extends Algorithm> boolean supportsAlgorithm(java.lang.Class<T> type)
java.lang.String getIdentifier()
Operation types ought to be representable by a function name.
The following ensures that this contract is met when overriding the method.Function instances.java.lang.String stringify(java.lang.String[] children)
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 getOperator() or 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.children - 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.java.lang.String getOperator()
int getArity()
boolean isOperator()
boolean isIndexer()
Function 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'!@Deprecated boolean isDifferentiable()
boolean isInline()
Operation
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.Operation changes the contents of inputs.<T extends Algorithm> boolean supports(java.lang.Class<T> implementation)
default Result execute(Function caller, ExecutionCall<?> call)
double calculate(double[] inputs,
int j,
int d,
Function[] src)
Function instances... inputs - An array of scalar input variables.j - The index variable for indexed execution on the input array. (-1 if no indexing should occur)d - The index of the variable of which a derivative ought to be calculated.src - The child nodes of the Function node to which this very OperationType belongs.