@@ -40,6 +40,37 @@ const StaticVector{N, T} = StaticArray{Tuple{N}, T, 1}
40
40
const StaticMatrix{N, M, T} = StaticArray{Tuple{N, M}, T, 2 }
41
41
const StaticVecOrMat{T} = Union{StaticVector{<: Any , T}, StaticMatrix{<: Any , <: Any , T}}
42
42
43
+ # Add a new BroadcastStyle for StaticArrays, derived from AbstractArrayStyle
44
+ # A constructor that changes the style parameter N (array dimension) is also required
45
+ struct StaticArrayStyle{N} <: Base.Broadcast.AbstractArrayStyle{N} end
46
+ StaticArrayStyle {M} (:: Val{N} ) where {M,N} = StaticArrayStyle {N} ()
47
+
48
+ is_staticarray_like (:: StaticArray ) = true
49
+
50
+ # similar_type
51
+
52
+ """
53
+ similar_type(static_array)
54
+ similar_type(static_array, T)
55
+ similar_type(array, ::Size)
56
+ similar_type(array, T, ::Size)
57
+
58
+ Returns a constructor for a statically-sized array similar to the input array
59
+ (or type) `static_array`/`array`, optionally with different element type `T` or size
60
+ `Size`. If the input `array` is not a `StaticArray` then the `Size` is mandatory.
61
+
62
+ This differs from `similar()` in that the resulting array type may not be
63
+ mutable (or define `setindex!()`), and therefore the returned type may need to
64
+ be *constructed* with its data.
65
+
66
+ Note that the (optional) size *must* be specified as a static `Size` object (so the compiler
67
+ can infer the result statically).
68
+
69
+ New types should define the signature `similar_type(::Type{A},::Type{T},::Size{S}) where {A<:MyType,T,S}`
70
+ if they wish to overload the default behavior.
71
+ """
72
+ function similar_type end
73
+
43
74
include (" staticarrays.jl" )
44
75
include (" utils.jl" )
45
76
include (" staticsize.jl" )
0 commit comments