{"id":27996525,"url":"https://github.com/borglab/swiftfusion","last_synced_at":"2025-06-20T14:37:03.131Z","repository":{"id":45539044,"uuid":"220840496","full_name":"borglab/SwiftFusion","owner":"borglab","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-18T21:24:57.000Z","size":7986,"stargazers_count":118,"open_issues_count":43,"forks_count":13,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-08T21:45:58.056Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borglab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-10T19:36:21.000Z","updated_at":"2025-03-15T16:00:57.000Z","dependencies_parsed_at":"2023-01-29T20:01:30.701Z","dependency_job_id":null,"html_url":"https://github.com/borglab/SwiftFusion","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/borglab/SwiftFusion","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borglab%2FSwiftFusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borglab%2FSwiftFusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borglab%2FSwiftFusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borglab%2FSwiftFusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borglab","download_url":"https://codeload.github.com/borglab/SwiftFusion/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borglab%2FSwiftFusion/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260962995,"owners_count":23089526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T21:45:07.771Z","updated_at":"2025-06-20T14:36:58.115Z","avatar_url":"https://github.com/borglab.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftFusion\n\nA differentiable sensor fusion library written in Swift.\n\nThink factor graphs (à la [GTSAM](https://gtsam.org)) coupled with deep learning (via [Swift for TensorFlow](https://www.tensorflow.org/swift)).\n\nThis project is in an early phase, but feel free to explore! Subject to *massive* changes. :-)\n\n## Getting started\n\n### Installation\n\n#### macOS\n\nDownload a [Swift for TensorFlow macOS toolchain](https://github.com/tensorflow/swift/blob/main/Installation.md#development-snapshots) and follow the [macOS installation instructions](https://github.com/tensorflow/swift/blob/master/Installation.md#macos). Installing the latest development snapshot is recommended. [Check here](https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#installing-dependencies) for the \"required\" version of Xcode for using nightly toolchains. Sometimes toolchains may also work with older Xcode minor versions than the one listed.\n\nTo use Swift for TensorFlow, add the toolchain to `PATH`:\n\n```\nexport PATH=\"/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.12.xctoolchain/usr/bin/:$PATH\"\n```\n\n#### Linux\n\nDownload a [Swift for TensorFlow Linux toolchain](https://github.com/tensorflow/swift/blob/main/Installation.md#development-snapshots) and follow the [Linux installation instructions](https://github.com/tensorflow/swift/blob/master/Installation.md#linux). Installing the latest development snapshot is recommended.\n\n#### NVIDIA Jetson\n\nDownload the [Swift for TensorFlow NVIDIA Jetson toolchain](https://storage.googleapis.com/swift-tensorflow-artifacts/oneoff-builds/swift-tensorflow-RELEASE-0.11-Jetson4.4.tar.gz) and follow the [Linux installation instructions](https://github.com/tensorflow/swift/blob/master/Installation.md#linux).\n\n### Testing\n\n```\nswift test --enable-test-discovery\n```\n\n### Benchmarking\n\n```\nswift run -c release -Xswiftc -cross-module-optimization SwiftFusionBenchmarks\n```\n\n## Development\n\n### Xcode (macOS)\n\nXcode provides a great Swift development experience on macOS.\n\nTo open SwiftFusion in Xcode, run `open Package.swift`.\n\n### Visual Studio Code\n\nTo enable Swift autocomplete in Visual Studio Code, install the [Maintained Swift Development Environment plugin](https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swift-development-environment), and set the following plugin settings:\n\n```\n\"sde.languageServerMode\": \"sourcekit-lsp\",\n\"sourcekit-lsp.serverPath\": \"\u003cyour toolchain path\u003e/usr/bin/sourcekit-lsp\",\n\"sourcekit-lsp.toolchainPath\": \"\u003cyour toolchain path\u003e\",\n\"swift.path.swift_driver_bin\": \"\u003cyour toolchain path\u003e/usr/bin/swift\",\n```\n\nThe [CodeLLDB plugin](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) enables debugging within Visual Studio Code. You need to set the following setting:\n\n```\n\"lldb.library\": \"/swift-tensorflow-toolchain/usr/lib/liblldb.so\"\n```\n\nA sample `launch.json` file:\n\n```json\n{\n  \"version\": \"0.2.0\",\n  \"configurations\": [\n    {\n      \"type\": \"lldb\",\n      \"request\": \"launch\",\n      \"name\": \"Debug\",\n      \"program\": \"${workspaceFolder}/.build/x86_64-unknown-linux-gnu/debug/SwiftFusionPackageTests.xctest\",\n      \"args\": [\n        \"--enable-test-discovery\"\n      ],\n      \"cwd\": \"${workspaceFolder}\"\n    }\n  ]\n}\n```\n\n## Code overview\n\nThe main code is in `Sources/SwiftFusion`, organized under subdirectories.\n\n### Core\n\nThe core abstractions of SwiftFusion:\n\n- [`Vector.swift`](Sources/SwiftFusion/Core/Vector.swift): protocol that formalizes a Euclidean vector space with standard orthonormal basis, and defines a great number of default methods for it.  Also defines the `ScalarsInitializableVector` and `FixedSizeVector` protocols, and a collection `StandardBasis\u003cV: Vector\u003e` for the orthogonal bases.\n- [`Manifold.swift`](Sources/SwiftFusion/Core/Manifold.swift): protocol that inherits from `Differentiable` that adds `retract` and `localCoordinate`, which convert between a `Manifold` structure and its `LocalCoordinate`.\n- [`LieGroup.swift`](Sources/SwiftFusion/Core/LieGroup.swift): protocol that formalizes making a differentiable manifold into a Lie group with composition operator `*`. Also defines `LieGroupCoordinate` protocol.\n\nSpecific `Vector`-like data structures:\n\n- [`VectorN.swift`](Sources/SwiftFusion/Core/VectorN.swift): generated by `VectorN.swift.gyb`, implements small fixed-size vectors conforming to `AdditiveArithmetic`, `Vector`, and `FixedSizeVector`.\n- [`FixedSizeMatrix.swift`](Sources/SwiftFusion/Core/FixedSizeMatrix.swift): matrix whose dimensions are known at compile time. Conforms to `Equatable, KeyPathIterable, CustomStringConvertible, AdditiveArithmetic, Differentiable, FixedSizeVector`.\n\nAdditional utilities:\n\n- [`DataTypes.swift`](Sources/SwiftFusion/Core/DataTypes.swift): for now, just implements `LieGroup` protocol for `Vector5`\n- [`Dictionary+Differentiable.swift`](Sources/SwiftFusion/Core/Dictionary+Differentiable.swift): conform `Dictionary` to `Differentiable`.\n- [`MathUtil.swift`](Sources/SwiftFusion/Core/MathUtil.swift): for now just `pinv` (pseudo-inverse), using [`Tensor.svd`](https://www.tensorflow.org/swift/api_docs/Structs/Tensor#svdcomputeuv:fullmatrices:).\n- [`TensorVector.swift`](Sources/SwiftFusion/Core/TensorVector.swift): a view of a `Tensor` that conforms to the `Vector` protocol.\n- [`TrappingDouble.swift`](Sources/SwiftFusion/Core/TrappingDouble.swift): a wrapper for `Double` that traps instead of allowing `NaN`.\n- [`Tuple+Vector.swift`](Sources/SwiftFusion/Core/Tuple+Vector.swift): (undocumented)\n- [`TypeKeyedArrayBuffers.swift`](Sources/SwiftFusion/Core/TypeKeyedArrayBuffers.swift): related to storage of `Values` and `Factors`.\n\n### Inference\n\n- [`FactorGraph.swift`](Sources/SwiftFusion/Inference/FactorGraph.swift): the main factor graph structure storing factors.\n- [`Factor.swift`](Sources/SwiftFusion/Inference/Factor.swift): defines the core factor protocol hierarchy `Factor` → `VectorFactor` → `LinearizableFactor` → `GaussianFactor`, as well as the `VariableTuple` and `DifferentiableVariableTuple` protocols and `Tuple` conformances.\n- [`GaussianFactorGraph.swift`](Sources/SwiftFusion/Inference/GaussianFactorGraph.swift): A factor graph whose factors are all `GaussianFactor`s.\n\nA factor graph stores factors in a storage array of type `[ObjectIdentifier: AnyFactorArrayBuffer]`. [`ObjectIdentifier`](https://developer.apple.com/documentation/swift/objectidentifier) is a built-in Swift identifier type and `AnyFactorArrayBuffer` is defined in [FactorsStorage.swift](Sources/SwiftFusion/Inference/FactorsStorage.swift).\n\n### Optimizers\n\n- [`GradientDescent.swift`](Sources/SwiftFusion/Optimizers/GradientDescent.swift): a basic gradient descent optimizer.\n- [`CGLS.swift`](Sources/SwiftFusion/Optimizers/CGLS.swift): a conjugate gradient solver for least-squares problems.\n- [`LM.swift`](Sources/SwiftFusion/Optimizers/LM.swift): a Levenberg-Marquardt nonlinear optimizer.\n\n### MCMC\n\n- [`RandomWalkMetropolis.swift`](Sources/SwiftFusion/MCMC/RandomWalkMetropolis.swift): implements a Metropolis sampler modeled after [its equivalent](https://www.tensorflow.org/probability/api_docs/python/tfp/mcmc/RandomWalkMetropolis) in [TensorFlow Probability](https://www.tensorflow.org/probability).\n\n### Geometry\n\nThis directory defines rotation and pose types.\n\nWe use the GTSAM naming scheme: `Pose2`, `Rot2`, `Pose3`, and `Rot3`.\n\n- [`Pose2.swift`](Sources/SwiftFusion/Geometry/Pose2.swift): a 2D pose.\n- [`Rot2.swift`](Sources/SwiftFusion/Geometry/Rot2.swift): a 2D rotation.\n- [`Pose3.swift`](Sources/SwiftFusion/Geometry/Pose2.swift): a 3D pose.\n- [`Rot3.swift`](Sources/SwiftFusion/Geometry/Rot3.swift): a 3D rotation.\n\n2D and 3D points are simply represented as `Vector2` and `Vector3`.\n\n### Image\n\n- [`ArrayImage.swift`](Sources/SwiftFusion/Image/ArrayImage.swift): `Differentiable` multi-channel image stored as `[Double]`. Has a differentiable `tensor` method and `update` function.\n- [`OrientedBoundingBox.swift`](Sources/SwiftFusion/Image/OrientedBoundingBox.swift): a rectangular region of an image, not necessarily axis-aligned.\n- [`Patch.swift`](Sources/SwiftFusion/Image/Patch.swift): a differentiable `patch` method for `ArrayImage`, that returns a resampled image for the given `OrientedBoundingBox`.\n\n### Datasets\n\nThis directory primarily contains support for reading G2O files.\n\n# LICENSE\n\n```\nCopyright 2020 The SwiftFusion Team\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborglab%2Fswiftfusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborglab%2Fswiftfusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborglab%2Fswiftfusion/lists"}