PhysicsBasedAnimationToolkit 0.0.10
Cross-platform C++20 library of algorithms and data structures commonly used in computer graphics research on physically-based simulation.
Loading...
Searching...
No Matches
pbat::common Namespace Reference

Common functionality. More...

Classes

class  BinaryRadixTree
 Binary radix tree implementation. More...
 
class  BruteSet
 Fixed-size brute-force set implementation. More...
 
class  Heap
 Fixed-size max heap. More...
 
struct  Overloaded
 C++20 feature to allow multiple inheritance of operator() for lambdas. More...
 
class  Queue
 Fixed-size queue implementation. More...
 
class  Stack
 Fixed-size stack implementation. More...
 

Concepts

concept  CArithmetic
 Concept for arithmetic types.
 
concept  CIndex
 Concept for integral types.
 
concept  CFloatingPoint
 Concept for floating-point types.
 
concept  CIndexRange
 Range of integer types.
 
concept  CContiguousIndexRange
 Contiguous range of integer types.
 
concept  CArithmeticRange
 Range of arithmetic types.
 
concept  CContiguousArithmeticRange
 Contiguous range of arithmetic types.
 
concept  CContiguousArithmeticMatrixRange
 Range of Eigen fixed-size matrix types.
 

Functions

template<std::integral TIndex, class FLess>
auto ArgSort (TIndex n, FLess less) -> Eigen::Vector< TIndex, Eigen::Dynamic >
 Computes the indices that would sort an array.
 
template<class... Ts, class F>
constexpr void ForTypes (F &&f)
 Compile-time for loop over types.
 
template<auto... Xs, class F>
constexpr void ForValues (F &&f)
 Compile-time for loop over values.
 
template<auto Begin, auto End, typename F>
constexpr void ForRange (F &&f)
 Compile-time for loop over a range of values.
 
template<std::random_access_iterator TWorkBegin, std::random_access_iterator TWorkEnd, std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, class FKey, class T = typename std::iterator_traits<TValuesBegin>::value_type, class TKey = typename std::invoke_result_t<FKey, T>>
void CountingSort (TWorkBegin wb, TWorkEnd we, TValuesBegin vb, TValuesEnd ve, TKey keyMin=std::numeric_limits< TKey >::max(), FKey fKey=[](T const &key) { return key;})
 Counting sort.
 
template<std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, std::random_access_iterator TWorkBegin, class FKey>
void PrefixSumFromSortedKeys (TValuesBegin vb, TValuesEnd ve, TWorkBegin wb, FKey fKey)
 
template<CContiguousArithmeticRange R>
auto ToEigen (R &&r) -> Eigen::Map< Eigen::Vector< std::ranges::range_value_t< R >, Eigen::Dynamic > const >
 Map a range of scalars to an eigen vector of such scalars.
 
template<std::ranges::random_access_range R>
auto Slice (R &&r)
 Slice view over a range for Eigen advanced indexing.
 
template<typename T>
void HashCombineAccumulate (std::size_t &seed, T const &val)
 Incrementally combine hash values of multiple arguments.
 
template<typename... Types>
std::size_t HashCombine (Types const &... args)
 Combine hash values of multiple arguments.
 
template<CIndexRange R, std::integral TIndex = std::ranges::range_value_t<R>>
auto CumSum (R &&sizes) -> Eigen::Vector< TIndex, Eigen::Dynamic >
 Cumulative sum of a range of integers.
 
template<std::integral TIndex>
auto Counts (auto begin, auto end, TIndex ncounts) -> Eigen::Vector< TIndex, Eigen::Dynamic >
 Counts the number of occurrences of each integer in a contiguous range.
 
template<std::integral TIndex>
auto Shuffle (TIndex begin, TIndex end) -> Eigen::Vector< TIndex, Eigen::Dynamic >
 Randomly shuffle a range of integers.
 
template<std::integral TIndexB, std::integral TIndexE, class Func, class TIndex = std::common_type_t<TIndexB, TIndexE>>
auto Filter (TIndexB begin, TIndexE end, Func &&f) -> Eigen::Vector< TIndex, Eigen::Dynamic >
 Filters a range of integers based on a predicate function.
 
template<class TDerivedX, class TDerivedR, class TScalar = typename TDerivedX::Scalar, std::integral TIndex = typename TDerivedR::Scalar>
auto Repeat (Eigen::DenseBase< TDerivedX > const &x, Eigen::DenseBase< TDerivedR > const &r) -> Eigen::Vector< TScalar, Eigen::Dynamic >
 Repeats elements of a vector according to a repetition vector.
 
auto Modulo (auto a, auto b)
 
template<class FVisit, class FChild, class TIndex = Index, auto N = 2, auto kStackDepth = 64>
PBAT_HOST_DEVICE void TraverseNAryTreePseudoPreOrder (FVisit fVisit, FChild fChild, TIndex root=0)
 Pre-order traversal over an n-ary tree starting from root.
 
template<class FVisit, class FChild, class TIndex = Index, auto N = 2, auto kStackDepth = 64>
PBAT_HOST_DEVICE void TraverseNAryTreePseudoPostOrder (FVisit fVisit, FChild fChild, TIndex root=0)
 Post-order traversal over an n-ary tree starting from root.
 
template<std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, std::random_access_iterator TPermutationBegin>
void Permute (TValuesBegin vb, TValuesEnd ve, TPermutationBegin pb)
 Permute the values in-place according to the permutation.
 

Detailed Description

Common functionality.

Function Documentation

◆ ArgSort()

template<std::integral TIndex, class FLess>
auto pbat::common::ArgSort ( TIndex n,
FLess less ) -> Eigen::Vector<TIndex, Eigen::Dynamic>

Computes the indices that would sort an array.

Template Parameters
TIndexCoefficient type of returned vector
FLessCallable with signature bool(TIndex, TIndex)
Parameters
nNumber of elements
lessLess-than comparison function object
Returns
|n| array of indices that would sort the input array

◆ CountingSort()

template<std::random_access_iterator TWorkBegin, std::random_access_iterator TWorkEnd, std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, class FKey, class T = typename std::iterator_traits<TValuesBegin>::value_type, class TKey = typename std::invoke_result_t<FKey, T>>
void pbat::common::CountingSort ( TWorkBegin wb,
TWorkEnd we,
TValuesBegin vb,
TValuesEnd ve,
TKey keyMin = std::numeric_limits<TKey>::max(),
FKey fKey = [](T const& key) { return key; } )

Counting sort.

Template Parameters
TWorkBeginIterator type to the beginning of the work array
TWorkEndIterator type to the end of the work array
TValuesBeginIterator type to the beginning of the values
TValuesEndIterator type to the end of the values
FKeyKey accessor callable with signature TKey(T)
TValue type
TKeyKey type
Parameters
wbIterator to the beginning of the work array
weIterator to the end of the work array
vbIterator to the beginning of values
veIterator to the end of values
keyMinMinimum key value
fKeyKey accessor callable
Precondition
*(wb+i) == 0 for all i in [0, std::distance(wb,we))

◆ Counts()

template<std::integral TIndex>
auto pbat::common::Counts ( auto begin,
auto end,
TIndex ncounts ) -> Eigen::Vector<TIndex, Eigen::Dynamic>

Counts the number of occurrences of each integer in a contiguous range.

Template Parameters
TIndexInteger type of counts
Parameters
beginRange begin
endRange end (exclusive)
ncountsUpper bound on values in range
Returns
Counts of each integer in the range

◆ CumSum()

template<CIndexRange R, std::integral TIndex = std::ranges::range_value_t<R>>
auto pbat::common::CumSum ( R && sizes) -> Eigen::Vector<TIndex, Eigen::Dynamic>

Cumulative sum of a range of integers.

Template Parameters
RInteger range type
TIndexType of the integers
Parameters
sizesRange of integers
Returns
Cumulative sum of the range

◆ Filter()

template<std::integral TIndexB, std::integral TIndexE, class Func, class TIndex = std::common_type_t<TIndexB, TIndexE>>
auto pbat::common::Filter ( TIndexB begin,
TIndexE end,
Func && f ) -> Eigen::Vector<TIndex, Eigen::Dynamic>

Filters a range of integers based on a predicate function.

Template Parameters
TIndexBType of the beginning index
TIndexEType of the ending index
FuncPredicate function type (TIndex -> bool)
TIndexCommon type of the indices
Parameters
beginStart of the range (inclusive)
endEnd of the range (exclusive)
fPredicate function to filter the range
Returns
Filtered range of integers

◆ ForRange()

template<auto Begin, auto End, typename F>
void pbat::common::ForRange ( F && f)
constexpr

Compile-time for loop over a range of values.

Template Parameters
BeginStarting loop index
EndEnding loop index (exclusive)
FCallable with signature void operator()<decltype(Begin)>()
Parameters
fFunction object to call

◆ ForTypes()

template<class... Ts, class F>
void pbat::common::ForTypes ( F && f)
constexpr

Compile-time for loop over types.

Template Parameters
TsTypes to loop over
FCallable with signature void operator()<T>()
Parameters
fFunction object to call

◆ ForValues()

template<auto... Xs, class F>
void pbat::common::ForValues ( F && f)
constexpr

Compile-time for loop over values.

Template Parameters
XsValues to loop over
FCallable with signature void operator()<X>()
Parameters
fFunction object to call

◆ HashCombine()

template<typename... Types>
std::size_t pbat::common::HashCombine ( Types const &... args)

Combine hash values of multiple arguments.

Template Parameters
TypesHashable types
Parameters
argsArguments to hash
Returns
Hash value

◆ HashCombineAccumulate()

template<typename T>
void pbat::common::HashCombineAccumulate ( std::size_t & seed,
T const & val )

Incrementally combine hash values of multiple arguments.

Template Parameters
THashable type
Parameters
seedStarting hash value
valValue to hash

◆ Permute()

template<std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, std::random_access_iterator TPermutationBegin>
void pbat::common::Permute ( TValuesBegin vb,
TValuesEnd ve,
TPermutationBegin pb )

Permute the values in-place according to the permutation.

Taken from SO

Template Parameters
TValuesBeginIterator type to the beginning of the values
TValuesEndIterator type to the end of the values
TPermutationBeginIterator type to the beginning of the permutation
Parameters
vbIterator to the beginning of values
veIterator to the end of values
pbIterator to the beginning of permutation
Note
The permutation is modified in-place for the duration of the function, but is restored to its original state before returning.
Postcondition
The permutation referenced by pb is un-modified.
The values referenced by [vb, ve) are permuted according to the permutation.

◆ PrefixSumFromSortedKeys()

template<std::random_access_iterator TValuesBegin, std::random_access_iterator TValuesEnd, std::random_access_iterator TWorkBegin, class FKey>
void pbat::common::PrefixSumFromSortedKeys ( TValuesBegin vb,
TValuesEnd ve,
TWorkBegin wb,
FKey fKey )
Template Parameters
FKey
TValuesBegin
TValuesEnd
TWorkBegin
Parameters
vb
ve
wb
fKey

◆ Repeat()

template<class TDerivedX, class TDerivedR, class TScalar = typename TDerivedX::Scalar, std::integral TIndex = typename TDerivedR::Scalar>
auto pbat::common::Repeat ( Eigen::DenseBase< TDerivedX > const & x,
Eigen::DenseBase< TDerivedR > const & r ) -> Eigen::Vector<TScalar, Eigen::Dynamic>

Repeats elements of a vector according to a repetition vector.

Similar to numpy.repeat

Template Parameters
TDerivedXEigen dense expression of the input vector
TDerivedREigen dense expression of the repetition vector
TScalarScalar type of the input vector
TIndexInteger type of the repetition vector
Parameters
xValues to repeat
rRepetition vector
Returns
Vector with repeated elements

◆ Shuffle()

template<std::integral TIndex>
auto pbat::common::Shuffle ( TIndex begin,
TIndex end ) -> Eigen::Vector<TIndex, Eigen::Dynamic>

Randomly shuffle a range of integers.

Template Parameters
TIndexInteger type of the range
Parameters
beginStart of the range (inclusive)
endEnd of the range (exclusive)
Returns
Shuffled range of integers

◆ Slice()

template<std::ranges::random_access_range R>
auto pbat::common::Slice ( R && r)

Slice view over a range for Eigen advanced indexing.

Template Parameters
RRange type
Parameters
rRange
Returns
Type with size(), operator[] and operator() for Eigen advanced indexing

◆ ToEigen()

template<CContiguousArithmeticRange R>
auto pbat::common::ToEigen ( R && r) -> Eigen::Map<Eigen::Vector<std::ranges::range_value_t<R>, Eigen::Dynamic> const>

Map a range of scalars to an eigen vector of such scalars.

Map a range of scalar matrices to an eigen vector of such scalars.

Template Parameters
RRange type
Parameters
rRange
Returns
Eigen vector adaptor
Template Parameters
RRange type
Parameters
rRange
Returns
Eigen matrix adaptor

◆ TraverseNAryTreePseudoPostOrder()

template<class FVisit, class FChild, class TIndex = Index, auto N = 2, auto kStackDepth = 64>
PBAT_HOST_DEVICE void pbat::common::TraverseNAryTreePseudoPostOrder ( FVisit fVisit,
FChild fChild,
TIndex root = 0 )

Post-order traversal over an n-ary tree starting from root.

Template Parameters
FVisitFunction to visit a node
FChildFunction to get the child of a node
TIndexType of the index
NNumber of children per node
kStackDepthMaximum depth of the traversal's stack. The actual stack depth will be N*kStackDepth.
Parameters
fVisitvoid(TIndex node) function to visit a node.
fChildtemplate <TIndex c> TIndex(TIndex node) function to get child c of a node. Returns the child index or -1 if no child.
rootIndex of the root node to start the search from
Note
The traversal is deemed "pseudo" post-order because each visited node's children are visited in arbitrary order. The only guarantee is that a parent node is visited after its children. This is due to compile-time loops not being able to guarantee the order of execution.
The visitor does not support sub-tree pruning, since visited nodes are always processed after their sub-tree.

◆ TraverseNAryTreePseudoPreOrder()

template<class FVisit, class FChild, class TIndex = Index, auto N = 2, auto kStackDepth = 64>
PBAT_HOST_DEVICE void pbat::common::TraverseNAryTreePseudoPreOrder ( FVisit fVisit,
FChild fChild,
TIndex root = 0 )

Pre-order traversal over an n-ary tree starting from root.

Template Parameters
FVisitFunction to visit a node
FChildFunction to get the child of a node
TIndexType of the index
NNumber of children per node
kStackDepthMaximum depth of the traversal's stack
Parameters
fVisitbool(TIndex node) function to visit a node. Returns true if node's sub-tree should be visited.
fChildtemplate <TIndex c> TIndex(TIndex node) function to get child c of a node. Returns the child index or -1 if no child.
rootIndex of the root node to start the search from
Note
The traversal is deemed "pseudo" pre-order because each visited node's children are visited in arbitrary order. The only guarantee is that a parent node is visited before its children. This is due to compile-time loops not being able to guarantee the order of execution.