diff --git a/src/Sets/Ballp.jl b/src/Sets/Ballp.jl index c2897e2411..80f2d0e7fc 100644 --- a/src/Sets/Ballp.jl +++ b/src/Sets/Ballp.jl @@ -4,7 +4,7 @@ import Base: rand, export Ballp """ - Ballp{N<:AbstractFloat} <: AbstractCentrallySymmetric{N} + Ballp{N<:AbstractFloat, VN<:AbstractVector{N}} <: AbstractCentrallySymmetric{N} Type that represents a ball in the p-norm, for ``1 ≤ p ≤ ∞``. @@ -36,7 +36,8 @@ A five-dimensional ball in the ``p=3/2`` norm centered at the origin of radius ```jldoctest ballp_constructor julia> B = Ballp(3/2, zeros(5), 0.5) -Ballp{Float64}(1.5, [0.0, 0.0, 0.0, 0.0, 0.0], 0.5) +Ballp{Float64,Array{Float64,1}}(1.5, [0.0, 0.0, 0.0, 0.0, 0.0], 0.5) + julia> dim(B) 5 ``` @@ -53,13 +54,13 @@ julia> σ([1., 2, 3, 4, 5], B) 0.33790011086518895 ``` """ -struct Ballp{N<:AbstractFloat} <: AbstractCentrallySymmetric{N} +struct Ballp{N<:AbstractFloat, VN<:AbstractVector{N}} <: AbstractCentrallySymmetric{N} p::N - center::Vector{N} + center::VN radius::N # default constructor with domain constraint for radius and p - function Ballp(p::N, center::Vector{N}, radius::N) where {N<:Real} + function Ballp(p::N, center::VN, radius::N) where {N<:Real, VN<:AbstractVector{N}} @assert radius >= zero(N) "radius must not be negative" @assert p >= 1 "p must not be less than 1" if p == Inf @@ -69,7 +70,7 @@ struct Ballp{N<:AbstractFloat} <: AbstractCentrallySymmetric{N} elseif p == 1 return Ball1(center, radius) else - return new{N}(p, center, radius) + return new{N, VN}(p, center, radius) end end end @@ -180,9 +181,11 @@ Then ``x ∈ B`` iff ``\\left( ∑_{i=1}^n |c_i - x_i|^p \\right)^{1/p} ≤ r``. ```jldoctest julia> B = Ballp(1.5, [1., 1.], 1.) -Ballp{Float64}(1.5, [1.0, 1.0], 1.0) +Ballp{Float64,Array{Float64,1}}(1.5, [1.0, 1.0], 1.0) + julia> [.5, -.5] ∈ B false + julia> [.5, 1.5] ∈ B true ```