Skip to content

Commit a5ab6fd

Browse files
committed
handle map like StaticArrays
1 parent 454cd4e commit a5ab6fd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/fixed_arrays.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using LinearAlgebra
33
import Random
44
import Base: setindex
55

6-
abstract type StaticVector{N, T} end
6+
abstract type StaticVector{N, T} <: AbstractVector{T} end
77
function similar_type end
88

99
struct StaticArrayStyle{T, AsConst} <: Broadcast.BroadcastStyle end
@@ -119,7 +119,7 @@ Base.BroadcastStyle(::Broadcast.BroadcastStyle, ::StaticArrayStyle{T, B}) where
119119
# StaticArrayStyle{preffered_type, B1 || B2}()
120120

121121
# If we don't inherit from AbstractVector we need this?
122-
Base.broadcastable(x::StaticVector) = x
122+
# Base.broadcastable(x::StaticVector) = x
123123

124124
# Required to avoid size missmatches between Array and StaticVector
125125
function Broadcast.instantiate(bc::Broadcast.Broadcasted{<: StaticArrayStyle{<: Any, true}})
@@ -143,7 +143,9 @@ function Base.copy(bc::Broadcast.Broadcasted{StaticArrayStyle{T, false}}) where
143143
return T(broadcast(bc.f, args...))
144144
end
145145

146-
Base.map(f, b::StaticVector) = similar_type(b)(map(f, b.data))
146+
Base.map(f, a::StaticVector, args::AbstractArray...) = broadcast(f, a, args...)
147+
Base.map(f, a::AbstractArray, b::StaticVector, args::AbstractArray...) = broadcast(f, a, b, args...)
148+
Base.map(f, a::StaticVector, b::StaticVector, args::AbstractArray...) = broadcast(f, a, b, args...)
147149

148150
function Random.rand(rng::Random.AbstractRNG, ::Random.SamplerType{V}) where V <: StaticVector{N,T} where {N, T}
149151
V(ntuple(i-> rand(rng, T), N))

0 commit comments

Comments
 (0)