# GTSAM

## Introduction

* Official tutorials: <https://gtsam.org/tutorials/intro.html>
* Example project that uses GTSAM: <https://github.com/hanzheteng/LeGO-LOAM>

## Examples

### Speed up Key operations by [TBB](https://en.wikipedia.org/wiki/Threading_Building_Blocks) library

```cpp
// inference/Factor.h 
class Factor{
  protected:
    /// The keys involved in this factor
    KeyVector keys_;
}

// inference/Key.h
typedef FastVector<Key> KeyVector;

// base/types.h
typedef std::uint64_t Key;         /// Integer nonlinear key type
typedef std::uint64_t FactorIndex; /// Integer nonlinear factor index type
typedef ptrdiff_t DenseIndex;      /// The index type for Eigen objects

// base/FastVector.h
// FastVector is a type alias to a std::vector with a custom memory allocator.
// The particular allocator depends on GTSAM's cmake configuration.
template <typename T>
using FastVector =
    std::vector<T, typename internal::FastDefaultVectorAllocator<T>::type>;

// base/FastDefaultAllocator.h
/// Default allocator for vector types (we never use boost pool for vectors)
    template<typename T>
    struct FastDefaultVectorAllocator
    {
#if defined GTSAM_ALLOCATOR_TBB
      typedef tbb::tbb_allocator<T> type;
      static const bool isBoost = false;
      static const bool isTBB = true;
      static const bool isSTL = false;
#else
      typedef std::allocator<T> type;
      static const bool isBoost = false;
      static const bool isTBB = false;
      static const bool isSTL = true;
#endif
    };
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.hanzheteng.com/development/libraries/gtsam.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
