Skip to content

Commit

Permalink
Define similar_type and StaticArrayStyle in the core package. (#1084
Browse files Browse the repository at this point in the history
)

* 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 <mateuszbaran89@gmail.com>

Co-authored-by: Mateusz Baran <mateuszbaran89@gmail.com>
  • Loading branch information
N5N3 and mateuszbaran authored Aug 24, 2022
1 parent 0f68fdb commit 159befb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StaticArrays"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.5.5"
version = "1.5.6"

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

[compat]
julia = "1.6"
StaticArraysCore = "~1.1"
StaticArraysCore = "~1.3.0"

[extras]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
2 changes: 2 additions & 0 deletions src/StaticArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ using StaticArraysCore: StaticArraysCore, StaticArray, StaticScalar, StaticVecto
StaticMatrix, StaticVecOrMat, tuple_length, tuple_prod,
tuple_minimum, size_to_tuple, require_one_based_indexing
using StaticArraysCore: FieldArray, FieldMatrix, FieldVector
using StaticArraysCore: StaticArrayStyle
import StaticArraysCore: SArray, SVector, SMatrix
import StaticArraysCore: MArray, MVector, MMatrix
import StaticArraysCore: SizedArray, SizedVector, SizedMatrix
import StaticArraysCore: check_array_parameters, convert_ntuple
import StaticArraysCore: similar_type

# end of StaticArraysCore imports
# StaticArraysCore exports
Expand Down
22 changes: 0 additions & 22 deletions src/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,6 @@ end
Base.IndexStyle(::Type{T}) where {T<:StaticArray} = IndexLinear()

# Default type search for similar_type
"""
similar_type(static_array)
similar_type(static_array, T)
similar_type(array, ::Size)
similar_type(array, T, ::Size)
Returns a constructor for a statically-sized array similar to the input array
(or type) `static_array`/`array`, optionally with different element type `T` or size
`Size`. If the input `array` is not a `StaticArray` then the `Size` is mandatory.
This differs from `similar()` in that the resulting array type may not be
mutable (or define `setindex!()`), and therefore the returned type may need to
be *constructed* with its data.
Note that the (optional) size *must* be specified as a static `Size` object (so the compiler
can infer the result statically).
New types should define the signature `similar_type(::Type{A},::Type{T},::Size{S}) where {A<:MyType,T,S}`
if they wish to overload the default behavior.
"""
function similar_type end

similar_type(::SA) where {SA<:StaticArrayLike} = similar_type(SA,eltype(SA))
similar_type(::Type{SA}) where {SA<:StaticArrayLike} = similar_type(SA,eltype(SA))

Expand Down
5 changes: 1 addition & 4 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ using Base.Broadcast: broadcast_shape, _broadcast_getindex, combine_axes
import Base.Broadcast: BroadcastStyle, materialize!, instantiate
import Base.Broadcast: _bcs1 # for SOneTo axis information
using Base.Broadcast: _bcsm
# Add a new BroadcastStyle for StaticArrays, derived from AbstractArrayStyle
# A constructor that changes the style parameter N (array dimension) is also required
struct StaticArrayStyle{N} <: AbstractArrayStyle{N} end
StaticArrayStyle{M}(::Val{N}) where {M,N} = StaticArrayStyle{N}()

BroadcastStyle(::Type{<:StaticArray{<:Tuple, <:Any, N}}) where {N} = StaticArrayStyle{N}()
BroadcastStyle(::Type{<:Transpose{<:Any, <:StaticArray}}) = StaticArrayStyle{2}()
BroadcastStyle(::Type{<:Adjoint{<:Any, <:StaticArray}}) = StaticArrayStyle{2}()
Expand Down

2 comments on commit 159befb

@mateuszbaran
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66933

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.6 -m "<description of version>" 159befb43caae9728844f2e239b20977e662314b
git push origin v1.5.6

Please sign in to comment.