Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Allowing storage of an value in VariableAssignments with specific Key #106

Open
ProfFan opened this issue Jun 26, 2020 · 4 comments
Open

Comments

@ProfFan
Copy link
Collaborator

ProfFan commented Jun 26, 2020

Historically in GTSAM (and in old SwFusion) we have a system where we use a single number to represent a variable. This has its disadvantages, but it makes association of data from different stages of optimization easy.

We should be able to do similar thing in the new implementation, or should we?

@marcrasi
Copy link
Collaborator

marcrasi commented Jun 26, 2020

Yes this sounds important and doable.

For performance, it is important to keep the consecutive TypedIDs under the hood but there can be a Dictionary somewhere that maps custom Keys to TypedIDs. The APIs could be arranged so that the TypedIDs are usually hidden and users only need to deal with them if they want fastest random access. Like:

var x = VariableAssignments<String>() // "String" is the key type

// under the hood, generates a TypedID<Int>(0) for `1` and also adds the mapping "a" -> TypedID<Int>(0) to the dict
x.store("a", 1)

x["a", type: Int.self]

// under the hood, generates a TypedID<Pose2>(0) for `Pose2(0, 0, 0)` and also adds the mapping "b" -> TypedID<Pose2>(0) to the dict
x.store("b", Pose2(0, 0, 0))

var graph = FactorGraph()

// under the hood, looks up that "b" means `TypedID<Pose2>(0)`, and stores the `TypedID` inside the `PriorFactor` instead of the string
graph.add(PriorFactor("b", Pose2(1, 0, 0))

There are a few ways this can be implemented. It could be built into VariableAssignments. It could be a wrapper type over VariableAssignments, so that methods that don't care about the custom keys can pass the VariableAssignments around without the dictionary overhead.

We could discuss this a bit during the meeting tomorrow. Dave may have useful opinions!

@dellaert
Copy link
Member

dellaert commented Jun 26, 2020 via email

@ProfFan
Copy link
Collaborator Author

ProfFan commented Jun 26, 2020

Fan, is it not easy to just create a local function x:Int-> TypedId<Pose,Int> to create pose keys, etc?

Yes, but then we will need to have boilerplate :)

@marcrasi
Copy link
Collaborator

Newbie question: If it’s important to keep consecutive, then why is Int part of the type?

No good reason. I want to remove it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants