trsl logo

Template Range Sampling Library Documentation


TRSL is a C++ library that implements several sampling schemes behind an (STL-like) iterator interface. The library may be used e.g. in particle filtering or probabilistic inference frameworks. For an overview of the functionalities provided by TRSL, refer to the Products page.


Released TRSL 0.2.2. This release contains minor updates, see Version History for a list of changes.
The Boost Software License is now Open Source (certified by OSI since Feb. 2008).
Released TRSL 0.2.1. This release contains minor updates only, see Version History for a list of changes.
TRSL 0.2.0 is out. See Version History for a list of changes.
TRSL 0.1.1 is out. See Version History for a list of changes.


TRSL is distributed under the Boost Software License (BSL). BSL is a GPL-compatible free-software license, very similar to the BSD license and the MIT license; see Boost Software License Background. BSL is also open-source; see Boost Software License 1.0 on the Open Source Initiative website.


TRSL is in a usable state. However, as its version number suggests, it is likely to grow and change interface in the future.


Releases are available at the Sourceforge download page. The latest sources are available through Subversion:
svn co trsl

Project Services

Sourceforge project page.

TRSL is meant to be OS Portable. It has been tested on Linux and MacOS X with GCC 4 and LLVM 2.8 (with clang). If anyone tries it with a different compiler/platform, please comment!


The preferred method of communication is currently the Sourceforge forums (anonymous posts allowed).


See the Products page for the complete list of functionalities offered by TRSL.

The central TRSL product is trsl::is_picked_systematic, a predicate functor to use in combination with trsl::persistent_filter_iterator to form a sample iterator. The sample iterator accesses a population of elements through a range defined by a pair of Forward Iterators (begin/end), and provides on-the-fly iteration through a sample of the population.

Let us assume a particle filter implementation, which manages a population of particles (struct Particle { weight; x; y; }) stored in a container ParticleCollection. The following bit of code shows an example of how to iterate through a sample of the population after having implemented ParticleCollection::sample_begin(size_t) and ParticleCollection::sample_end() using e.g. trsl::is_picked_systematic.

const size_t POPULATION_SIZE = 100;
const size_t SAMPLE_SIZE = 10;

// Generate a population //

ParticleCollection population;
for (size_t i = 0; i < POPULATION_SIZE; ++i)
  Particle p(double(rand())/RAND_MAX,  // weight
             double(rand())/RAND_MAX,  // position (x)
             double(rand())/RAND_MAX); // position (y)

// Sample from the population //

ParticleCollection sample;

//-- population contains 100 elements. --//

for (ParticleCollection::const_sample_iterator
       si = population.sample_begin(SAMPLE_SIZE),
       se = population.sample_end();
     si != se; ++si)
  Particle p = *si;

  // ... or do something else with *si ...

//-- sample contains 10 elements. --//

assert(sample.size() == SAMPLE_SIZE);


TRSL is developped by Renaud Detry.


TRSL is based on the excellent Boost Iterator Library.

Several concept implementations (e.g. accessors) are inspired from libkdtree++.

© Copyright 2007-2011 Renaud Detry.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
Revised Wed Apr 6 16:30:07 2011. Logo