Skip to content

Commit

Permalink
Add constructor of matrix power given a target index (#132)
Browse files Browse the repository at this point in the history
* add constructor of matrix power given a target index

* pull out constructors
  • Loading branch information
schillic authored Feb 11, 2020
1 parent b614457 commit b122bc3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,26 @@ mutable struct IntervalMatrixPower{T}
Mᵏ::IntervalMatrix{T}
k::Int

function IntervalMatrixPower(M::IntervalMatrix{T}) where {T}
return new{T}(M, M, 1)
end

function IntervalMatrixPower(M::IntervalMatrix{T}, Mᵏ::IntervalMatrix{T},
k::Int) where {T}
@assert k >= 1 "matrix powers must be positive"
return new{T}(M, Mᵏ, k)
end
end

function IntervalMatrixPower(M::IntervalMatrix{T}) where {T}
return IntervalMatrixPower(M, M, 1)
end

function IntervalMatrixPower(M::IntervalMatrix{T}, k::Int) where {T}
@assert k >= 1 "matrix powers must be positive"
pow = IntervalMatrixPower(M, M, 1)
@inbounds for i in 1:(k-1)
increment!(pow)
end
return pow
end

function copy(pow::IntervalMatrixPower)
return IntervalMatrixPower(pow.M, pow.Mᵏ, pow.k)
end
Expand Down

0 comments on commit b122bc3

Please sign in to comment.