Skip to content

Commit e801976

Browse files
authored
mixed float interval matrix multiplication (#83)
1 parent df773b9 commit e801976

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

src/multiplication.jl

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ Sets the algorithm used to perform matrix multiplication with interval matrices.
2626
"""
2727
function set_multiplication_mode(multype)
2828
type = MultiplicationType{multype}()
29-
@eval *(A::AbstractMatrix{Interval{T}} where T, B::AbstractMatrix{Interval{T}} where T) =
29+
@eval *(A::AbstractMatrix{Interval{T}}, B::AbstractMatrix{Interval{T}}) where T =
3030
*($type, A, B)
3131

32+
@eval *(A::AbstractMatrix{T}, B::AbstractMatrix{Interval{T}}) where T = *($type, A, B)
33+
34+
@eval *(A::AbstractMatrix{Interval{T}}, B::AbstractMatrix{T}) where T = *($type, A, B)
35+
36+
@eval *(A::Diagonal, B::AbstractMatrix{Interval{T}}) where T = *($type, A, B)
37+
@eval *(A::AbstractMatrix{Interval{T}}, B::Diagonal) where T = *($type, A, B)
3238
config[:multiplication] = multype
3339
end
3440

@@ -66,6 +72,58 @@ function *(::MultiplicationType{:fast},
6672
return Interval.(Cinf, Csup)
6773
end
6874

75+
76+
function *(::MultiplicationType{:fast},
77+
A::AbstractMatrix{T},
78+
B::AbstractMatrix{Interval{T}}) where {T<:Real}
79+
80+
Binf = inf.(B)
81+
Bsup = sup.(B)
82+
83+
mB, R, Csup = setrounding(T, RoundUp) do
84+
mB = Binf + 0.5 * (Bsup - Binf)
85+
86+
rB = mB - Binf
87+
88+
R = abs.(A) * rB
89+
Csup = A * mB + R
90+
91+
return mB, R, Csup
92+
end
93+
94+
Cinf = setrounding(T, RoundDown) do
95+
A * mB - R
96+
end
97+
98+
return Interval.(Cinf, Csup)
99+
end
100+
101+
function *(::MultiplicationType{:fast},
102+
A::AbstractMatrix{Interval{T}},
103+
B::AbstractMatrix{T}) where {T<:Real}
104+
105+
Ainf = inf.(A)
106+
Asup = sup.(A)
107+
108+
mA, R, Csup = setrounding(T, RoundUp) do
109+
mA = Ainf + 0.5 * (Asup - Ainf)
110+
111+
rA = mA - Ainf
112+
113+
R = rA * abs.(B)
114+
Csup = mA * B + R
115+
116+
return mA, R, Csup
117+
end
118+
119+
Cinf = setrounding(T, RoundDown) do
120+
mA * B - R
121+
end
122+
123+
return Interval.(Cinf, Csup)
124+
end
125+
126+
69127
function *(::MultiplicationType{:rank1},
70128
A::AbstractMatrix{Interval{T}},
71129
B::AbstractMatrix{Interval{T}}) where {T<:Real}

test/test_multiplication.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
A = [2..4 -2..1; -1..2 2..4]
77
set_multiplication_mode(:slow)
8-
@test A*A == [0..18 -16..8; -8..16 0..18]
8+
@test A * A == [0..18 -16..8; -8..16 0..18]
99

1010
set_multiplication_mode(:rank1)
11-
@test A*A == [0..18 -16..8; -8..16 0..18]
11+
@test A * A == [0..18 -16..8; -8..16 0..18]
1212

1313
set_multiplication_mode(:fast)
14-
@test A*A == [-2..19.5 -16..10; -10..16 -2..19.5]
14+
@test A * A == [-2..19.5 -16..10; -10..16 -2..19.5]
15+
@test A * mid.(A) == [5..12.5 -8..2; -2..8 5..12.5]
16+
@test mid.(A) * A == [5..12.5 -8..2; -2..8 5..12.5]
1517
end

0 commit comments

Comments
 (0)