Reference
FunctionImplementations.AbstractArrayStyle — Type
FunctionImplementations.AbstractArrayStyle{N} <: Style is the abstract supertype for any style associated with an AbstractArray type. The N parameter is the dimensionality, which can be handy for AbstractArray types that only support specific dimensionalities:
struct SparseMatrixStyle <: FunctionImplementations.AbstractArrayStyle{2} end
FunctionImplementations.Style(::Type{<:SparseMatrixCSC}) = SparseMatrixStyle()For AbstractArray types that support arbitrary dimensionality, N can be set to Any:
struct MyArrayStyle <: FunctionImplementations.AbstractArrayStyle{Any} end
FunctionImplementations.Style(::Type{<:MyArray}) = MyArrayStyle()In cases where you want to be able to mix multiple AbstractArrayStyles and keep track of dimensionality, your style needs to support a Val constructor:
struct MyArrayStyleDim{N} <: FunctionImplementations.AbstractArrayStyle{N} end
(::Type{<:MyArrayStyleDim})(::Val{N}) where N = MyArrayStyleDim{N}()Note that if two or more AbstractArrayStyle subtypes conflict, the resulting style will fall back to that of Arrays. If this is undesirable, you may need to define binary Style rules to control the output type.
FunctionImplementations.DefaultArrayStyle — Type
FunctionImplementations.DefaultArrayStyle{N}() is a FunctionImplementations.Style indicating that an object behaves as an N-dimensional array. Specifically, DefaultArrayStyle is used for any AbstractArray type that hasn't defined a specialized style, and in the absence of overrides from other arguments the resulting output type is Array.
FunctionImplementations.Implementation — Type
FunctionImplementations.Implementation(f, s) wraps a function f with a style s. This can be used to create function implementations that behave differently based on the style of their arguments.
FunctionImplementations.Style — Type
Style is an abstract type and trait-function used to determine behavior of objects. Style(typeof(x)) returns the style associated with x. To customize the behavior of a type, one can declare a style by defining a type/method pair
struct MyContainerStyle <: Style end
FunctionImplementations.Style(::Type{<:MyContainer}) = MyContainerStyle()FunctionImplementations.Style — Method
(s::Style)(f)Calling a Style s with a function f as s(f) is a shorthand for creating a FunctionImplementations.Implementation object wrapping the function f with Style s.
FunctionImplementations.Style — Method
Style(::Style1, ::Style2) = Style3()Indicate how to resolve different Styles. For example,
Style(::Primary, ::Secondary) = Primary()would indicate that style Primary has precedence over Secondary. You do not have to (and generally should not) define both argument orders. The result does not have to be one of the input arguments, it could be a third type.
FunctionImplementations.permuteddims — Method
permuteddims(a::AbstractArray, perm)Lazy version of permutedims. Defaults to constructing a Base.PermutedDimsArray but can be customized to output a different type of array.
FunctionImplementations.result_style — Function
result_style(s1::Style[, s2::Style])::StyleTakes one or two Styles and combines them using Style to determine a common Style.
Examples
julia> FunctionImplementations.result_style(FunctionImplementations.DefaultArrayStyle{0}(), FunctionImplementations.DefaultArrayStyle{3}())
FunctionImplementations.DefaultArrayStyle{Any}()
julia> FunctionImplementations.result_style(FunctionImplementations.UnknownStyle(), FunctionImplementations.DefaultArrayStyle{1}())
FunctionImplementations.DefaultArrayStyle{1}()FunctionImplementations.style — Function
style(cs...)::StyleDecides which Style to use for any number of value arguments. Uses Style to get the style for each argument, and uses result_style to combine styles.
Examples
julia> FunctionImplementations.style([1], [1 2; 3 4])
FunctionImplementations.DefaultArrayStyle{Any}()