Skip to content

Commit 02a94c6

Browse files
authored
Add more functions for SDK and deprecate some smalldata functions (#1107)
* Add more functions for SDK and deprecate some smalldata functions * Update smalldata docs and tests --------- Co-authored-by: Johannes Terblanche <Affie@users.noreply.github.com>
1 parent a1d7339 commit 02a94c6

File tree

11 files changed

+184
-108
lines changed

11 files changed

+184
-108
lines changed

docs/src/GraphData.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ itself, large entries will slow the graph down, so if data should exceed a
156156
few bytes/kb, it should rather be saved in bigData.
157157

158158

159-
- [`getSmallData`](@ref)
160-
- [`setSmallData!`](@ref)
159+
- [`getMetadata`](@ref)
160+
- [`setMetadata!`](@ref)
161161

162162

163163
Example:
164164

165165
```julia
166-
setSmallData!(x0, Dict("entry"=>"entry value"))
167-
getSmallData(x0)
166+
setMetadata!(x0, Dict("entry"=>"entry value"))
167+
getMetadata(x0)
168168
```
169169

170170
#### Big Data

src/DataBlobs/services/BlobEntry.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ end
2828
# label
2929
# id
3030

31-
getLabel(entry::BlobEntry) = entry.label
32-
getId(entry::BlobEntry) = entry.id
3331
getHash(entry::BlobEntry) = hex2bytes(entry.hash)
3432
getTimestamp(entry::BlobEntry) = entry.timestamp
3533

@@ -173,6 +171,10 @@ function addBlobEntry!(dfg::AbstractDFG, vLbl::Symbol, entry::BlobEntry;)
173171
return addBlobEntry!(getVariable(dfg, vLbl), entry)
174172
end
175173

174+
function addBlobEntries!(dfg::AbstractDFG, vLbl::Symbol, entries::Vector{BlobEntry})
175+
return addBlobEntry!.(dfg, vLbl, entries)
176+
end
177+
176178
"""
177179
$(SIGNATURES)
178180
Update data entry

src/Deprecated.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ export DFGSummary
3939
DFGSummary(args) = error("DFGSummary is deprecated")
4040
@deprecate getSummary(dfg::AbstractDFG) getSummaryGraph(dfg)
4141

42+
##------------------------------------------------------------------------------
43+
## smallData
44+
##------------------------------------------------------------------------------
45+
@deprecate getSmallData(args...) getMetadata(args...)
46+
@deprecate setSmallData!(args...) setMetadata!(args...)
47+
@deprecate addSmallData!(args...) addMetadata!(args...)
48+
@deprecate updateSmallData!(args...) updateMetadata!(args...)
49+
@deprecate deleteSmallData!(args...) deleteMetadata!(args...)
50+
@deprecate listSmallData(args...) listMetadata(args...)
51+
@deprecate emptySmallData!(args...) emptyMetadata!(args...)
52+
4253
## ================================================================================
4354
## Deprecated in v0.24
4455
##=================================================================================

src/DistributedFactorGraphs.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ export getDimension, getManifold, getPointType
174174
export getPointIdentity, getPoint, getCoordinates
175175

176176
# Small Data CRUD
177-
export SmallDataTypes,
178-
getSmallData,
179-
addSmallData!,
180-
updateSmallData!,
181-
deleteSmallData!,
182-
listSmallData,
183-
emptySmallData!
184-
export getSmallData, setSmallData!
177+
export SmallDataTypes
178+
export getMetadata,
179+
setMetadata!,
180+
addMetadata!,
181+
updateMetadata!,
182+
deleteMetadata!,
183+
listMetadata,
184+
emptyMetadata!
185185

186186
# CRUD & SET
187187
export getVariableSolverData,
@@ -239,6 +239,7 @@ export getBlobEntriesVariables
239239
# aliases
240240
export addBlob!
241241
export packBlob, unpackBlob
242+
export @format_str
242243

243244
##------------------------------------------------------------------------------
244245
# Factors
@@ -326,6 +327,18 @@ export getData, addData!, updateData!, deleteData!
326327

327328
export plotDFG
328329

330+
## TODO maybe move to DFG
331+
# addAgent!
332+
# listAgents
333+
# addGraph!
334+
# deleteGraph!
335+
# listGraphs
336+
# getAgents
337+
# getModel
338+
# getModels
339+
# addModel!
340+
# getGraphs
341+
329342
##==============================================================================
330343
## Files Includes
331344
##==============================================================================

src/entities/Agent.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@
55
metadata::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
66
blobEntries::OrderedDict{Symbol, BlobEntry} = OrderedDict{Symbol, BlobEntry}()
77
end
8-
9-
getLabel(a::Agent) = a.label
10-
getMetadata(a::Agent) = a.metadata

src/entities/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Base.@kwdef struct DFGFactor{T, N} <: AbstractDFGFactor
207207
Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)"""
208208
solvable::Base.RefValue{Int}
209209
"""Dictionary of small data associated with this variable.
210-
Accessors: [`getSmallData`](@ref), [`setSmallData!`](@ref)"""
210+
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
211211
smallData::Dict{Symbol, SmallDataTypes}
212212
# Inner constructor
213213
function DFGFactor{T}(

src/entities/DFGVariable.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ StructTypes.StructType(::Type{Variable}) = StructTypes.UnorderedStruct()
263263
StructTypes.idproperty(::Type{Variable}) = :id
264264
StructTypes.omitempties(::Type{Variable}) = (:id,)
265265

266+
function getMetadata(v::Variable)
267+
return JSON3.read(base64decode(v.metadata), Dict{Symbol, SmallDataTypes})
268+
end
269+
270+
function setMetadata!(v::Variable, metadata::Dict{Symbol, SmallDataTypes})
271+
return error("FIXME: Metadata is not currently mutable in a Variable")
272+
# v.metadata = base64encode(JSON3.write(metadata))
273+
end
274+
266275
##------------------------------------------------------------------------------
267276
## DFGVariable lv2
268277
##------------------------------------------------------------------------------
@@ -297,7 +306,7 @@ Base.@kwdef struct DFGVariable{T <: InferenceVariable, P, N} <: AbstractDFGVaria
297306
solverDataDict::Dict{Symbol, VariableNodeData{T, P, N}} =
298307
Dict{Symbol, VariableNodeData{T, P, N}}()
299308
"""Dictionary of small data associated with this variable.
300-
Accessors: [`getSmallData`](@ref), [`setSmallData!`](@ref)"""
309+
Accessors: [`getMetadata`](@ref), [`setMetadata!`](@ref)"""
301310
smallData::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}()
302311
"""Dictionary of large data associated with this variable.
303312
Accessors: [`addBlobEntry!`](@ref), [`getBlobEntry`](@ref), [`updateBlobEntry!`](@ref), and [`deleteBlobEntry!`](@ref)"""
@@ -352,6 +361,13 @@ Base.setproperty!(x::DFGVariable, f::Symbol, val) = begin
352361
end
353362
end
354363

364+
getMetadata(v::DFGVariable) = v.smallData
365+
366+
function setMetadata!(v::DFGVariable, metadata::Dict{Symbol, SmallDataTypes})
367+
v.smallData !== metadata && empty!(v.smallData)
368+
return merge!(v.smallData, metadata)
369+
end
370+
355371
##------------------------------------------------------------------------------
356372
## DFGVariableSummary lv1
357373
##------------------------------------------------------------------------------

src/services/AbstractDFG.jl

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ Base.Broadcast.broadcastable(dfg::AbstractDFG) = Ref(dfg)
2828
##------------------------------------------------------------------------------
2929
## Getters
3030
##------------------------------------------------------------------------------
31+
"""
32+
$(SIGNATURES)
33+
Get the id of the node.
34+
"""
35+
getId(node) = node.id
36+
37+
"""
38+
$(SIGNATURES)
39+
Get the label of the node.
40+
"""
41+
getLabel(node) = node.label
42+
43+
"""
44+
$SIGNATURES
45+
46+
Get the metadata of the node.
47+
"""
48+
getMetadata(node) = node.metadata
49+
3150
"""
3251
$(SIGNATURES)
3352
Convenience function to get all the metadata of a DFG
@@ -120,6 +139,15 @@ function getTypeDFGFactors end
120139
##------------------------------------------------------------------------------
121140
## Setters
122141
##------------------------------------------------------------------------------
142+
"""
143+
$SIGNATURES
144+
Set the metadata of the node.
145+
"""
146+
function setMetadata!(node, metadata::Dict{Symbol, SmallDataTypes})
147+
# with set old data should be removed, but care is taken to make sure its not the same object
148+
node.metadata !== metadata && empty!(node.metadata)
149+
return merge!(node.metadata, metadata)
150+
end
123151

124152
"""
125153
$(SIGNATURES)
@@ -140,24 +168,6 @@ end
140168
"""
141169
$SIGNATURES
142170
143-
Get the metadata of the node.
144-
"""
145-
getMetadata(node) = node.metadata
146-
147-
"""
148-
$SIGNATURES
149-
150-
Set the metadata of the node.
151-
"""
152-
function setMetadata!(node, metadata::Dict{Symbol, SmallDataTypes})
153-
# with set old data should be removed, but care is taken to make sure its not the same object
154-
node.metadata !== metadata && empty!(node.metadata)
155-
return merge!(node.metadata, metadata)
156-
end
157-
158-
"""
159-
$SIGNATURES
160-
161171
Get the metadata from the agent in the AbstractDFG.
162172
"""
163173
getAgentMetadata(dfg::AbstractDFG) = getMetadata(getAgent(dfg))
@@ -212,7 +222,7 @@ emptyGraphMetadata!(dfg::AbstractDFG) = empty!(dfg.graphMetadata)
212222
#TODO add__Data!?
213223

214224
##==============================================================================
215-
## Agent/Graph Blob Entries CRUD
225+
## Agent/Graph/Model Blob Entries CRUD
216226
##==============================================================================
217227

218228
function getGraphBlobEntry end
@@ -229,8 +239,16 @@ function addAgentBlobEntries! end
229239
function updateAgentBlobEntry! end
230240
function deleteAgentBlobEntry! end
231241

242+
function getModelBlobEntry end
243+
function getModelBlobEntries end
244+
function addModelBlobEntry! end
245+
function addModelBlobEntries! end
246+
function updateModelBlobEntry! end
247+
function deleteModelBlobEntry! end
248+
232249
function listGraphBlobEntries end
233250
function listAgentBlobEntries end
251+
function listModelBlobEntries end
234252

235253
##==============================================================================
236254
## AbstractBlobStore CRUD
@@ -315,6 +333,30 @@ function getVariable(dfg::G, label::Union{Symbol, String}) where {G <: AbstractD
315333
return error("getVariable not implemented for $(typeof(dfg))")
316334
end
317335

336+
"""
337+
$(SIGNATURES)
338+
Get a VariableSummary from a DFG.
339+
"""
340+
function getVariableSummary end
341+
342+
"""
343+
$(SIGNATURES)
344+
Get the variables from a DFG as a Vector{VariableSummary}.
345+
"""
346+
function getVariablesSummary end
347+
348+
"""
349+
$(SIGNATURES)
350+
Get a VariableSkeleton from a DFG.
351+
"""
352+
function getVariableSkeleton end
353+
354+
"""
355+
$(SIGNATURES)
356+
Get the variables from a DFG as a Vector{VariableSkeleton}.
357+
"""
358+
function getVariablesSkeleton end
359+
318360
"""
319361
$(SIGNATURES)
320362
Get a DFGFactor from a DFG using its label.
@@ -323,6 +365,12 @@ function getFactor(dfg::G, label::Union{Symbol, String}) where {G <: AbstractDFG
323365
return error("getFactor not implemented for $(typeof(dfg))")
324366
end
325367

368+
"""
369+
$(SIGNATURES)
370+
Get the skeleton factors from a DFG as a Vector{FactorSkeleton}.
371+
"""
372+
function getFactorsSkeleton end
373+
326374
function Base.getindex(dfg::AbstractDFG, lbl::Union{Symbol, String})
327375
if isVariable(dfg, lbl)
328376
getVariable(dfg, lbl)

0 commit comments

Comments
 (0)