Skip to content

Commit c67aa77

Browse files
authored
Speed up iteration for IntervalBox (#177)
* Speed up iteration for IntervalBox * Tweaks * Inline broadcast
1 parent 12d1a6c commit c67aa77

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/multidim/arithmetic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
wrap(v::SVector{N,T} where {N,T<:Interval}) = IntervalBox(v)
2222
wrap(v) = v
2323

24-
Base.broadcast(f, X::IntervalBox) = wrap(f.(X.v))
25-
Base.broadcast(f, X::IntervalBox, Y::IntervalBox) = wrap(f.(X.v, Y.v))
26-
Base.broadcast(f, X::IntervalBox, y) = wrap(f.(X.v, y))
24+
@inline Base.broadcast(f, X::IntervalBox) = wrap(f.(X.v))
25+
@inline Base.broadcast(f, X::IntervalBox, Y::IntervalBox) = wrap(f.(X.v, Y.v))
26+
@inline Base.broadcast(f, X::IntervalBox, y) = wrap(f.(X.v, y))
2727

2828
for op in (:+, :-, :, :, :, :isinterior, :dot, :setdiff, :×)
2929
@eval $(op)(a::SVector, b::IntervalBox) = $(op)(IntervalBox(a), b)

src/multidim/intervalbox.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ done(X::IntervalBox{N,T}, state) where {N,T} = state > N
3232

3333
eltype(::Type{IntervalBox{N,T}}) where {N,T} = Interval{T} # Note that this is defined for the type
3434

35-
# length(X::IntervalBox{N,T}) where {N,T} = N
35+
length(X::IntervalBox{N,T}) where {N,T} = N
3636

3737

3838

@@ -49,7 +49,7 @@ Return a vector of the `mid` of each interval composing the `IntervalBox`.
4949
5050
See `mid(X::Interval, α=0.5)` for more informations.
5151
"""
52-
mid(X::IntervalBox) = mid.(X)
52+
mid(X::IntervalBox) = mid.(X.v)
5353
mid(X::IntervalBox, α) = mid.(X.v, α)
5454

5555
big(X::IntervalBox) = big.(X)
@@ -95,4 +95,3 @@ IntervalBox(x::Interval, ::Type{Val{n}}) where {n} = IntervalBox(SVector(ntuple(
9595
IntervalBox(x::Interval, n::Int) = IntervalBox(x, Val{n})
9696

9797
dot(x::IntervalBox, y::IntervalBox) = dot(x.v, y.v)
98-
length(x::IntervalBox) = length(x.v)

0 commit comments

Comments
 (0)