Skip to content

Commit 23d5117

Browse files
committed
Formatted and fixed doctests
1 parent 8f8d57d commit 23d5117

File tree

8 files changed

+32
-26
lines changed

8 files changed

+32
-26
lines changed

docs/src/lib/sets/ZonotopeMD.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
CurrentModule = LazySets.ZonotopeModule
33
```
44

5-
# [Zonotope](@id def_ZonotopeMD)
5+
# [ZonotopeMD](@id def_ZonotopeMD)
66

77
```@docs
88
ZonotopeMD
99
```
1010

1111
## Operations
12+
1213
```@docs
1314
genmat(::ZonotopeMD)
14-
cartesian_product(Z1::ZonotopeMD, Z2::ZonotopeMD)
15-
```
16-
17-
Undocumented implementations:
18-
19-
* [`center`](@ref center(::LazySet))
20-
* [`ngens`](@ref ngens(::AbstractZonotope))
15+
cartesian_product(::ZonotopeMD, ::ZonotopeMD)
16+
center(::ZonotopeMD)
17+
ngens(::ZonotopeMD)
18+
```

src/Sets/Zonotope/ZonotopeMD/ZonotopeMD.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,27 @@ Constructing a zonotope in normal form from a center, general generator matrix `
3030
3131
```jldoctest zonotopemd_label
3232
julia> c = [0.0, 0.0];
33+
3334
julia> M = [1.0 2.0; 3.0 1.0];
35+
3436
julia> d = [0.1, 0.2];
37+
3538
julia> Z = ZonotopeMD(c, M, d)
36-
ZonotopeMD{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}([0.0, 0.0], [1.0 0.0; 0.0 1.0], [0.1, 0.2])
39+
ZonotopeMD{Float64, Vector{Float64}, Matrix{Float64}, Vector{Float64}}([0.0, 0.0], [1.0 2.0; 3.0 1.0], [0.1, 0.2])
3740
3841
julia> center(Z)
3942
2-element Vector{Float64}:
4043
0.0
4144
0.0
4245
4346
julia> genmat(Z)
44-
2×4 Matrix{Float64}:
45-
1.0 2.0 0.1 0.0
46-
3.0 1.0 0.0 0.2
47+
2×4 SparseArrays.SparseMatrixCSC{Float64, Int64} with 6 stored entries:
48+
1.0 2.0 0.1
49+
3.0 1.0 ⋅ 0.1
4750
```
4851
4952
The generator matrix returned by `genmat` is the concatenation `[M D]`, where `D` is the diagonal matrix formed from `d`.
50-
53+
THe resulting matrix is stored as a sparse matrix.
5154
Constructing the same zonotope by passing the full generator matrix `[M D]` directly:
5255
5356
```jldoctest zonotopemd_label
@@ -64,32 +67,34 @@ You can also convert back to a standard `Zonotope` if needed:
6467
6568
```jldoctest zonotopemd_label
6669
julia> Zstd = Zonotope(Z)
67-
Zonotope{Float64, Vector{Float64}, Matrix{Float64}}([0.0, 0.0], [1.0 2.0 0.1 0.0; 3.0 1.0 0.0 0.2])
70+
Zonotope{Float64, Vector{Float64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}([0.0, 0.0], sparse([1, 2, 1, 2, 1, 2], [1, 1, 2, 2, 3, 4], [1.0, 3.0, 2.0, 1.0, 0.1, 0.2], 2, 4))
6871
```
6972
7073
"""
71-
struct ZonotopeMD{N,VN<: AbstractVector{N}, MN<:AbstractMatrix{N},DN<:AbstractVector{N}} <: AbstractZonotope{N}
74+
struct ZonotopeMD{N,VN<:AbstractVector{N},MN<:AbstractMatrix{N},DN<:AbstractVector{N}} <:
75+
AbstractZonotope{N}
7276
center::VN
7377
M::MN
7478
d::DN
7579

76-
function ZonotopeMD(center::VN, M::MN, d::DN) where {N,
77-
VN<:AbstractVector{N},
78-
MN<:AbstractMatrix{N},
79-
DN<:AbstractVector{N}}
80+
function ZonotopeMD(center::VN, M::MN,
81+
d::DN) where {N,
82+
VN<:AbstractVector{N},
83+
MN<:AbstractMatrix{N},
84+
DN<:AbstractVector{N}}
8085
@assert length(center) == size(M, 1) == length(d) "Dimensions must match"
8186
return new{N,VN,MN,DN}(center, M, d)
8287
end
8388
end
8489

8590
# constructor from generator matrix
86-
function ZonotopeMD(center::VN, G::AbstractMatrix{N}) where {N, VN<:AbstractVector{N}}
91+
function ZonotopeMD(center::VN, G::AbstractMatrix{N}) where {N,VN<:AbstractVector{N}}
8792
n, p = size(G)
8893
@assert p % n == 0 "The generator matrix must contain a multiple of n columns"
8994
@assert p >= 2n "Expected at least order 2 zonotope"
9095

9196
M = G[:, 1:(p - n)]
92-
D = G[:, end - n + 1:end]
97+
D = G[:, (end - n + 1):end]
9398

9499
@assert isdiag(D) "The last n columns of the generator matrix must be diagonal"
95100
d = diag(D)

src/Sets/Zonotope/ZonotopeMD/cartesian_product.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ function cartesian_product(Z1::ZonotopeMD, Z2::ZonotopeMD)
1717
d = vcat(Z1.d, Z2.d)
1818
M = blockdiag(sparse(Z1.M), sparse(Z2.M))
1919
return ZonotopeMD(c, M, d)
20-
end
20+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
function center(Z::ZonotopeMD)
22
return Z.center
3-
end
3+
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Zonotope(Z::ZonotopeMD) = convert(Zonotope, Z)
1+
Zonotope(Z::ZonotopeMD) = convert(Zonotope, Z)

src/Sets/Zonotope/ZonotopeMD/genmat.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ A matrix where each column represents one generator of the zonotope `Z`.
1414
function genmat(Z::ZonotopeMD)
1515
D = spdiagm(0 => Z.d)
1616
return hcat(Z.M, D)
17-
end
17+
end

src/Sets/Zonotope/ZonotopeMD/ngens.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ngens(Z::ZonotopeMD) = size(Z.M, 2) + length(Z.d)
1+
ngens(Z::ZonotopeMD) = size(Z.M, 2) + length(Z.d)

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ if test_suite_basic
150150
@testset "LazySets.Zonotope" begin
151151
include("Sets/Zonotope.jl")
152152
end
153+
@testset "LazySets.ZonotopeMD" begin
154+
include("Sets/ZonotopeMD.jl")
155+
end
153156
@testset "LazySets.ZeroSet" begin
154157
include("Sets/ZeroSet.jl")
155158
end

0 commit comments

Comments
 (0)