|
40 | 40 |
|
41 | 41 | typeModuleName(varT::Type{<:InferenceVariable}) = typeModuleName(varT()) |
42 | 42 |
|
| 43 | +function parseVariableType(_typeString::AbstractString) |
| 44 | + m = match(r"{(\d+)}", _typeString) |
| 45 | + if !isnothing(m) #parameters in type |
| 46 | + param = parse(Int, m[1]) |
| 47 | + typeString = _typeString[1:(m.offset - 1)] |
| 48 | + else |
| 49 | + param = nothing |
| 50 | + typeString = _typeString |
| 51 | + end |
| 52 | + |
| 53 | + all_subtypes = Dict(map(s -> nameof(s) => s, subtypes(InferenceVariable))) |
| 54 | + |
| 55 | + subtype = get(all_subtypes, Symbol(split(typeString, ".")[end]), nothing) |
| 56 | + |
| 57 | + if isnothing(subtype) |
| 58 | + error("Unable to deserialize type $(_typeString), not found") |
| 59 | + return nothing |
| 60 | + end |
| 61 | + |
| 62 | + if isnothing(param) |
| 63 | + # no parameters, just return the type |
| 64 | + return subtype |
| 65 | + else |
| 66 | + # return the type with parameters |
| 67 | + return subtype{param} |
| 68 | + end |
| 69 | +end |
| 70 | + |
43 | 71 | """ |
44 | 72 | $(SIGNATURES) |
45 | 73 | Get a type from the serialization module. |
@@ -123,7 +151,7 @@ function unpackVariableState(d::PackedVariableState) |
123 | 151 | # Figuring out the variableType |
124 | 152 | # TODO deprecated remove in v0.11 - for backward compatibility for saved variableTypes. |
125 | 153 | ststring = string(split(d.variableType, "(")[1]) |
126 | | - T = getTypeFromSerializationModule(ststring) |
| 154 | + T = parseVariableType(ststring) |
127 | 155 | isnothing(T) && error( |
128 | 156 | "The variable doesn't seem to have a variableType. It needs to set up with an InferenceVariable from IIF. This will happen if you use DFG to add serialized variables directly and try use them. Please use IncrementalInference.addVariable().", |
129 | 157 | ) |
@@ -206,7 +234,7 @@ function unpackVariable(variable::VariableDFG; skipVersionCheck::Bool = false) |
206 | 234 | !skipVersionCheck && _versionCheck(variable) |
207 | 235 |
|
208 | 236 | # Variable and point type |
209 | | - variableType = DFG.getTypeFromSerializationModule(variable.variableType) |
| 237 | + variableType = parseVariableType(variable.variableType) |
210 | 238 | isnothing(variableType) && error( |
211 | 239 | "Cannot deserialize variableType '$(variable.variableType)' in variable '$(variable.label)'", |
212 | 240 | ) |
@@ -249,15 +277,19 @@ VariableDFG(v::VariableCompute) = packVariable(v) |
249 | 277 |
|
250 | 278 | # returns FactorDFG |
251 | 279 | function packFactor(f::FactorCompute) |
252 | | - fnctype = getObservation(f) |
| 280 | + obstype = typeof(getObservation(f)) |
| 281 | + fnctype = string(parentmodule(obstype), ".", nameof(obstype)) |
| 282 | + |
253 | 283 | return FactorDFG(; |
254 | 284 | id = f.id, |
255 | 285 | label = f.label, |
256 | 286 | tags = f.tags, |
257 | 287 | _variableOrderSymbols = f._variableOrderSymbols, |
258 | 288 | timestamp = f.timestamp, |
259 | 289 | nstime = string(f.nstime.value), |
260 | | - fnctype = String(_getname(fnctype)), |
| 290 | + #TODO fully test include module name in factor fnctype, see #1140 |
| 291 | + # fnctype = String(_getname(getObservation(f))), |
| 292 | + fnctype, |
261 | 293 | solvable = getSolvable(f), |
262 | 294 | metadata = base64encode(JSON3.write(f.smallData)), |
263 | 295 | # Pack the node data |
|
0 commit comments