Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperrectangle: revise docs entries, shorten docs, shorten signature #3691

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/lib/interfaces/AbstractHyperrectangle.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ high(::AbstractHyperrectangle, ::Int)
isflat(::AbstractHyperrectangle)
low(::AbstractHyperrectangle)
low(::AbstractHyperrectangle, ::Int)
ngens(::AbstractHyperrectangle{N}) where {N}
ngens(::AbstractHyperrectangle)
norm(::AbstractHyperrectangle, ::Real=Inf)
radius(::AbstractHyperrectangle, ::Real=Inf)
radius_hyperrectangle(::AbstractHyperrectangle, ::Int)
Expand All @@ -46,7 +46,7 @@ vertices_list(::AbstractHyperrectangle)
volume(::AbstractHyperrectangle)
distance(::AbstractVector, ::AbstractHyperrectangle{N}; ::Real=N(2)) where {N}
∈(::AbstractVector, ::AbstractHyperrectangle)
split(::AbstractHyperrectangle{N}, ::AbstractVector{Int}) where {N}
split(::AbstractHyperrectangle, ::AbstractVector{Int})
ρ(::AbstractVector, ::AbstractHyperrectangle)
σ(::AbstractVector, ::AbstractHyperrectangle)
```
Expand Down
96 changes: 91 additions & 5 deletions docs/src/lib/sets/Hyperrectangle.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Hyperrectangle

## Conversion

```@docs
```julia
convert(::Type{Hyperrectangle}, ::AbstractHyperrectangle)
convert(::Type{Hyperrectangle}, ::IA.IntervalBox)
convert(::Type{IA.IntervalBox}, ::AbstractHyperrectangle)
Expand All @@ -19,44 +19,118 @@ convert(::Type{IA.IntervalBox}, ::AbstractHyperrectangle)
## Operations

```@docs
center(::Hyperrectangle)
radius_hyperrectangle(::Hyperrectangle)
radius_hyperrectangle(::Hyperrectangle, ::Int)
```
```@meta
CurrentModule = LazySets.API
```
```@docs; canonical=false
rand(::Type{LazySet})
```
```@meta
CurrentModule = LazySets.HyperrectangleModule
```
```@docs
rand(::Type{Hyperrectangle})
permute(::Hyperrectangle, ::AbstractVector{Int})
```
```@meta
CurrentModule = LazySets.API
```
```@docs; canonical=false
translate(::LazySet, ::AbstractVector)
```
```@meta
CurrentModule = LazySets.HyperrectangleModule
```
```@docs
translate(::Hyperrectangle, ::AbstractVector)
```

```@meta
CurrentModule = LazySets.API
```

Undocumented implementations:

* [`center`](@ref center(::LazySet))
```@meta
CurrentModule = LazySets
```
* [`genmat`](@ref genmat(::AbstractHyperrectangle))
```@meta
CurrentModule = LazySets.API
```
* [`isoperationtype`](@ref isoperationtype(::Type{LazySet}))
* [`permute`](@ref permute(::LazySet, ::AbstractVector))
* [`scale!`](@ref scale!(::Real, ::LazySet))
* [`ρ`](@ref ρ(::AbstractVector, ::LazySet))
* [`σ`](@ref σ(::AbstractVector, ::LazySet))
* [`translate!`](@ref translate!(::LazySet, ::AbstractVector))

```@meta
CurrentModule = LazySets
```

Inherited from [`LazySet`](@ref):
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`concretize`](@ref concretize(::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet))
* `copy(::Type{LazySet})`
* [`diameter`](@ref diameter(::LazySet, ::Real=Inf))
* [`eltype`](@ref eltype(::Type{<:LazySet}))
* [`eltype`](@ref eltype(::LazySet))
* [`isoperation`](@ref isoperation(::LazySet))
* [`sample`](@ref sample(::LazySet, ::Int=1))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`surface`](@ref surface(::LazySet))
* [`vertices`](@ref vertices(::LazySet))
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
* [`scale`](@ref scale(::Real, ::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
* [`==`](@ref ==(::LazySet, ::LazySet))
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [`⊂`](@ref ⊂(::LazySet, ::LazySet))

Inherited from [`ConvexSet`](@ref):
* [`linear_combination`](@ref linear_combination(::ConvexSet, ::ConvexSet))

Inherited from [`AbstractPolyhedron`](@ref):
* [`ispolyhedral`](@ref ispolyhedral(::AbstractPolyhedron))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
* [`isuniversal`](@ref isuniversal(::AbstractPolytope, ::Bool=false))
* [`isboundedtype`](@ref isboundedtype(::Type{LazySet}))

Inherited from [`AbstractCentrallySymmetricPolytope`](@ref):
* [`an_element`](@ref an_element(::AbstractCentrallySymmetricPolytope))
* [`center`](@ref center(::AbstractCentrallySymmetricPolytope, ::Int))
* [`dim`](@ref dim(::AbstractCentrallySymmetricPolytope))
* [`isempty`](@ref isempty(::AbstractCentrallySymmetricPolytope))
* [`isuniversal`](@ref isuniversal(::AbstractCentrallySymmetricPolytope))

Inherited from [`AbstractZonotope`](@ref):
* [`order`](@ref order(::AbstractZonotope))
* [`remove_redundant_generators`](@ref remove_redundant_generators(::AbstractZonotope))
* [`togrep`](@ref togrep(::AbstractZonotope))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`reduce_order`](@ref reduce_order(::AbstractZonotope, ::Real, ::AbstractReductionMethod=GIR05()))
* [`split`](@ref split(::AbstractZonotope, ::Int))
* [`split`](@ref split(::AbstractZonotope, ::AbstractVector{Int}, ::AbstractVector{Int}))

Inherited from [`AbstractHyperrectangle`](@ref):
* [`area`](@ref area(::AbstractHyperrectangle))
* [`constraints_list`](@ref constraints_list(::AbstractHyperrectangle))
* [`extrema`](@ref extrema(::AbstractHyperrectangle))
* [`extrema`](@ref extrema(::AbstractHyperrectangle, ::Int))
* [`generators`](@ref generators(::AbstractHyperrectangle))
* [`genmat`](@ref genmat(::AbstractHyperrectangle))
* [`high`](@ref high(::AbstractHyperrectangle))
* [`high`](@ref high(::AbstractHyperrectangle, ::Int))
* [`isconvextype`](@ref isconvextype(::Type{AbstractHyperrectangle}))
* [`isflat`](@ref isflat(::Hyperrectangle))
* [`low`](@ref low(::AbstractHyperrectangle))
* [`low`](@ref low(::AbstractHyperrectangle, ::Int))
Expand All @@ -66,6 +140,18 @@ Inherited from [`AbstractHyperrectangle`](@ref):
* [`rectify`](@ref rectify(::AbstractHyperrectangle))
* [`reflect`](@ref reflect(::AbstractHyperrectangle))
* [`vertices_list`](@ref vertices_list(::AbstractHyperrectangle))
* [`volume`](@ref volume(::AbstractHyperrectangle))
* [`distance`](@ref distance(::AbstractVector, ::AbstractHyperrectangle{N}; ::Real=N(2)) where {N})
* [`∈`](@ref ∈(::AbstractVector, ::AbstractHyperrectangle))
* [`project`](@ref project(::AbstractHyperrectangle, ::AbstractVector))
* [`split`](@ref split(::AbstractHyperrectangle, ::AbstractVector{Int}))
* [`ρ`](@ref ρ(::AbstractVector, ::AbstractHyperrectangle))
* [`σ`](@ref σ(::AbstractVector, ::AbstractHyperrectangle))
* [`cartesian_product`](@ref cartesian_product(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`difference`](@ref difference(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`distance`](@ref distance(::AbstractHyperrectangle, ::AbstractHyperrectangle; ::Real=2.0))
* [`intersection`](@ref intersection(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`isdisjoint`](@ref isdisjoint(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`⊆`](@ref ⊆(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`minkowski_difference`](@ref minkowski_difference(::AbstractHyperrectangle, ::AbstractHyperrectangle))
* [`minkowski_sum`](@ref minkowski_sum(::AbstractHyperrectangle, ::AbstractHyperrectangle))
12 changes: 6 additions & 6 deletions src/Interfaces/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function generators(H::AbstractHyperrectangle)
end

"""
ngens(H::AbstractHyperrectangle{N}) where {N}
ngens(H::AbstractHyperrectangle)

Return the number of generators of a hyperrectangular set.

Expand All @@ -199,7 +199,8 @@ The number of generators.

A hyperrectangular set has one generator for each non-flat dimension.
"""
function ngens(H::AbstractHyperrectangle{N}) where {N}
function ngens(H::AbstractHyperrectangle)
N = eltype(H)
return sum(i -> radius_hyperrectangle(H, i) > zero(N), 1:dim(H))
end

Expand Down Expand Up @@ -650,8 +651,7 @@ function isflat(H::AbstractHyperrectangle)
end

"""
split(H::AbstractHyperrectangle{N},
num_blocks::AbstractVector{Int}) where {N}
split(H::AbstractHyperrectangle, num_blocks::AbstractVector{Int})

Partition a hyperrectangular set into uniform sub-hyperrectangles.

Expand All @@ -664,8 +664,7 @@ Partition a hyperrectangular set into uniform sub-hyperrectangles.

A list of `Hyperrectangle`s.
"""
function split(H::AbstractHyperrectangle{N},
num_blocks::AbstractVector{Int}) where {N}
function split(H::AbstractHyperrectangle, num_blocks::AbstractVector{Int})
@assert length(num_blocks) == dim(H) "the number of blocks " *
"($(length(num_blocks))) must be specified in each dimension ($(dim(H)))"
R = radius_hyperrectangle(H)
Expand All @@ -676,6 +675,7 @@ function split(H::AbstractHyperrectangle{N},
total_number = 1
lo = low(H)
hi = high(H)
N = eltype(H)

# precompute center points in each dimension
centers = Vector{StepRangeLen{N}}(undef, dim(H))
Expand Down
13 changes: 0 additions & 13 deletions src/Sets/Hyperrectangle/center.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
"""
center(H::Hyperrectangle)

Return the center of a hyperrectangle.

### Input

- `H` -- hyperrectangle

### Output

The center of the hyperrectangle.
"""
function center(H::Hyperrectangle)
return H.center
end
56 changes: 0 additions & 56 deletions src/Sets/Hyperrectangle/convert.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
"""
convert(::Type{Hyperrectangle}, H::AbstractHyperrectangle)

Convert a hyperrectangular set to a hyperrectangle.

### Input

- `Hyperrectangle` -- hyperrectangle target type
- `H` -- hyperrectangular set

### Output

A hyperrectangle.

### Examples

```jldoctest
julia> convert(Hyperrectangle, Interval(0.0, 1.0))
Hyperrectangle{Float64, Vector{Float64}, Vector{Float64}}([0.5], [0.5])
```
"""
function convert(::Type{Hyperrectangle}, H::AbstractHyperrectangle)
return Hyperrectangle(center(H), radius_hyperrectangle(H))
end
Expand All @@ -27,51 +6,16 @@ function load_IntervalArithmetic_convert()
return quote
import IntervalArithmetic as IA

"""
convert(::Type{IntervalArithmetic.IntervalBox}, H::AbstractHyperrectangle)

Convert a hyperrectangular set to an `IntervalBox` from `IntervalArithmetic`.

### Input

- `IntervalBox` -- target type
- `H` -- hyperrectangular set

### Output

An `IntervalBox`.
"""
function convert(::Type{IA.IntervalBox}, H::AbstractHyperrectangle)
return IA.IntervalBox(IA.interval.(low(H), high(H)))
end

"""
convert(::Type{Hyperrectangle}, IB::IntervalArithmetic.IntervalBox)

Convert an `IntervalBox` from `IntervalArithmetic` to a hyperrectangular set.

### Input

- `Hyperrectangle` -- target type
- `IB` -- interval box

### Output

A `Hyperrectangle`.

### Notes

`IntervalArithmetic.IntervalBox` uses *static* vectors to store each component
interval; hence the resulting `Hyperrectangle` has its center and radius
represented as a static vector (`SArray`).
"""
function convert(::Type{Hyperrectangle}, IB::IA.IntervalBox)
low_IB = IA.inf.(IB)
high_IB = IA.sup.(IB)
return Hyperrectangle(; low=low_IB, high=high_IB)
end

# method for Interval
function convert(::Type{Hyperrectangle}, I::IA.Interval)
low_I = [IA.inf(I)]
high_I = [IA.sup(I)]
Expand Down
14 changes: 0 additions & 14 deletions src/Sets/Hyperrectangle/permute.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
"""
permute(H::Hyperrectangle, p::AbstractVector{Int})

Permute the dimensions according to a permutation vector.

### Input

- `H` -- hyperrectangle
- `p` -- permutation vector

### Output

A permuted hyperrectangle.
"""
function permute(H::Hyperrectangle, p::AbstractVector{Int})
c = H.center[p]
r = H.radius[p]
Expand Down
16 changes: 2 additions & 14 deletions src/Sets/Hyperrectangle/rand.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
"""
# Extended help

rand(::Type{Hyperrectangle}; [N]::Type{<:Real}=Float64, [dim]::Int=2,
[rng]::AbstractRNG=GLOBAL_RNG, [seed]::Union{Int, Nothing}=nothing)

Create a random hyperrectangle.

### Input

- `Hyperrectangle` -- type for dispatch
- `N` -- (optional, default: `Float64`) numeric type
- `dim` -- (optional, default: 2) dimension
- `rng` -- (optional, default: `GLOBAL_RNG`) random number generator
- `seed` -- (optional, default: `nothing`) seed for reseeding

### Output

A random hyperrectangle.

### Algorithm

All numbers are normally distributed with mean 0 and standard deviation 1.
Expand Down
12 changes: 2 additions & 10 deletions src/Sets/Hyperrectangle/translate.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
translate(H::Hyperrectangle, v::AbstractVector; [share]::Bool=false)
# Extended help

Translate (i.e., shift) a hyperrectangle by a given vector.
translate(H::Hyperrectangle, v::AbstractVector; [share]::Bool=false)

### Input

Expand All @@ -10,17 +10,9 @@ Translate (i.e., shift) a hyperrectangle by a given vector.
- `share` -- (optional, default: `false`) flag for sharing unmodified parts of
the original set representation

### Output

A translated hyperrectangle.

### Notes

The radius vector is shared with the original hyperrectangle if `share == true`.

### Algorithm

We add the vector to the center of the hyperrectangle.
"""
function translate(H::Hyperrectangle, v::AbstractVector; share::Bool=false)
@assert length(v) == dim(H) "cannot translate a $(dim(H))-dimensional " *
Expand Down
Loading