Skip to content

Commit

Permalink
Merge pull request #218 from JuliaReach/schillic/interval
Browse files Browse the repository at this point in the history
Change Interval constructor to interval
  • Loading branch information
schillic authored Aug 25, 2023
2 parents 533a6e5 + 2896db6 commit 69b072e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/correction_matrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function input_correction(A::IntervalMatrix{T}, t, p) where {T}
E = _exp_remainder(A, t, p; n=n)
F = E / opnorm(A, Inf)

id = IntervalMatrix(Interval(one(T)) * I, n)
id = IntervalMatrix(interval(one(T)) * I, n)
_correction_loop!(F, A, id, t, p)

return F
Expand All @@ -84,7 +84,7 @@ function _correction_loop!(F, A::IntervalMatrix{T}, Aⁱ, t, p) where {T}
@inbounds for i in 2:p
tⁱ *= t
left = (one(T) / i^(i / (i - 1)) - one(T) / i^(1 / (i - 1))) * tⁱ
itv = Interval(left, zero(T))
itv = interval(left, zero(T))
Aⁱ *= A
i! *= i
F .+= itv * Aⁱ / i!
Expand Down
8 changes: 4 additions & 4 deletions src/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function exp_underapproximation(A::IntervalMatrix{T}, t, p) where {T}
for i in 1:n
minYZ = min(Y[i, j], Z[i, j])
maxYZ = max(Y[i, j], Z[i, j])
B[i, j] = Interval(minYZ, maxYZ)
B[i, j] = interval(minYZ, maxYZ)
end
end

Expand Down Expand Up @@ -252,7 +252,7 @@ function _truncated_exponential_series(A::IntervalMatrix{T}, t, p::Integer;
n=checksquare(A)) where {T}
if p == 0
# index i = 0 (identity matrix)
return IntervalMatrix(Interval(one(T)) * I, n)
return IntervalMatrix(interval(one(T)) * I, n)
elseif p == 1
# index i = 1
S = A * t
Expand Down Expand Up @@ -346,7 +346,7 @@ function scale_and_square(A::IntervalMatrix{T}, l::Integer, t, p;
end
end

A_scaled = A / Interval(T(2))^l
A_scaled = A / interval(T(2))^l
E = exp_overapproximation(A_scaled, t, p)
for i in 1:l
E = square(E)
Expand Down Expand Up @@ -412,7 +412,7 @@ function horner(A::IntervalMatrix{T}, K::Integer;
end

n = checksquare(A)
Iₙ = IntervalMatrix(Interval(one(T)) * I, n)
Iₙ = IntervalMatrix(interval(one(T)) * I, n)
H = Iₙ + A / K
for i in (K - 1):-1:1
H = Iₙ + A / i * H
Expand Down
10 changes: 5 additions & 5 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ An interval matrix proportional to the identity matrix can be built using the
```jldoctest interval_uniform_scaling
julia> using LinearAlgebra
julia> IntervalMatrix(Interval(1)*I, 2)
julia> IntervalMatrix(interval(1)*I, 2)
2×2 IntervalMatrix{Float64, Interval{Float64}, Matrix{Interval{Float64}}}:
[1, 1] [0, 0]
[0, 0] [1, 1]
Expand All @@ -44,12 +44,12 @@ The number of columns can be specified as a third argument, creating a rectangul
``(1, 1), (2, 2), …, (k, k)`` are specified, where ``k = \\min(m, n)``:
```jldoctest interval_uniform_scaling
julia> IntervalMatrix(Interval(-1, 1)*I, 2, 3)
julia> IntervalMatrix(interval(-1, 1)*I, 2, 3)
2×3 IntervalMatrix{Float64, Interval{Float64}, Matrix{Interval{Float64}}}:
[-1, 1] [0, 0] [0, 0]
[0, 0] [-1, 1] [0, 0]
julia> IntervalMatrix(Interval(-1, 1)*I, 3, 2)
julia> IntervalMatrix(interval(-1, 1)*I, 3, 2)
3×2 IntervalMatrix{Float64, Interval{Float64}, Matrix{Interval{Float64}}}:
[-1, 1] [0, 0]
[0, 0] [-1, 1]
Expand Down Expand Up @@ -94,7 +94,7 @@ end

# undef initializer, eg. IntervalMatrix{Float64}(undef, 2, 2)
function IntervalMatrix{T}(u::UndefInitializer, m::Integer, n::Integer=m) where {T}
mat = Matrix{Interval{T}}(undef, m, n)
mat = Matrix{Interval{T}}(u, m, n)
return IntervalMatrix(mat)
end

Expand Down Expand Up @@ -144,7 +144,7 @@ function IntervalMatrix(A::MT, B::MT) where {T,MT<:AbstractMatrix{T}}
"matrices should match, but they are $(size(A)) " *
"and $(size(B)) respectively"))

return IntervalMatrix(map((x, y) -> Interval(x, y), A, B))
return IntervalMatrix(map((x, y) -> interval(x, y), A, B))
end

"""
Expand Down
8 changes: 4 additions & 4 deletions src/operations/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Base: +, -, *, /, \
+(x::Interval, M::IntervalMatrix) = IntervalMatrix(x .+ M.mat)
+(M::IntervalMatrix, x::Interval) = IntervalMatrix(x .+ M.mat)

+(x::Number, M::IntervalMatrix) = Interval(x) + M
+(M::IntervalMatrix, x::Number) = Interval(x) + M
+(x::Number, M::IntervalMatrix) = interval(x) + M
+(M::IntervalMatrix, x::Number) = interval(x) + M

+(M1::IntervalMatrix, M2::AbstractMatrix) = IntervalMatrix(M1.mat + M2)
+(M1::AbstractMatrix, M2::IntervalMatrix) = IntervalMatrix(M1 + M2.mat)
Expand All @@ -27,8 +27,8 @@ import Base: +, -, *, /, \
*(x::Interval, M::IntervalMatrix) = IntervalMatrix(x .* M.mat)
*(M::IntervalMatrix, x::Interval) = IntervalMatrix(x .* M.mat)

*(x::Number, M::IntervalMatrix) = Interval(x) * M
*(M::IntervalMatrix, x::Number) = Interval(x) * M
*(x::Number, M::IntervalMatrix) = interval(x) * M
*(M::IntervalMatrix, x::Number) = interval(x) * M

/(M::IntervalMatrix, x::Number) = IntervalMatrix(M ./ x)

Expand Down
8 changes: 4 additions & 4 deletions src/operations/mult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function *(::MultiplicationType{:fast},
return mA * mB - R
end

return IntervalMatrix(Interval.(Cinf, Csup))
return IntervalMatrix(interval.(Cinf, Csup))
end

function *(::MultiplicationType{:fast},
Expand All @@ -89,7 +89,7 @@ function *(::MultiplicationType{:fast},
return A * mB - R
end

return IntervalMatrix(Interval.(Cinf, Csup))
return IntervalMatrix(interval.(Cinf, Csup))
end

function *(::MultiplicationType{:fast},
Expand All @@ -113,7 +113,7 @@ function *(::MultiplicationType{:fast},
return mA * B - R
end

return IntervalMatrix((Interval.(Cinf, Csup)))
return IntervalMatrix((interval.(Cinf, Csup)))
end

# function *(::MultiplicationType{:rank1},
Expand Down Expand Up @@ -150,6 +150,6 @@ end
# return Csup
# end

# return Interval.(Cinf, Csup)
# return interval.(Cinf, Csup)

# end
2 changes: 1 addition & 1 deletion src/operations/random.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# create a random interval for the given numeric type and random-number generator
@inline function _rand_interval(; N=Float64, rng::AbstractRNG=GLOBAL_RNG)
x, y = randn(rng, N), randn(rng, N)
return x < y ? Interval(x, y) : Interval(y, x)
return x < y ? interval(x, y) : interval(y, x)
end

"""
Expand Down
4 changes: 2 additions & 2 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
m3 = similar(m1)
@test m3 isa IntervalMatrix{Float64} && size(m3) == size(m1)
m = [1.0 2; 3 4]
mint = IntervalMatrix([Interval(1) Interval(2); Interval(3) Interval(4)])
mint = IntervalMatrix([interval(1) interval(2); interval(3) interval(4)])
@test IntervalMatrix(m) == mint

A = [1 2; 3 4]
Expand Down Expand Up @@ -41,7 +41,7 @@ end
@test eltype(m2) == Complex{Interval{Float64}}
end

@testset "special matrices" begin
@testset "Special matrices" begin
A = rand(IntervalMatrix)
@test A isa IntervalMatrix

Expand Down
2 changes: 1 addition & 1 deletion test/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using IntervalMatrices: TaylorOverapproximation,
_exp_remainder_series

@testset "Interval matrix exponential" begin
@test quadratic_expansion(-3 .. 3, 1.0, 2.0) == Interval(-0.125, 21)
@test quadratic_expansion(-3 .. 3, 1.0, 2.0) == interval(-0.125, 21)

M = IntervalMatrix([-1.1..0.9 -4.1 .. -3.9; 3.9..4.1 -1.1..0.9])

Expand Down

0 comments on commit 69b072e

Please sign in to comment.