Skip to content

Commit 8f195da

Browse files
authored
Merge pull request #338 from JuliaArrays/sd/extrema
fix extrema
2 parents 7059baf + ae51586 commit 8f195da

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/FixedSizeArrays.jl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ end
7474
export unit
7575

7676
function Base.extrema(a::AbstractVector{T}) where T <: StaticVector
77-
reduce((x, v)-> (min.(x[1], v), max.(x[2], v)), a)
77+
ET = eltype(T)
78+
reduce((x, v)-> (min.(x[1], v), max.(x[2], v)), (T(typemax(ET)), T(typemin(ET))), a)
7879
end
7980
function Base.minimum(a::AbstractVector{T}) where T <: StaticVector
80-
reduce((x, v)-> min.(x[1], v), a)
81+
reduce((x, v)-> min.(x[1], v), T(typemax(eltype(T))), a)
8182
end
8283
function Base.maximum(a::AbstractVector{T}) where T <: StaticVector
83-
reduce((x, v)-> max.(x[1], v), a)
84+
reduce((x, v)-> max.(x[1], v), T(typemin(eltype(T))), a)
8485
end
8586

8687

@@ -98,6 +99,15 @@ macro fixed_vector(name, parent)
9899
new{S, T}(StaticArrays.convert_ntuple(T, x))
99100
end
100101
end
102+
size_or(::Type{$(name)}, or) = or
103+
eltype_or(::Type{$(name)}, or) = or
104+
eltype_or(::Type{$(name){S, T} where S}, or) where {T} = T
105+
eltype_or(::Type{$(name){S, T} where T}, or) where {S} = or
106+
eltype_or(::Type{$(name){S, T}}, or) where {S, T} = T
107+
108+
size_or(::Type{$(name){S, T} where S}, or) where {T} = or
109+
size_or(::Type{$(name){S, T} where T}, or) where {S} = Size{(S,)}()
110+
size_or(::Type{$(name){S, T}}, or) where {S, T} = (S,)
101111
# Array constructor
102112
@inline function (::Type{$(name){S}})(x::AbstractVector{T}) where {S, T}
103113
@assert S <= length(x)
@@ -168,15 +178,7 @@ macro fixed_vector(name, parent)
168178
StaticArrays.default_similar_type(T,s(),Val{length(S)})
169179
end
170180
end
171-
size_or(::Type{$(name)}, or) = or
172-
eltype_or(::Type{$(name)}, or) = or
173-
eltype_or(::Type{$(name){S, T} where S}, or) where {T} = T
174-
eltype_or(::Type{$(name){S, T} where T}, or) where {S} = or
175-
eltype_or(::Type{$(name){S, T}}, or) where {S, T} = T
176181

177-
size_or(::Type{$(name){S, T} where S}, or) where {T} = or
178-
size_or(::Type{$(name){S, T} where T}, or) where {S} = Size{(S,)}()
179-
size_or(::Type{$(name){S, T}}, or) where {S, T} = (S,)
180182
end)
181183
end
182184

0 commit comments

Comments
 (0)