Skip to content

Commit

Permalink
Enforce rate units in MatrixExponentialTransiogram
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 29, 2024
1 parent 0203c72 commit a56628a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/theoretical/transiogram/matrixexponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct MatrixExponentialTransiogram{R<:StaticMatrix,B<:MetricBall} <: Transiogra
end

function MatrixExponentialTransiogram(ball::MetricBall, rate::AbstractMatrix)
srate = SMatrix{size(rate)...}(rate)
srate = SMatrix{size(rate)...}(float(asinvlen.(rate)))
MatrixExponentialTransiogram{typeof(srate),typeof(ball)}(srate, ball)
end

Expand Down
5 changes: 5 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# ------------------------------------------------------------------

const Len{T} = Quantity{T,u"𝐋"}
const InvLen{T} = Quantity{T,u"𝐋^-1"}

asinvlen(x::Number) = x * u"m^-1"
asinvlen(x::InvLen) = x
asinvlen(::Quantity) = throw(ArgumentError("invalid units, please check the documentation"))

addunit(x::Number, u) = x * u
addunit(::Quantity, _) = throw(ArgumentError("invalid units, please check the documentation"))
Expand Down
2 changes: 1 addition & 1 deletion test/theoretical/transiogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
R = A ./ sum(A, dims=2)
t = MatrixExponentialTransiogram(R)
@test t isa MatrixExponentialTransiogram
@test range(t) == maximum(1 ./ -diag(R))
@test range(t) == maximum(1 ./ -diag(R)) * u"m"

# invalid transition rate matrix
A = rand(3, 2)
Expand Down

0 comments on commit a56628a

Please sign in to comment.