Custom error to check stochastic matrix

Two points.

  1. This isn’t doing what you think it’s doing:
Julia> mat = [0.5, 0.5]
2-element Vector{Float64}:
0.5
0.5

julia> sum(mat, dims = 2)
2-element Vector{Float64}:
0.5
0.5

julia> mat = [0.5 0.5]
1×2 Matrix{Float64}:
 0.5  0.5

julia> sum(mat; dims = 2)
1×1 Matrix{Float64}:
 1.0

Note the different definition of mat.

  1. Never use exact comparisons.
julia> 3 * 0.1 == 0.3
false

Use isapprox(3 * 0.1, 0.3) instead: Getting started with Julia · JuMP