Skip to content

Commit 98f6502

Browse files
committed
Test unpackOldState, lower/lift Complex
1 parent 7ab4ea3 commit 98f6502

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

src/serialization/DFGStructStyles.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ function StructUtils.lift(
4343
end
4444
return AP(parts), nothing
4545
end
46+
47+
# Complex Serialization
48+
StructUtils.structlike(::DFGJSONStyle, ::Type{<:Complex}) = false
49+
StructUtils.lower(::DFGJSONStyle, x::Complex) = (real(x), imag(x))
50+
function StructUtils.lift(::DFGJSONStyle, ::Type{T}, x::JSON.LazyValue) where T <: Complex
51+
return T(x[1][], x[2][]), nothing
52+
end
53+
54+
# Above does not work for Arrya{ComplexF64, 0}
55+
StructUtils.lower(::DFGJSONStyle, x::AbstractArray{<:Complex, 0}) = (real(x), imag(x))
56+
function StructUtils.lift(::DFGJSONStyle, ::Type{A}, x::JSON.LazyValue) where A <: AbstractArray{T,0} where T <: Complex
57+
m = A(undef)
58+
m[] = (T(x[1][], x[2][]))
59+
return m, nothing
60+
end
61+
62+
# if serialized as an Struct
63+
# function StructUtils.lift(::DFGJSONStyle, ::Type{T}, x::JSON.LazyValue) where T <: Complex
64+
# return T(x.re[], x.im[]), nothing
65+
# end

src/serialization/StateSerialization.jl

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,9 @@ StructUtils.lower(T::AbstractStateType) = lowerStateKind(T)
4343
StructUtils.lift(::Type{AbstractStateType}, s) = liftStateKind(s)
4444

4545
##==============================================================================
46-
## OLD State Packing and unpacking
46+
## OLD State Packing and unpacking - Deprecated v0.29 - kept for migration
4747
##==============================================================================
4848

49-
# State Kind is handled seperately because it includes the N parameter.
50-
function stringStateKind(varT::AbstractStateType{N}) where {N}
51-
T = typeof(varT)
52-
if N == Any
53-
return string(parentmodule(T), ".", nameof(T))
54-
elseif N isa Integer
55-
return string(parentmodule(T), ".", nameof(T), "{", join(N, ","), "}")
56-
else
57-
throw(
58-
SerializationError(
59-
"Serializing Variable State type only supports an integer parameter, got '$(T)'.",
60-
),
61-
)
62-
end
63-
end
64-
6549
function parseStateKind(_typeString::AbstractString)
6650
m = match(r"{(\d+)}", _typeString)
6751
if !isnothing(m) #parameters in type
@@ -156,7 +140,7 @@ function unpackOldState(d)
156140
bandwidth = BW,
157141
)
158142
end
159-
return State{T, getPointType(T)}(;
143+
return State{typeof(T), getPointType(T)}(;
160144
label,
161145
belief,
162146
separator = Symbol.(d.separator),

test/testSerializingVariables.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,12 @@ end
102102
@test vsk.tags == v.tags
103103
end
104104
end
105+
106+
# TODO deprecated v0.29, remove this test and unpackOldState
107+
@testset "Serializing Old State" begin
108+
Pose2 = Pose{2}
109+
oldstates = JSON.parsefile(@__DIR__() * "/data/oldstate.json")
110+
states = DFG.unpackOldState.(oldstates)
111+
# just a spot check
112+
@test issetequal(getLabel.(states), [:default, :parametric, :graphinit])
113+
end

0 commit comments

Comments
 (0)