5 Extended Functions
Base functions are commonly understood functions that only work on tensors of a specific rank known as the base rank. Base functions can be extended to work with tensors of any rank higher than the base rank.
Additionally, all the base and extended functions are differentiable (as described in Overview). Here we define a differentiable function as a Racket function that can be used with the automatic differentiation functions provided by Malt to produce valid gradients.
primitive-1? A differentiable function of one argument that is constructed from the invocation of prim1.
primitive-2? A differentiable function of two arguments that is constructed from the invocation of prim2.
5.1 Unary function extension rules
If t is of rank m, the result is the tensor (f t).
Else for each element of t, say te, invoke the extended function on te and assemble the results into a tensor, in the order of the elements of t.
Unary functions are extended using ext1, ext1-ρ, or ext1-∇.
5.2 Binary function extension rules
If t is of rank m and u is of rank n, the result is the tensor (f t u).
Else if t is of rank m, for each element of u, say ue, invoke the extended function on t and ue, and assemble the results into a tensor, in the order of the elements of u.
Else if u is of rank n, for each element of t, say te, invoke the extended function on te and u, and assemble the results into a tensor, in the order of the elements of t.
Else if u and t are of equal length, for each element of t, say te, and u, say ue, invoke the extended function on te and ue, and assemble the results into a tensor, in the order of the elements of t and u.
Else if the rank of u is higher than the rank of t, for each element of u, say ue, invoke the extended function on t and ue, and assemble the results into a tensor, in the order of the elements of u.
Else if the rank of t is higher than the rank of u, for each element of t, say te, invoke the extended function on te and u, and assemble the results into a tensor, in the order of the elements of t.
Binary functions are extended using ext2, ext2-ρ, or ext2-∇.
procedure
prim : primitive-2? base-rank-1 : natural? base-rank-2 : natural?
5.3 Primitives in learner and nested-tensors
The following functions are available when the default tensor representation in Malt is learner or nested-tensors.
procedure
ρ-fn : (-> tensor? tensor?) ∇-fn : (-> tensor? tensor? tensor?)
procedure
ρ-fn : (-> tensor? tensor? tensor?) ∇-fn : (-> tensor? tensor? tensor? tensor?)
5.4 Primitives in flat-tensors
The following functions are available when the default tensor representation in Malt is flat-tensors.
procedure
ρ-fn : (-> tensor? tensor?) ∇-fn : (-> tensor? tensor? tensor?) shape-fn : (-> shape? shape?)
procedure
ρ-fn : (-> tensor? tensor? tensor?) ∇-fn : (-> tensor? tensor? tensor? tensor?) shape-fn : (-> shape? shape? shape?)
5.5 Extension in flat-tensors and nested-tensors
The following functions are available when the default tensor representation in Malt is flat-tensors or nested-tensors. These can be used to provide new tensor operations that cannot be constructed using ext1 and ext2. The following is a guideline, but the actual type of ρ-fn and ∇-fn arguments will vary by tensor representation. See the Malt source code for further examples.
procedure
ρ-fn : (-> tensor? tensor?) base-rank : natural?
procedure
∇-fn : (-> tensor? tensor? tensor?) base-rank : natural?
procedure
→ (-> tensor? tensor? tensor?) ρ-fn : (-> tensor? tensor? tensor?) base-rank-1 : natural? base-rank-2 : natural?
procedure
∇-fn : (-> tensor? tensor? tensor?) base-rank : natural?