Skip to content

Commit 0376f11

Browse files
committed
standard getfirstBlobentry
1 parent 8b957d0 commit 0376f11

File tree

8 files changed

+93
-68
lines changed

8 files changed

+93
-68
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,18 @@ Test = "1.10"
7575
TimeZones = "1.3.1"
7676
UUIDs = "1.10"
7777
julia = "1.10"
78+
LieGroups = "0.1"
7879

7980
[extras]
8081
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
8182
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
8283
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
84+
LieGroups = "6774de46-80ba-43f8-ba42-e41071ccfc5f"
8385
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
8486
Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
8587
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
8688
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
8789
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8890

8991
[targets]
90-
test = ["Aqua", "Test", "DataStructures", "GraphMakie", "LinearAlgebra", "Manifolds", "Pkg", "Statistics"]
92+
test = ["Aqua", "Test", "DataStructures", "GraphMakie", "LinearAlgebra", "Manifolds", "Pkg", "Statistics", "LieGroups"]

src/DataBlobs/entities/BlobStores.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ Design goal: all `Blobstore`s with the same `label` can contain the same `blobId
2929
3030
"""
3131
abstract type AbstractBlobstore{T} end
32+
const Blobstore = AbstractBlobstore

src/DataBlobs/services/BlobEntry.jl

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
2-
##==============================================================================
3-
## Blobentry - compare
4-
##==============================================================================
5-
6-
import Base: ==
7-
8-
@generated function ==(x::T, y::T) where {T <: Blobentry}
9-
return mapreduce(n -> :(x.$n == y.$n), (a, b) -> :($a && $b), fieldnames(x))
10-
end
11-
121
##==============================================================================
132
## Blobentry - common
143
##==============================================================================
@@ -85,49 +74,26 @@ Finds and returns the first blob entry that matches the filter.
8574
8675
Also see: [`getBlobentry`](@ref)
8776
"""
88-
function getfirstBlobentry(var::AbstractGraphVariable, blobId::UUID)
89-
for (k, v) in var.dataDict
90-
if blobId == v.blobId
91-
return v
92-
end
93-
end
94-
throw(KeyError("No blobEntry with blobId $(blobId) found in variable $(getLabel(var))"))
95-
end
96-
97-
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, blobId::UUID)
98-
return getfirstBlobentry(getVariable(dfg, label), blobId)
99-
end
100-
101-
function getfirstBlobentry(var::AbstractGraphVariable, key::Regex)
102-
for (k, v) in var.dataDict
103-
if occursin(key, string(v.label))
104-
return v
105-
end
106-
end
107-
throw(
108-
KeyError(
109-
"No blobEntry with label matching regex $(key) found in variable $(getLabel(var))",
110-
),
111-
)
112-
end
113-
114-
function getfirstBlobentry(var::VariableDFG, key::Regex)
115-
firstIdx = findfirst(x -> contains(string(x.label), key), var.blobEntries)
116-
if isnothing(firstIdx)
117-
throw(KeyError("$key"))
77+
function getfirstBlobentry(
78+
v::AbstractGraphVariable;
79+
labelFilter::Union{Nothing, Function} = nothing,
80+
blobIdFilter::Union{Nothing, Function} = nothing,
81+
)
82+
entries = getBlobentries(v; labelFilter, blobIdFilter)
83+
if isempty(entries)
84+
return nothing
85+
else
86+
return entries[1]
11887
end
119-
return var.blobEntries[firstIdx]
12088
end
12189

122-
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, key::Regex)
123-
els = listBlobentries(dfg, label)
124-
firstIdx = findfirst(contains(key), string.(els))
125-
isnothing(firstIdx) && throw(
126-
KeyError(
127-
"No blobEntry with label matching regex $(key) found in variable $(label)",
128-
),
129-
)
130-
return getBlobentry(dfg, label, els[firstIdx])
90+
function getfirstBlobentry(
91+
dfg::AbstractDFG,
92+
label::Symbol;
93+
labelFilter::Union{Nothing, Function} = nothing,
94+
blobIdFilter::Union{Nothing, Function} = nothing,
95+
)
96+
return getfirstBlobentry(getVariable(dfg, label); labelFilter, blobIdFilter)
13197
end
13298

13399
# TODO Consider autogenerating all methods of the form:
@@ -227,38 +193,49 @@ end
227193
228194
Does a blob entry exist with `blobLabel`.
229195
"""
230-
hasBlobentry(var::VariableCompute, blobLabel::Symbol) = haskey(var.dataDict, blobLabel)
196+
hasBlobentry(v::VariableCompute, blobLabel::Symbol) = haskey(v.dataDict, blobLabel)
231197

232-
function hasBlobentry(var::VariableDFG, label::Symbol)
233-
return label in getproperty.(var.blobEntries, :label)
198+
function hasBlobentry(v::VariableDFG, label::Symbol)
199+
return label in getproperty.(v.blobEntries, :label)
234200
end
235201

236202
"""
237203
$(SIGNATURES)
238204
239205
Get blob entries, returns a `Vector{Blobentry}`.
240206
"""
241-
function getBlobentries(var::VariableCompute)
242-
return collect(values(var.dataDict))
207+
function getBlobentries(v::VariableCompute)
208+
return collect(values(v.dataDict))
209+
end
210+
211+
function getBlobentries(v::VariableDFG)
212+
return copy(v.blobEntries)
243213
end
244214

245-
function getBlobentries(var::VariableDFG)
246-
return var.blobEntries
215+
function getBlobentries(
216+
v::AbstractGraphVariable;
217+
labelFilter::Union{Nothing, Function} = nothing,
218+
blobIdFilter::Union{Nothing, Function} = nothing,
219+
)
220+
entries = getBlobentries(v)
221+
filterDFG!(entries, labelFilter, x -> string(x.label))
222+
filterDFG!(entries, blobIdFilter, x -> string(x.blobId))
223+
return entries
247224
end
248225

249226
function getBlobentries(
250227
dfg::AbstractDFG,
251228
variableLabel::Symbol;
252229
labelFilter::Union{Nothing, Function} = nothing,
230+
blobIdFilter::Union{Nothing, Function} = nothing,
253231
)
254-
entries = getBlobentries(getVariable(dfg, variableLabel))
255-
filterDFG!(entries, labelFilter)
256-
return entries
232+
return getBlobentries(getVariable(dfg, variableLabel); labelFilter, blobIdFilter)
257233
end
258234

259235
function gatherBlobentries(
260236
dfg::AbstractDFG;
261237
labelFilter::Union{Nothing, Function} = nothing,
238+
blobIdFilter::Union{Nothing, Function} = nothing,
262239
solvableFilter::Union{Nothing, Function} = nothing,
263240
tagsFilter::Union{Nothing, Function} = nothing,
264241
typeFilter::Union{Nothing, Function} = nothing,
@@ -272,7 +249,7 @@ function gatherBlobentries(
272249
labelFilter = variableLabelFilter,
273250
)
274251
return map(vls) do vl
275-
return getBlobentries(dfg, vl; labelFilter)
252+
return vl => getBlobentries(dfg, vl; labelFilter, blobIdFilter)
276253
end
277254
end
278255

src/Deprecated.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,39 @@ function getBlobentries(
321321
)
322322
return getBlobentries(dfg, label, Regex(string(skey)))
323323
end
324+
325+
function getfirstBlobentry(var::AbstractGraphVariable, blobId::UUID)
326+
Base.depwarn(
327+
"getfirstBlobentry(var, blobId) is deprecated, use getfirstBlobentry(var; blobIdFilter = ==(string(blobId))) instead.",
328+
:getfirstBlobentry,
329+
)
330+
return getfirstBlobentry(var; blobIdFilter = ==(string(blobId)))
331+
end
332+
333+
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, blobId::UUID)
334+
Base.depwarn(
335+
"getfirstBlobentry(dfg, label, blobId) is deprecated, use getfirstBlobentry(dfg, label; blobIdFilter = ==(string(blobId))) instead.",
336+
:getfirstBlobentry,
337+
)
338+
return getfirstBlobentry(dfg, label; blobIdFilter = ==(string(blobId)))
339+
end
340+
341+
function getfirstBlobentry(var::AbstractGraphVariable, key::Regex)
342+
Base.depwarn(
343+
"getfirstBlobentry(var, key::Regex) is deprecated, use getfirstBlobentry(var; labelFilter=contains(key)) instead.",
344+
:getfirstBlobentry,
345+
)
346+
return getfirstBlobentry(var; labelFilter = contains(key))
347+
end
348+
349+
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, key::Regex)
350+
Base.depwarn(
351+
"getfirstBlobentry(dfg, label, key::Regex) is deprecated, use getfirstBlobentry(dfg, label; labelFilter=contains(key)) instead.",
352+
:getfirstBlobentry,
353+
)
354+
return getfirstBlobentry(dfg, label; labelFilter = contains(key))
355+
end
356+
324357
## ================================================================================
325358
## Deprecated in v0.27
326359
##=================================================================================

src/services/CompareUtils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const GeneratedCompareUnion = Union{
2121
MeanMaxPPE,
2222
State,
2323
PackedState,
24+
Blobentry,
2425
VariableCompute,
2526
VariableDFG,
2627
VariableSummary,

src/services/DFGVariable.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ end
777777

778778
function deleteState!(v::VariableCompute, label::Symbol)
779779
if !haskey(v.solverDataDict, label)
780-
throw(KeyError("State '$(label)' does not exist"))
780+
throw(LabelNotFoundError("State", label))
781781
end
782782
delete!(v.solverDataDict, label)
783783
return 1
@@ -851,6 +851,7 @@ function listStates(
851851
return labels
852852
end
853853

854+
#TODO deprecate PPEs
854855
##==============================================================================
855856
## Point Parametric Estimates
856857
##==============================================================================

test/testBlocks.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,15 @@ function blobsStoresTestBlock!(fg)
10471047
@test issetequal(listBlobentries(fg, :a), [:label1, :label2])
10481048
@test listBlobentries(fg, :b) == Symbol[:label2]
10491049

1050+
# test collecting blobentries with filters
1051+
gathered = DFG.gatherBlobentries(
1052+
fg;
1053+
variableLabelFilter = contains("a"),
1054+
labelFilter = contains("1"),
1055+
)
1056+
@test first(gathered[1]) == :a
1057+
@test last(gathered[1])[1] == getBlobentry(fg, :a, :label1)
1058+
10501059
#delete
10511060
@test deleteBlobentry!(fg, var1.label, de1.label) == 1
10521061
@test listBlobentries(fg, var1.label) == Symbol[:label2]
@@ -1102,7 +1111,7 @@ function blobsStoresTestBlock!(fg)
11021111
@test data[1].hash == newData.hash #[1]
11031112
data = getData(fg, :a, r"testing") # convenience wrapper over getBlob
11041113
@test data[1].hash == newData.hash #[1]
1105-
be = getfirstBlobentry(fg, :a, r"testing")
1114+
be = getfirstBlobentry(fg, :a; labelFilter = contains(r"testing"))
11061115
data = getData(fg, :a, be.blobId) # convenience wrapper over getBlob
11071116
@test data[1].hash == newData.hash #[1]
11081117
# @test data[2] == newData[2]

test/test_defVariable.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using LieGroups
12
using Manifolds
23
using Test
34
using LinearAlgebra
@@ -14,14 +15,14 @@ using LinearAlgebra
1415
@defVariable(TestVarType1, Euclidean(3), zeros(3))
1516
@defVariable(
1617
TestVarType2,
17-
SpecialEuclidean(3),
18+
SpecialEuclideanGroup(3),
1819
ArrayPartition(zeros(3), diagm(ones(3)))
1920
)
2021

2122
##
2223

2324
@test getManifold(TestVarType1) == Euclidean(3)
24-
@test getManifold(TestVarType2) == SpecialEuclidean(3)
25+
@test getManifold(TestVarType2) == SpecialEuclideanGroup(3)
2526

2627
@test getDimension(TestVarType1) === 3
2728
@test getDimension(TestVarType2) === 6
@@ -39,7 +40,7 @@ using LinearAlgebra
3940
##
4041

4142
@test getManifold(TestVarType1()) == Euclidean(3)
42-
@test getManifold(TestVarType2()) == SpecialEuclidean(3)
43+
@test getManifold(TestVarType2()) == SpecialEuclideanGroup(3)
4344

4445
@test getDimension(TestVarType1()) === 3
4546
@test getDimension(TestVarType2()) === 6

0 commit comments

Comments
 (0)