-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from contagon/serde
Serde Support
- Loading branch information
Showing
34 changed files
with
997 additions
and
3,888 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,78 @@ | ||
[package] | ||
name = "samrs" | ||
name = "factrs" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# base | ||
ahash = "0.8.11" | ||
derive_more = "0.99.17" | ||
paste = "1.0.15" | ||
downcast-rs = "1.2.1" | ||
log = "0.4.21" | ||
|
||
faer = { version = "0.19.0", default-features = false, features = ["perf-warn", "std"] } | ||
# numerical | ||
faer = { version = "0.19.0", default-features = false, features = [ | ||
"perf-warn", | ||
"std", | ||
] } | ||
faer-ext = { version = "0.2.0", features = ["nalgebra"] } | ||
nalgebra = { version = "0.32.5" } | ||
num-dual = "0.9.1" | ||
matrixcompare-core = { version = "0.1", optional = true } | ||
serde = {version = "1.0.203", optional = true } | ||
log = "0.4.21" | ||
rerun = { version = "0.16.1", optional = true} | ||
|
||
[[example]] | ||
name = "g2o-rerun" | ||
required-features = ["rerun"] | ||
# serialization | ||
serde = { version = "1.0.203", optional = true } | ||
typetag = { version = "0.2.16", optional = true } | ||
serde_json = { version = "1.0.120", optional = true } | ||
|
||
# rerun support | ||
rerun = { version = "0.16.1", optional = true, default-features = false, features = [ | ||
"sdk", | ||
] } | ||
|
||
[features] | ||
# Run everything with f32 instead of the defaul f64 | ||
f32 = [] | ||
|
||
# Use left instead of right for lie group updates | ||
left = [] | ||
|
||
# use SO(n) x R instead of SE(n) for exponential map | ||
fake_exp = [] | ||
|
||
# Necessary dependencies for matrix comparing | ||
compare = ["dep:matrixcompare-core", "nalgebra/compare", "faer/matrixcompare"] | ||
serde = ["dep:serde", "nalgebra/serde", "faer/serde", "ahash/serde"] | ||
multithread = ["faer/rayon"] | ||
|
||
# Add multithreaded support (may run slower on smaller problems) | ||
rayon = ["faer/rayon"] | ||
|
||
# Add support for serialization | ||
serde = [ | ||
"dep:serde", | ||
"dep:typetag", | ||
"nalgebra/serde-serialize", | ||
"faer/serde", | ||
"ahash/serde", | ||
] | ||
# just used for examples | ||
serde_json = ["dep:serde_json"] | ||
|
||
# Support for conversion to rerun variable types | ||
rerun = ["dep:rerun"] | ||
|
||
[dev-dependencies] | ||
matrixcompare = "0.3.0" | ||
plotters = "0.3.6" | ||
pretty_env_logger = "0.4" | ||
nalgebra = { version = "0.32.5", features = ["compare"] } | ||
|
||
[[example]] | ||
name = "g2o" | ||
|
||
[[example]] | ||
name = "g2o-rerun" | ||
required-features = ["rerun"] | ||
|
||
[[example]] | ||
name = "serde" | ||
required-features = ["serde", "serde_json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use factrs::{ | ||
containers::{Graph, Values, X}, | ||
factors::Factor, | ||
noise::GaussianNoise, | ||
residuals::{BetweenResidual, PriorResidual}, | ||
robust::{GemanMcClure, L2}, | ||
variables::{SE2, SO2}, | ||
}; | ||
|
||
fn main() { | ||
// ------------------------- Try with values ------------------------- // | ||
let x = SO2::from_theta(0.6); | ||
let y = SE2::new(1.0, 2.0, 0.3); | ||
let mut values = Values::new(); | ||
values.insert(X(0), x.clone()); | ||
values.insert(X(1), y.clone()); | ||
|
||
let serialized = serde_json::to_string_pretty(&values).unwrap(); | ||
println!("serialized = {}", serialized); | ||
|
||
// Convert the JSON string back to a Point. | ||
let deserialized: Values = serde_json::from_str(&serialized).unwrap(); | ||
println!("deserialized = {}", deserialized); | ||
|
||
// ------------------------- Try with graph ------------------------- // | ||
let prior = PriorResidual::new(x); | ||
let bet = BetweenResidual::new(y); | ||
|
||
let prior = Factor::new_full( | ||
&[X(0)], | ||
prior, | ||
GaussianNoise::from_scalar_cov(0.1), | ||
GemanMcClure::default(), | ||
); | ||
let bet = Factor::new_full(&[X(0), X(1)], bet, GaussianNoise::from_scalar_cov(10.0), L2); | ||
let mut graph = Graph::new(); | ||
graph.add_factor(prior); | ||
graph.add_factor(bet); | ||
|
||
let serialized = serde_json::to_string_pretty(&graph).unwrap(); | ||
println!("serialized = {}", serialized); | ||
|
||
let deserialized: Graph = serde_json::from_str(&serialized).unwrap(); | ||
println!("deserialized = {:?}", deserialized); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.