File numerics/src/tools/op3x3.h#

Go to the source code of this file

linear algebra operations in 3D

Defines

M_PI#
M_PI_2#
MAYBE_UNUSED#
WARN_RESULT_IGNORED#
SOLVE_3X3_GEPP(MAT, X)#
OP3X3(EXPR)#

OP3X3(EXPR) do EXPR 9 times.

Parameters:
  • EXPR – a C expression that should contains self incrementing pointers on arrays[9]

OP3(EXPR)#

OP3(EXPR) do EXPR 3 times.

Parameters:
  • EXPR – a C expression that should contains self incrementing pointers on arrays[9]

SET3X3(V)#

SET3X3 : set pointers on a 3x3 matrix a (*a00 *a01 *a10 etc.) warning the pointer a is modified (use a00 instead) and is ready for a next SET3X3.

SET3X3MAYBE(V)#
SET3(V)#

SET3 : set pointers on a vector3 v (*v0 *v1 *v2) Warning: the pointer v is modified and is ready for a next SET3 use *v0 if you need *v.

SET3MAYBE(V)#

SET3MAYBE : set pointers on a vector3 v (*v0 *v1 *v2) only if v is non null.

Warning: the pointer v is modified and is ready for a next SET3 use *v0 if you need *v

mat_elem(a, y, x, n)#
A(y, x)#

Functions

static inline void cpy3x3 (double *restrict a, double *restrict b)

copy a 3x3 matrix or a vector[9]

Parameters:
  • a[in] a[9]

  • b[out] b[9]

static inline void add3x3(double a[9], double b[9])#

add a 3x3 matrix or a vector[9]

Parameters:
  • a[in] a[9]

  • b[inout] b[9]

static inline void sub3x3(double a[9], double b[9])#

sub a 3x3 matrix or a vector[9]

Parameters:
  • a[in] a[9]

  • b[inout] b[9]

static inline void cpy3(double a[3], double b[3])#

copy a vector[3]

Parameters:
  • a[in] a[3]

  • b[out] b[3]

static inline void add3(double a[3], double b[3])#

add a vector[3]

Parameters:
  • a[in] a[3]

  • b[inout] b[3]

static inline void sub3(double a[3], double b[3])#

sub a vector[3]

Parameters:
  • a[in] a[3]

  • b[inout] b[3]

static inline void scal3x3(double scal, double m[9])#

scalar multiplication of a matrix3x3

Parameters:
  • scal[in] double scalar

  • m[inout] m[9]

static inline void diag_scal3 (double *restrict scal_coeffs, double *restrict v)

diagonal scaling of a vector

Parameters:
  • scal_coeffs[in] diagonal part of a matrix

  • v[inout] a 3D vector

static inline void scal3(double scal, double *v)#

scalar multiplication of a vector3

Parameters:
  • scal[in] double scalar

  • v[inout] v[3]

static inline void cpytr3x3 (double *restrict a, double *restrict b)

copy & transpose a matrix

Parameters:
  • a[in] *a

  • b[out] transpose(*a)

static inline void mv3x3 (double *restrict a, double *restrict v, double *restrict r)

matrix vector multiplication

Parameters:
  • a[in] 3 by 3 matrix in col-major

  • v[in] 3 dimensional vector

  • r[out] \(r = a*v\)

static inline void mtv3x3 (double *restrict a, double *restrict v, double *restrict r)

transpose(matrix) vector multiplication

Parameters:
  • a[in] 3 by 3 matrix in col-major

  • v[in] 3 dimensional vector

  • r[out] \(r = a^T*v\)

static inline void mvp2x2 (const double *restrict a, const double *restrict v, double *restrict r)

add a matrix vector multiplication

Parameters:
  • a[in] a[4]

  • v[in] v[2]

  • r[out] r[2] the result of r += av

static inline void mvp3x3 (const double *restrict a, const double *restrict v, double *restrict r)

add a matrix vector multiplication

Parameters:
  • a[in] a[9]

  • v[in] v[3]

  • r[out] r[3] the result of r += av

static inline void mvp5x5 (const double *restrict a, const double *restrict v, double *restrict r)
static inline void mvp_alpha3x3 (double alpha, const double *restrict a, const double *restrict v, double *restrict r)

add a matrix vector multiplication scaled by alpha

Parameters:
  • alpha[in] scalar coeff

  • a[in] a[9]

  • v[in] v[3]

  • r[out] r[3] the result of r += av

static inline void mvm3x3 (double *restrict a, double *restrict v, double *restrict r)

minux the result a matrix vector multiplication

Parameters:
  • a[in] matrix

  • v[in] vector

  • r[out] the result of r -= av

static inline void mtvm3x3 (double *restrict a, double *restrict v, double *restrict r)

transpose(matrix) vector multiplication

Parameters:
  • a[in] 3 by 3 matrix in col-major

  • v[in] 3 dimensional vector

  • r[out] \(r = a^T*v\)

static inline void mm3x3 (double *restrict a, double *restrict b, double *restrict c)

matrix matrix multiplication : c = a * b

Parameters:
  • a[in] a[9]

  • b[in] b[9]

  • c[out] c[9]

static inline void mmp3x3 (double *restrict a, double *restrict b, double *restrict c)

add a matrix matrix multiplication : c += a*b

Parameters:
  • a[in] a[9]

  • b[in] b[9]

  • c[out] c[9]

static inline void mmm3x3 (double *restrict a, double *restrict b, double *restrict c)

sub a matrix matrix multiplication : c -= a*b

Parameters:
  • a[in] a[9]

  • b[in] b[9]

  • c[out] c[9]

static inline double det3x3(double *a)#

determinant

Parameters:

a[in] double* a

Returns:

the value of the determinant

static inline WARN_RESULT_IGNORED int solv3x3 (double *restrict a, double *restrict x, double *restrict b)

system resolution : x <- sol(Ax = b)

Parameters:
  • a[in] double a[9]

  • x[out] double x[3]

  • b[in] double b[3]

Returns:

0 if success, 1 if failed

static inline int equal3x3 (double *restrict a, double *restrict b)

check equality : a[9] == b[9]

Parameters:
  • a[in] double a[9]

  • b[in] double b[9]

Returns:

1 if true, 0 if false

static inline int equal3 (double *restrict a, double *restrict b)

check equality : a[3] == b[3]

Parameters:
  • a[in] double a[3]

  • b[in] double b[3]

Returns:

1 if true, 0 if false

static inline double dot3 (double *restrict a, double *restrict b)

scalar product : c <- a.b

Parameters:
  • a[in] double a[3]

  • b[in] double b[3]

Returns:

the scalar product

static inline void cross3 (double *restrict a, double *restrict b, double *restrict c)

cross product : c <- a x b

Parameters:
  • a[in] double a[3]

  • b[in] double b[3]

  • c[out] double c[3]

static inline double hypot2(double *a)#

norm : || a || may underflow & overflow

Parameters:

a[in] a[2]

Returns:

the norm

static inline double hypot3(double *a)#

norm : || a || may underflow & overflow

Parameters:

a[in] a[3]

Returns:

the norm

static inline double hypot5(double *a)#
static inline double hypot9(double *a)#
static inline void extract3x3 (int n, int i0, int j0, double *restrict a, double *restrict b)

extract3x3 : copy a sub 3x3 matrix of *a into *b

static inline void insert3x3 (int n, int i0, int j0, double *restrict a, double *restrict b)

insert3x3 : insert a 3x3 matrix *b into *a

void print3x3(double *mat)#

print a matrix

Parameters:

mat – the matrix

void print3(double *v)#

print a vector

Parameters:

v[in] the vector

static inline WARN_RESULT_IGNORED int orthoBaseFromVector_old (double *Ax, double *Ay, double *Az, double *A1x, double *A1y, double *A1z, double *A2x, double *A2y, double *A2z)

orthoBaseFromVector : From a vector A, build a matrix (A,A1,A2) such that it is an orthonormal.

Parameters:
  • Ax[inout] first component of the vector A

  • Ay[inout] second component of the vector A

  • Az[inout] third component of the vector A

  • A1x[out] first component of the vector A

  • A1y[out] second component of the vector A

  • A1z[out] third component of the vector A

  • A2x[out] first component of the vector A

  • A2y[out] second component of the vector A

  • A2z[out] third component of the vector A

Returns:

0 if success, 1 if there is a problem

static inline int orthoBaseFromVector(double *Ax, double *Ay, double *Az, double *A1x, double *A1y, double *A1z, double *A2x, double *A2y, double *A2z)#
static inline WARN_RESULT_IGNORED int solve_3x3_gepp (const double *restrict a, double *restrict b)

solve Ax = b by partial pivoting Gaussian elimination.

This function is 10 to 20 times faster than calling LAPACK (tested with netlib).

Parameters:
  • a – column-major matrix (not modified)

  • b[inout] on input, the right-hand side; on output the solution x

Returns:

0 if ok, otherwise the column where no pivot could be selected

static void swap_row(double *a, double *b, int r1, int r2, int n)#
static inline void solve_nxn_gepp(int n, double *a, double *b, double *x)#
static inline WARN_RESULT_IGNORED int eig_3x3 (double *restrict a, double *restrict b, double *restrict eig)

Computation of the eigenvalues of a symmetric 3x3 real matrix.

Parameters:
  • a – symmetric column-major matrix (not modified)

  • b – a 3x3 work matrix

  • eig[inout] eigenvalie in decreasing order

Returns:

0 all the time