Skip to content

Commit

Permalink
#58 - added common functions for SingleSet
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 14, 2017
1 parent 9830c76 commit 355259d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SingleSet.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export SingleSet
export SingleSet,
element

"""
SingleSet{N<:Real} <: Box{N}
Expand Down
35 changes: 35 additions & 0 deletions src/Singleton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,41 @@ struct Singleton{N<:Real} <: SingleSet{N}
element::Vector{N}
end

"""
element(S::Singleton{N})::Vector{N} where {N<:Real}
Return the element of a singleton.
### Input
- `S` -- singleton
### Output
The element of the singleton.
"""
function element(S::Singleton{N})::Vector{N} where {N<:Real}
return S.element
end

"""
element(S::Singleton{N}, i::Int)::N where {N<:Real}
Return the i-th entry of the element of a singleton.
### Input
- `S` -- singleton
- `i` -- dimension
### Output
The i-th entry of the element of the singleton.
"""
function element(S::Singleton{N}, i::Int)::N where {N<:Real}
return S.element[i]
end

"""
dim(S::Singleton)::Int
Expand Down
35 changes: 35 additions & 0 deletions src/ZeroSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ end
# type-less convenience constructor
ZeroSet(dim::Int) = ZeroSet{Float64}(dim)

"""
element(S::ZeroSet{N})::Vector{N} where {N<:Real}
Return the element of a zero set.
### Input
- `S` -- zero set
### Output
The element of the zero set, i.e., a zero vector.
"""
function element(S::ZeroSet{N})::Vector{N} where {N<:Real}
return zeros(N, S.dim)
end

"""
element(S::ZeroSet{N}, ::Int)::N where {N<:Real}
Return the i-th entry of the element of a zero set.
### Input
- `S` -- zero set
- `i` -- dimension
### Output
The i-th entry of the element of the zero set, i.e., 0.
"""
function element(S::ZeroSet{N}, ::Int)::N where {N<:Real}
return zero(N)
end

"""
dim(Z::ZeroSet)::Int
Expand Down

0 comments on commit 355259d

Please sign in to comment.