Skip to content
Snippets Groups Projects
Unverified Commit 55bb9b35 authored by Lucas Ondel Yang's avatar Lucas Ondel Yang
Browse files

change cumsum -> sum

parent 975fbbf5
No related branches found
No related tags found
No related merge requests found
# SPDX-License-Identifier: CECILL-2.1 # SPDX-License-Identifier: CECILL-2.1
""" """
Base.cumsum(A[; n = nstates(A)]) Base.cumsum(A[; init = initstates(A), n = nstates(A)])
Accumulate the weight of all the paths of length less or equal to Accumulate the weight of all the paths of length less or equal to
`n`. `n`.
""" """
function Base.cumsum(A::AbstractFSA; v₀ = α(A), n = nstates(A)) function Base.sum(A::AbstractFSA; init = α(A), n = nstates(A))
v = v₀ v = init
σ = dot(v, ω(A)) + ρ(A) σ = dot(v, ω(A)) + ρ(A)
for i in 1:n for i in 1:n
v = T(A)' * v v = T(A)' * v
......
...@@ -60,15 +60,15 @@ end ...@@ -60,15 +60,15 @@ end
# union # union
B12 = convert((w, l) -> f(L, w, l), union(A1, A2)) B12 = convert((w, l) -> f(L, w, l), union(A1, A2))
cs_B12 = cumsum(B12) cs_B12 = sum(B12)
cs_B1_B2 = cumsum(B1) + cumsum(B2) cs_B1_B2 = sum(B1) + sum(B2)
@test cs_B12.tval[1] cs_B1_B2.tval[1] @test cs_B12.tval[1] cs_B1_B2.tval[1]
@test cs_B12.tval[2] == cs_B1_B2.tval[2] @test cs_B12.tval[2] == cs_B1_B2.tval[2]
# concatenation # concatenation
B12 = convert((w, l) -> f(L, w, l), cat(A1, A2)) B12 = convert((w, l) -> f(L, w, l), cat(A1, A2))
cs_B12 = cumsum(B12) cs_B12 = sum(B12)
cs_B1_B2 = cumsum(B2) * cumsum(B1) cs_B1_B2 = sum(B2) * sum(B1)
@test cs_B12.tval[1] cs_B1_B2.tval[1] @test cs_B12.tval[1] cs_B1_B2.tval[1]
@test cs_B12.tval[2] == cs_B1_B2.tval[2] @test cs_B12.tval[2] == cs_B1_B2.tval[2]
...@@ -82,10 +82,10 @@ end ...@@ -82,10 +82,10 @@ end
B2_n3 = B2 cat(B2, B2) cat(B2, B2, B2) B2_n3 = B2 cat(B2, B2) cat(B2, B2, B2)
cB2p = closure(B2; plus = true) cB2p = closure(B2; plus = true)
cB2 = closure(B2; plus = false) cB2 = closure(B2; plus = false)
cs_B2p_n3 = cumsum(B2p_n3; n = n) cs_B2p_n3 = sum(B2p_n3; n = n)
cs_B2_n3 = cumsum(B2_n3; n = n) cs_B2_n3 = sum(B2_n3; n = n)
cs_cB2p = cumsum(cB2p; n = n) cs_cB2p = sum(cB2p; n = n)
cs_cB2 = cumsum(cB2; n = n) cs_cB2 = sum(cB2; n = n)
@test cs_cB2p.tval[1] cs_B2p_n3.tval[1] @test cs_cB2p.tval[1] cs_B2p_n3.tval[1]
@test cs_cB2p.tval[2] == cs_B2p_n3.tval[2] @test cs_cB2p.tval[2] == cs_B2p_n3.tval[2]
@test cs_cB2.tval[1] cs_B2_n3.tval[1] @test cs_cB2.tval[1] cs_B2_n3.tval[1]
...@@ -93,13 +93,13 @@ end ...@@ -93,13 +93,13 @@ end
# reverse # reverse
rB2 = convert((w, l) -> f(L, w, l), A2 |> reverse) rB2 = convert((w, l) -> f(L, w, l), A2 |> reverse)
s1 = val(cumsum(B2).tval[2]) s1 = val(sum(B2).tval[2])
s2 = Set((StringMonoid reverse val).((val cumsum)(rB2)[2])) s2 = Set((StringMonoid reverse val).((val sum)(rB2)[2]))
@test s1 == s2 @test s1 == s2
# renorm # renorm
@test Base.isapprox(val(cumsum(A1 |> renorm; n = 100)), val(one(K)), atol=1e-6) @test Base.isapprox(val(sum(A1 |> renorm; n = 100)), val(one(K)), atol=1e-6)
@test Base.isapprox(val(cumsum(A2 |> renorm; n = 100)), val(one(K)), atol=1e-6) @test Base.isapprox(val(sum(A2 |> renorm; n = 100)), val(one(K)), atol=1e-6)
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment