Skip to content

Commit 159befb

Browse files
N5N3mateuszbaran
andauthored
Define similar_type and StaticArrayStyle in the core package. (#1084)
* Define `similar_type` and `StaticArrayStyle` in core package. See JuliaArrays/StaticArraysCore.jl#5 and JuliaArrays/StaticArraysCore.jl#8 * Bump version * Update Project.toml Co-authored-by: Mateusz Baran <[email protected]> Co-authored-by: Mateusz Baran <[email protected]>
1 parent 0f68fdb commit 159befb

File tree

4 files changed

+5
-28
lines changed

4 files changed

+5
-28
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StaticArrays"
22
uuid = "90137ffa-7385-5640-81b9-e52037218182"
3-
version = "1.5.5"
3+
version = "1.5.6"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -10,7 +10,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1010

1111
[compat]
1212
julia = "1.6"
13-
StaticArraysCore = "~1.1"
13+
StaticArraysCore = "~1.3.0"
1414

1515
[extras]
1616
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"

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)