Skip to content

Commit a46c084

Browse files
committed
Define similar_type and StaticArrayStyle in core package.
See JuliaArrays/StaticArraysCore.jl#5 and JuliaArrays/StaticArraysCore.jl#8
1 parent 0f68fdb commit a46c084

File tree

3 files changed

+3
-26
lines changed

3 files changed

+3
-26
lines changed

src/StaticArrays.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ using StaticArraysCore: StaticArraysCore, StaticArray, StaticScalar, StaticVecto
2828
StaticMatrix, StaticVecOrMat, tuple_length, tuple_prod,
2929
tuple_minimum, size_to_tuple, require_one_based_indexing
3030
using StaticArraysCore: FieldArray, FieldMatrix, FieldVector
31+
using StaticArraysCore: StaticArrayStyle
3132
import StaticArraysCore: SArray, SVector, SMatrix
3233
import StaticArraysCore: MArray, MVector, MMatrix
3334
import StaticArraysCore: SizedArray, SizedVector, SizedMatrix
3435
import StaticArraysCore: check_array_parameters, convert_ntuple
36+
import StaticArraysCore: similar_type
3537

3638
# end of StaticArraysCore imports
3739
# StaticArraysCore exports

src/abstractarray.jl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,6 @@ end
3636
Base.IndexStyle(::Type{T}) where {T<:StaticArray} = IndexLinear()
3737

3838
# Default type search for similar_type
39-
"""
40-
similar_type(static_array)
41-
similar_type(static_array, T)
42-
similar_type(array, ::Size)
43-
similar_type(array, T, ::Size)
44-
45-
Returns a constructor for a statically-sized array similar to the input array
46-
(or type) `static_array`/`array`, optionally with different element type `T` or size
47-
`Size`. If the input `array` is not a `StaticArray` then the `Size` is mandatory.
48-
49-
This differs from `similar()` in that the resulting array type may not be
50-
mutable (or define `setindex!()`), and therefore the returned type may need to
51-
be *constructed* with its data.
52-
53-
Note that the (optional) size *must* be specified as a static `Size` object (so the compiler
54-
can infer the result statically).
55-
56-
New types should define the signature `similar_type(::Type{A},::Type{T},::Size{S}) where {A<:MyType,T,S}`
57-
if they wish to overload the default behavior.
58-
"""
59-
function similar_type end
60-
6139
similar_type(::SA) where {SA<:StaticArrayLike} = similar_type(SA,eltype(SA))
6240
similar_type(::Type{SA}) where {SA<:StaticArrayLike} = similar_type(SA,eltype(SA))
6341

src/broadcast.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ using Base.Broadcast: broadcast_shape, _broadcast_getindex, combine_axes
77
import Base.Broadcast: BroadcastStyle, materialize!, instantiate
88
import Base.Broadcast: _bcs1 # for SOneTo axis information
99
using Base.Broadcast: _bcsm
10-
# Add a new BroadcastStyle for StaticArrays, derived from AbstractArrayStyle
11-
# A constructor that changes the style parameter N (array dimension) is also required
12-
struct StaticArrayStyle{N} <: AbstractArrayStyle{N} end
13-
StaticArrayStyle{M}(::Val{N}) where {M,N} = StaticArrayStyle{N}()
10+
1411
BroadcastStyle(::Type{<:StaticArray{<:Tuple, <:Any, N}}) where {N} = StaticArrayStyle{N}()
1512
BroadcastStyle(::Type{<:Transpose{<:Any, <:StaticArray}}) = StaticArrayStyle{2}()
1613
BroadcastStyle(::Type{<:Adjoint{<:Any, <:StaticArray}}) = StaticArrayStyle{2}()

0 commit comments

Comments
 (0)