Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::SimdGeneralizedLossT< T > Class Template Reference

SIMD (vectorized) variant of GeneralizedLossT that operates on DrJit Packet<T> lanes instead of individual scalars. More...

#include <simd_generalized_loss.h>

Inheritance diagram for momentum::SimdGeneralizedLossT< T >:

Public Types

using Base = GeneralizedLossT<T>

Public Member Functions

 SimdGeneralizedLossT (const T &a=Base::kL2, const T &c=T(1))
 Constructs a SIMD generalized loss with shape a and scale c.
Packet< T > value (const Packet< T > &sqrError) const
 Returns the loss value for each lane of sqrError.
Packet< T > deriv (const Packet< T > &sqrError) const
 Returns d(loss)/d(sqrError) for each lane of sqrError.
Public Member Functions inherited from momentum::GeneralizedLossT< T >
 GeneralizedLossT (const T &a=kL2, const T &c=T(1))
 Constructs a generalized loss with shape a and scale c.
T value (const T &sqrError) const
 Returns the loss value for a given squared error.
T deriv (const T &sqrError) const
 Derivative of the loss with respect to the input squared error.
bool isL2 () const
 Returns true if this loss is an L2 loss (alpha ~= 2).
T invC2 () const
 Returns the stored 1/c^2 value. For default c=1, this is 1.0.

Additional Inherited Members

Static Public Attributes inherited from momentum::GeneralizedLossT< T >
static constexpr T kL2 = T(2)
 Special-case alpha values that are either at a singularity in the general formula or simplify to a closed-form computation.
static constexpr T kL1 = T(1)
static constexpr T kCauchy = T(0)
static constexpr T kWelsch = std::numeric_limits<T>::lowest()
 Sentinel for the Welsch (alpha -> -inf) limit.
Protected Types inherited from momentum::GeneralizedLossT< T >
enum class  LossType {
  L1 , L2 , Cauchy , Welsch ,
  General
}
Protected Attributes inherited from momentum::GeneralizedLossT< T >
const T alpha_
const T invC2_
 Stored as 1/c^2 (instead of c) as a small optimization, since the loss formulas use this quantity directly.
LossType lossType_
Static Protected Attributes inherited from momentum::GeneralizedLossT< T >
static constexpr T kEps = 1e-9
 Small threshold used to detect proximity to special-case alpha values.

Detailed Description

template<typename T>
class momentum::SimdGeneralizedLossT< T >

SIMD (vectorized) variant of GeneralizedLossT that operates on DrJit Packet<T> lanes instead of individual scalars.

See GeneralizedLossT for the full mathematical description, the meaning of alpha and c, and the alpha-value reference (L2, L1/pseudo-Huber, Cauchy, Geman-McClure, Welsch).

Inherits the scalar value() / deriv() overloads and the cached lossType_ / invC2_ state from the base class. Branching on the loss type is uniform across all packet lanes (alpha is fixed at construction), so no per-lane masking is needed in the implementation.

When to use
Use this class inside SIMD error functions that process multiple constraints in a single packet (e.g., Simd*ErrorFunction). For scalar error functions or one-off evaluations, prefer the base GeneralizedLossT directly.
Thread safety
Instances are immutable after construction (all state is const in the base class), so concurrent reads from multiple threads are safe. Each evaluation is stateless.

Definition at line 33 of file simd_generalized_loss.h.

Member Typedef Documentation

◆ Base

template<typename T>
using momentum::SimdGeneralizedLossT< T >::Base = GeneralizedLossT<T>

Definition at line 35 of file simd_generalized_loss.h.

Constructor & Destructor Documentation

◆ SimdGeneralizedLossT()

template<typename T>
momentum::SimdGeneralizedLossT< T >::SimdGeneralizedLossT ( const T & a = Base::kL2,
const T & c = T(1) )
explicit

Constructs a SIMD generalized loss with shape a and scale c.

Parameters
aShape parameter alpha. See GeneralizedLossT for the alpha-value reference and the special-case constants (kL2, kL1, kCauchy, kWelsch).
cScale parameter. Must be > 0.

Definition at line 75 of file simd_generalized_loss.cpp.

Member Function Documentation

◆ deriv()

template<typename T>
Packet< T > momentum::SimdGeneralizedLossT< T >::deriv ( const Packet< T > & sqrError) const
nodiscard

Returns d(loss)/d(sqrError) for each lane of sqrError.

Used to chain-rule the loss into the Jacobian of the underlying residual.

Parameters
sqrErrorPacket of non-negative squared residuals (one per lane).
Returns
Packet of derivatives, one per input lane.

Definition at line 115 of file simd_generalized_loss.cpp.

References momentum::GeneralizedLossT< T >::alpha_, momentum::GeneralizedLossT< T >::Cauchy, momentum::GeneralizedLossT< T >::General, momentum::GeneralizedLossT< T >::invC2_, momentum::GeneralizedLossT< T >::L1, momentum::GeneralizedLossT< T >::L2, momentum::GeneralizedLossT< T >::lossType_, MT_LOGE, and momentum::GeneralizedLossT< T >::Welsch.

◆ value()

template<typename T>
Packet< T > momentum::SimdGeneralizedLossT< T >::value ( const Packet< T > & sqrError) const
nodiscard

The documentation for this class was generated from the following files: