DerivativeAttribute Class

Declares partial-derivative semantics for an enclosing CLR implementation or an explicitly identified semantic AutoDiff function.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.10.0
C#
public sealed class DerivativeAttribute : Attribute
Inheritance
Object  →  Attribute  →  DerivativeAttribute

Remarks

The source generator supports local functions declared directly in a static or instance primal method. Use the parameter-name constructor for a named partial, or the parameterless form when exactly one enclosing by-value parameter is differentiable. The receiver is context and is never selected by this shorthand. Multiple named partials may coexist.

At a source call, each explicit partial takes precedence over body differentiation for its parameter, in both forward and reverse mode. Uncovered active parameters use source-body differentiation. The returned coefficient must be valid for the target's represented input and output spaces. Supported forms include matching array/vector coefficients for a container-to-scalar function. A provider either returns its coefficient or returns void with one FunctionValueAttribute array/vector coefficient destination. That destination has the differentiated input's runtime shape and receives fresh, body-local storage; no Length metadata is required. Straight-line indexed writes are supported; structured control flow remains excluded. A local provider may additionally have one by-value parameter marked with PrimalReturnValueAttribute. The imported primal contract must expose a CLR return transport whose represented type matches that parameter; additional logical outputs do not affect this role. The parameter supplies already-computed context, does not affect semantic input arity, and is not derivative-result storage.

Each partial receives the full primal context, including an instance receiver and unused parameters. Bodies currently support straight-line computations using admitted compiler-owned calls, constants, and semantic calls to AutoDiffFunctionAttribute implementations in the current compilation or referenced portable AutoDiff packages; arbitrary receiver memory access and receiver differentiation are unsupported.

A nested declaration is metadata within the primal body and cannot be invoked there. A generation request on the enclosing method itself still differentiates its body; this rule applies when another differentiated method calls it.

AutoDiffFunctionAttribute declares semantic function identity; AutoDiffAttribute requests derivative generation. A derivative parameter marked with PrimalReturnValueAttribute receives the CLR primal return value without recomputing the primal.

When the enclosing method has AutoDiffFunctionAttribute, an element-polymorphic body is automatically generalized and shared with compatible local and published referenced implementations. Current scalar substitution supports double and float, including typed numeric constants and semantic calls. Calls to annotated user implementations select the unique exact concrete signature after substitution; missing or ambiguous implementations are errors.

ImplementationSpecific set to true forces an exact rule for the enclosing CLR implementation. Omitted or false permits, but does not guarantee, sharing. A body with another numerical element domain, or a method without semantic identity, remains exact. Exact rules specialize shared rules; only a rule miss uses body differentiation.

The two-string constructor declares a top-level shared provider on a static, non-generic ordinary method with one coefficient-result channel and by-value parameters. Its ordinary parameters supply primal inputs in declaration order, excluding the optional PrimalReturnValueAttribute context and FunctionValueAttribute coefficient destination. The named input, coefficient and optional primal result use one coherent double or float element domain. The body must safely generalize over its numerical element type; there is no exact fallback, and ImplementationSpecific must be false. When an implementation projection is available, it supplies the authoritative target signature and logical input coordinate. The provider does not define the primal codomain. Provider-only packages retain legacy scalar publication. For concrete semantics, use the nested form on the actual CLR implementation.

A top-level provider remains an ordinary callable method. It need not have a corresponding implementation in its assembly and does not itself establish an implementation binding. Scalar rules retain portable publication; container and buffered coefficients require an authoritative target projection and remain in the current compilation's typed catalog. Published referenced rules retain the existing scalar explicit-partial semantics. Unsupported CLR call shapes and structured control flow in derivative bodies remain excluded.

A buffered result role asserts that incoming destination contents are not primal inputs. The provider author is responsible for a correct derivative and required result writes; the compiler does not prove exhaustive initialization. Construction is isolated from primal/context storage and caller adjoints. Buffered providers remain current-compilation rules without ADRB/ADPK 1.0 publication.

Constructors

DerivativeAttribute() Initializes a new instance of the DerivativeAttribute class.
DerivativeAttribute(String) Initializes a new instance of the DerivativeAttribute class.
DerivativeAttribute(String, String) Initializes a new instance of the DerivativeAttribute class.

Properties

FunctionIdentifier Gets the explicitly declared semantic function identifier, or null for a nested derivative declaration.
ImplementationSpecific Gets or sets whether the derivative must remain attached to its concrete CLR implementation, preventing otherwise possible sharing or generalization to the semantic function.
ParameterName Gets the primal parameter name, or null when the declaration relies on a single unambiguous differentiable enclosing parameter.
TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute.
(Inherited from Attribute)

Methods

EqualsReturns a value that indicates whether this instance is equal to a specified object.
(Inherited from Attribute)
GetHashCodeReturns the hash code for this instance.
(Inherited from Attribute)
GetTypeGets the Type of the current instance.
(Inherited from Object)
IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
(Inherited from Attribute)
MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
(Inherited from Attribute)
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also