Skip to content

Commit

Permalink
review AbstractHyperrectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jun 17, 2019
1 parent c575be8 commit 516a320
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,44 @@ end
# iterator that wraps the generator matrix
struct HyperrectangleGeneratorIterator{AH<:AbstractHyperrectangle}
H::AH
len::Int
nonflats::Vector{Int} # dimensions along which `H` is not flat
dim::Int # total number of dimensions of `H` (stored for efficiency)

function HyperrectangleGeneratorIterator(H::AH) where {N<:Real,
AH<:AbstractHyperrectangle{N}}
len = dim(H)
for i in 1:len
if radius_hyperrectangle(H, i) == zero(N)
len -= 1
n = dim(H)
nonflats = Vector{Int}()
sizehint!(nonflats, n)
@inbounds for i in 1:n
if radius_hyperrectangle(H, i) != zero(N)
push(nonflats, i)
end
end
return new{AH}(H, len)
return new{AH}(H, nonflats, n)
end
end

Base.length(it::HyperrectangleGeneratorIterator) = it.len
Base.length(it::HyperrectangleGeneratorIterator) = length(it.nonflats)

Base.eltype(::Type{<:HyperrectangleGeneratorIterator{<:AbstractHyperrectangle{N}}}) where {N} =
Approximations.UnitVector{N}

function Base.iterate(it::HyperrectangleGeneratorIterator{<:AH},
state::Int=1) where {N, AH<:AbstractHyperrectangle{N}}
local r
while true
if state > dim(it.H)
return nothing
end
r = radius_hyperrectangle(it.H, state)
if r != zero(N)
break
end
state += 1
if state > length(it.nonflats)
return nothing
end
g = Approximations.UnitVector(state, dim(it.H), r)
i = it.nonflats[state]
r = radius_hyperrectangle(it.H, i)
g = Approximations.UnitVector(i, it.dim, r)
state += 1
return (g, state)
end

"""
generators(H::AbstractHyperrectangle)
Return an iterator over the (single) generator of a hyperrectangular set.
Return an iterator over the generators of a hyperrectangular set.
### Input
Expand Down

0 comments on commit 516a320

Please sign in to comment.