OpenVDB 14.0.0
Loading...
Searching...
No Matches
MatBase< T, ROWS, COLS > Class Template Reference

Base class for fixed-size matrices. Provides shared element-wise arithmetic, scalar arithmetic, equality, transpose, mat*mat, and mat*vec. Storage is a flat row-major array mData[ROWS * COLS]. Derived classes supply constructors plus any dimension-specific extras (e.g. inverse() on Mat2). More...

#include <nanovdb/math/Math.h>

Public Types

using ValueType = T

Public Member Functions

 MatBase () noexcept=default
 Default-construct (entries are left uninitialized for trivially-default-constructible T).
template<typename S>
__hostdev__ constexpr MatBase (S *array) noexcept
 Read ROWS*COLS elements from array in row-major order, converting each element from S to T via static_cast.
__hostdev__ constexpr T * operator[] (int row) noexcept
 2D row access. Returns a pointer to the start of row; the caller indexes into it with the column. Asserts 0 <= row < ROWS in debug builds; column index is the caller's responsibility (use 0 <= col < COLS).
__hostdev__ constexpr const T * operator[] (int row) const noexcept
 Const overload of operator[](int); see non-const variant.
__hostdev__ constexpr T * data () noexcept
 return a raw pointer to the underlying 1D storage (row-major)
__hostdev__ constexpr const T * data () const noexcept
 return a const raw pointer to the underlying 1D storage (row-major)
template<typename Derived>
__hostdev__ constexpr Derived plus (const Derived &rhs) const noexcept
 return *this + rhs as a Derived
template<typename Derived>
__hostdev__ constexpr Derived minus (const Derived &rhs) const noexcept
 return *this - rhs as a Derived
template<typename Derived>
__hostdev__ constexpr Derived negate () const noexcept
 return -(*this) as a Derived
template<typename Derived>
__hostdev__ constexpr Derived scale (T s) const noexcept
 return s * (*this) as a Derived
__hostdev__ constexpr MatBase & addAssign (const MatBase &rhs) noexcept
 Element-wise add rhs into *this and return *this.
__hostdev__ constexpr MatBase & subAssign (const MatBase &rhs) noexcept
 Element-wise subtract rhs from *this and return *this.
__hostdev__ constexpr MatBase & scaleAssign (T s) noexcept
 Multiply every element by scalar s in place; return *this. s is taken by value so m *= m[0][0] scales every element by the original value.
template<typename Derived>
__hostdev__ constexpr Derived divideBy (T s) const noexcept
 return (*this) / s element-wise as a Derived. Floating-point T multiplies by the reciprocal 1/s; integer T divides each element, since 1/s would truncate to zero.
__hostdev__ constexpr MatBase & divideAssignScalar (T s) noexcept
 Divide every element by scalar s in place; return *this. Uses the same floating-point reciprocal / integer per-element split as divideBy. s is taken by value so m /= m[0][0] is safe.
__hostdev__ constexpr bool equals (const MatBase &rhs) const noexcept
 Return true iff every element compares equal to rhs.
template<typename Result>
__hostdev__ constexpr Result transposeAs () const noexcept
 return the transpose of *this as the Result type.
template<typename Result, typename Rhs>
__hostdev__ constexpr Result multiply (const Rhs &rhs) const noexcept
 return (*this) * rhs as the Result type.
template<typename VecResult, typename VecRhs>
__hostdev__ constexpr VecResult multiplyVec (const VecRhs &v) const noexcept
 return (*this) * v as the VecResult type.

Static Public Member Functions

static __hostdev__ constexpr int rows () noexcept
 Compile-time row count.
static __hostdev__ constexpr int cols () noexcept
 Compile-time column count.
static __hostdev__ constexpr int size () noexcept
 Compile-time element count, i.e. ROWS * COLS.

Protected Member Functions

template<typename... Args>
__hostdev__ constexpr MatBase (Args... args) noexcept
 Variadic component-init ctor — used only by derived ctors (Mat2(T a, T b, T c, T d) : Base(a, b, c, d) {}). The member-init list directly initializes mData, avoiding the default-construct- then-assign that a body-assignment ctor would impose on a non-fundamental T.

Static Protected Member Functions

template<typename Result, typename F, int... I>
static __hostdev__ constexpr Result generate (F f, std::integer_sequence< int, I... >) noexcept
 Return a Result whose row-major element idx is f(idx), built through its Count-element constructor. This is constexpr-valid in C++17 without first value-initializing a result and overwriting it.
template<typename Result, int Count = ROWS * COLS, typename F>
static __hostdev__ constexpr Result generate (F f) noexcept

Protected Attributes

T mData [ROWS *COLS]

Detailed Description

template<typename T, int ROWS, int COLS>
class nanovdb::math::MatBase< T, ROWS, COLS >

Base class for fixed-size matrices. Provides shared element-wise arithmetic, scalar arithmetic, equality, transpose, mat*mat, and mat*vec. Storage is a flat row-major array mData[ROWS * COLS]. Derived classes supply constructors plus any dimension-specific extras (e.g. inverse() on Mat2).

Member Typedef Documentation

◆ ValueType

template<typename T, int ROWS, int COLS>
using ValueType = T

Constructor & Destructor Documentation

◆ MatBase() [1/3]

template<typename T, int ROWS, int COLS>
MatBase ( )
defaultnoexcept

Default-construct (entries are left uninitialized for trivially-default-constructible T).

◆ MatBase() [2/3]

template<typename T, int ROWS, int COLS>
template<typename S>
__hostdev__ constexpr MatBase ( S * array)
inlineconstexprnoexcept

Read ROWS*COLS elements from array in row-major order, converting each element from S to T via static_cast.

◆ MatBase() [3/3]

template<typename T, int ROWS, int COLS>
template<typename... Args>
__hostdev__ constexpr MatBase ( Args... args)
inlineexplicitconstexprprotectednoexcept

Variadic component-init ctor — used only by derived ctors (Mat2(T a, T b, T c, T d) : Base(a, b, c, d) {}). The member-init list directly initializes mData, avoiding the default-construct- then-assign that a body-assignment ctor would impose on a non-fundamental T.

Member Function Documentation

◆ addAssign()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr MatBase & addAssign ( const MatBase< T, ROWS, COLS > & rhs)
inlineconstexprnoexcept

Element-wise add rhs into *this and return *this.

◆ cols()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr int cols ( )
inlinestaticnodiscardconstexprnoexcept

Compile-time column count.

◆ data() [1/2]

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr const T * data ( ) const
inlineconstexprnoexcept

return a const raw pointer to the underlying 1D storage (row-major)

◆ data() [2/2]

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr T * data ( )
inlineconstexprnoexcept

return a raw pointer to the underlying 1D storage (row-major)

◆ divideAssignScalar()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr MatBase & divideAssignScalar ( T s)
inlineconstexprnoexcept

Divide every element by scalar s in place; return *this. Uses the same floating-point reciprocal / integer per-element split as divideBy. s is taken by value so m /= m[0][0] is safe.

◆ divideBy()

template<typename T, int ROWS, int COLS>
template<typename Derived>
__hostdev__ constexpr Derived divideBy ( T s) const
inlinenodiscardconstexprnoexcept

return (*this) / s element-wise as a Derived. Floating-point T multiplies by the reciprocal 1/s; integer T divides each element, since 1/s would truncate to zero.

◆ equals()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr bool equals ( const MatBase< T, ROWS, COLS > & rhs) const
inlinenodiscardconstexprnoexcept

Return true iff every element compares equal to rhs.

◆ generate() [1/2]

template<typename T, int ROWS, int COLS>
template<typename Result, int Count = ROWS * COLS, typename F>
__hostdev__ constexpr Result generate ( F f)
inlinestaticconstexprprotectednoexcept

◆ generate() [2/2]

template<typename T, int ROWS, int COLS>
template<typename Result, typename F, int... I>
__hostdev__ constexpr Result generate ( F f,
std::integer_sequence< int, I... >  )
inlinestaticconstexprprotectednoexcept

Return a Result whose row-major element idx is f(idx), built through its Count-element constructor. This is constexpr-valid in C++17 without first value-initializing a result and overwriting it.

◆ minus()

template<typename T, int ROWS, int COLS>
template<typename Derived>
__hostdev__ constexpr Derived minus ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

return *this - rhs as a Derived

◆ multiply()

template<typename T, int ROWS, int COLS>
template<typename Result, typename Rhs>
__hostdev__ constexpr Result multiply ( const Rhs & rhs) const
inlinenodiscardconstexprnoexcept

return (*this) * rhs as the Result type.

Template Parameters
Resulta matrix type whose dimensions are (ROWS, Rhs::cols())
Rhsa matrix type whose row count equals COLS

◆ multiplyVec()

template<typename T, int ROWS, int COLS>
template<typename VecResult, typename VecRhs>
__hostdev__ constexpr VecResult multiplyVec ( const VecRhs & v) const
inlinenodiscardconstexprnoexcept

return (*this) * v as the VecResult type.

Template Parameters
VecResulta vector type whose SIZE equals ROWS
VecRhsa vector type whose SIZE equals COLS

◆ negate()

template<typename T, int ROWS, int COLS>
template<typename Derived>
__hostdev__ constexpr Derived negate ( ) const
inlinenodiscardconstexprnoexcept

return -(*this) as a Derived

◆ operator[]() [1/2]

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr const T * operator[] ( int row) const
inlineconstexprnoexcept

Const overload of operator[](int); see non-const variant.

◆ operator[]() [2/2]

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr T * operator[] ( int row)
inlineconstexprnoexcept

2D row access. Returns a pointer to the start of row; the caller indexes into it with the column. Asserts 0 <= row < ROWS in debug builds; column index is the caller's responsibility (use 0 <= col < COLS).

◆ plus()

template<typename T, int ROWS, int COLS>
template<typename Derived>
__hostdev__ constexpr Derived plus ( const Derived & rhs) const
inlinenodiscardconstexprnoexcept

return *this + rhs as a Derived

◆ rows()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr int rows ( )
inlinestaticnodiscardconstexprnoexcept

Compile-time row count.

◆ scale()

template<typename T, int ROWS, int COLS>
template<typename Derived>
__hostdev__ constexpr Derived scale ( T s) const
inlinenodiscardconstexprnoexcept

return s * (*this) as a Derived

◆ scaleAssign()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr MatBase & scaleAssign ( T s)
inlineconstexprnoexcept

Multiply every element by scalar s in place; return *this. s is taken by value so m *= m[0][0] scales every element by the original value.

◆ size()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr int size ( )
inlinestaticnodiscardconstexprnoexcept

Compile-time element count, i.e. ROWS * COLS.

◆ subAssign()

template<typename T, int ROWS, int COLS>
__hostdev__ constexpr MatBase & subAssign ( const MatBase< T, ROWS, COLS > & rhs)
inlineconstexprnoexcept

Element-wise subtract rhs from *this and return *this.

◆ transposeAs()

template<typename T, int ROWS, int COLS>
template<typename Result>
__hostdev__ constexpr Result transposeAs ( ) const
inlinenodiscardconstexprnoexcept

return the transpose of *this as the Result type.

Template Parameters
Resulta matrix type whose dimensions are (COLS, ROWS)

Member Data Documentation

◆ mData

template<typename T, int ROWS, int COLS>
T mData[ROWS *COLS]
protected