# File AlgebraHelpers.hpp

namespace Acts

Note

This file is foreseen for the `Geometry` module to replace `Extent`

Functions

template<typename MatrixType>
MatrixType bitsetToMatrix(const std::bitset<MatrixType::RowsAtCompileTime * MatrixType::ColsAtCompileTime> bs)

Convert a bitset to a matrix of integers, with each element set to the bit value.

Note

How the bits are assigned to matrix elements depends on the storage type of the matrix being converted (row-major or col-major)

Template Parameters

MatrixType – Matrix type that is produced

Parameters

bs – The bitset to convert

Returns

A matrix with the integer values of the bits from `bs`

template<typename A, typename B>
inline ActsMatrix<A::RowsAtCompileTime, B::ColsAtCompileTime> blockedMult(const A &a, const B &b)

Perform a blocked matrix multiplication, avoiding Eigen GEMM methods.

Template Parameters
• A – The type of the first matrix, which should be MxN

• B – The type of the second matrix, which should be NxP

Parameters
• a[in] An MxN matrix of type A

• b[in] An NxP matrix of type P

Returns

The product ab

template<typename Derived>
auto matrixToBitset(const Eigen::PlainObjectBase<Derived> &m)

Convert an integer matrix to a bitset.

Note

How the bits are ordered depends on the storage type of the matrix being converted (row-major or col-major)

Template Parameters

Derived – Eigen base concrete type

Parameters

m – Matrix that is converted

Returns

The converted bitset.

template<typename T>
constexpr T safeExp(T val) noexcept

Calculate the exponential function while avoiding FPEs.

Parameters

val – argument for which the exponential function should be evaluated.

Returns

0 in the case of underflow, std::numeric_limits<T>::infinity in the case of overflow, std::exp(val) else

template<typename MatrixType, typename ResultType = MatrixType>
std::optional<ResultType> safeInverse(const MatrixType &m) noexcept

FPE “safe” functions.

Our main motivation for this is that users might have a strict FPE policy which would flag every single occurrence as a failure and then sombody has to investigate. Since we are processing a high number of events and floating point numbers sometimes work in mysterious ways the caller of this function might want to hide FPEs and handle them in a more controlled way. Calculate the inverse of an Eigen matrix after checking if it can be numerically inverted. This allows to catch potential FPEs before they occur.

Template Parameters
• Derived – Eigen derived concrete type

• Result – Eigen result type defaulted to input type

Parameters

m – Eigen matrix to invert

Returns

The theta value

template<typename T>
struct ExpSafeLimit
#include <Acts/Utilities/AlgebraHelpers.hpp>

Specialization of the exponent limit to be used for safe exponential, depending on the floating point type.

See https://godbolt.org/z/z53Er6Mzf for reasoning for the concrete numbers.

template<>
struct ExpSafeLimit<double>
#include <Acts/Utilities/AlgebraHelpers.hpp>

Public Static Attributes

static constexpr double value = 500.0
template<>
struct ExpSafeLimit<float>
#include <Acts/Utilities/AlgebraHelpers.hpp>

Public Static Attributes

static constexpr float value = 50.0