Skip to content

Commit 583ac5b

Browse files
committed
Move core broadcast to core package
1 parent a997508 commit 583ac5b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/StaticArraysCore.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,37 @@ const StaticVector{N, T} = StaticArray{Tuple{N}, T, 1}
4040
const StaticMatrix{N, M, T} = StaticArray{Tuple{N, M}, T, 2}
4141
const StaticVecOrMat{T} = Union{StaticVector{<:Any, T}, StaticMatrix{<:Any, <:Any, T}}
4242

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+
4374
include("staticarrays.jl")
4475
include("utils.jl")
4576
include("staticsize.jl")

0 commit comments

Comments
 (0)