17 #ifndef __UTIL_MATH_MATRIX_H__
18 #define __UTIL_MATH_MATRIX_H__
22 #define MAT(A, size, row, col) A[(row) * (size) + (col)]
26 # define MATS(A, n, r, c, s) A[((r) * (n) + (c)) * (s)]
28 # define MATHS(A, r, c, s) A[((r) * ((r) + 1) / 2 + (c)) * (s)]
29 # define VECS(V, i, s) V[(i) * (s)]
31 # define MATS(A, n, r, c, s) MAT(A, n, r, c)
32 # define MATHS(A, r, c, s) A[(r) * ((r) + 1) / 2 + (c)]
33 # define VECS(V, i, s) V[i]
40 for (
int i = 0; i < n; i++) {
47 for (
int row = 0; row < n; row++) {
58 for (
int i = 0; i < n; i++) {
65 for (
int i = 0; i < n; i++) {
75 for (
int i = 0; i < n; i++) {
76 a[i * astride] *= b[i];
82 for (
int i = 0; i < n; i++) {
89 for (
int i = 0; i < n; i++) {
90 a[i] =
max(
a[i], b[i]);
96 for (
int i = 0; i < n; i++) {
104 for (
int i = 0; i < n; i++) {
121 for (
int row = 0; row < n; row++) {
133 for (
int row = 0; row < n; row++) {
145 for (
int row = 0; row < n; row++) {
157 for (
int row = 0; row < n; row++) {
167 for (
int i = 0; i < n; i++) {
168 for (
int j = 0; j < i; j++) {
183 for (
int row = 0; row < n; row++) {
186 for (
int k = 0; k <
col; k++) {
190 sum_col =
sqrtf(
max(sum_col, 0.0f));
223 for (
int row = 0; row < n; row++) {
231 for (
int row = n - 1; row >= 0; row--) {
252 const float singular_epsilon = 1e-9f;
254 for (
int row = 0; row < n; row++) {
256 MATS(
V, n, row,
col, v_stride) = (
col == row) ? 1.0f : 0.0f;
260 for (
int sweep = 0; sweep < 8; sweep++) {
261 float off_diagonal = 0.0f;
262 for (
int row = 1; row < n; row++) {
267 if (off_diagonal < 1e-7f) {
276 float threshold = 0.2f * off_diagonal / (n * n);
278 for (
int row = 1; row < n; row++) {
286 if (sweep > 3 && abs_element <= singular_epsilon *
fabsf(
MAT(
A, n, row, row)) &&
298 if (sweep < 3 && (abs_element < threshold)) {
309 if (abs_element > singular_epsilon *
fabsf(singular_diff)) {
310 float cot_2phi = 0.5f * singular_diff /
element;
311 ratio = 1.0f / (
fabsf(cot_2phi) +
sqrtf(1.0f + cot_2phi * cot_2phi));
316 ratio =
element / singular_diff;
319 float c = 1.0f /
sqrtf(1.0f + ratio * ratio);
323 float tan_phi_2 = s / (1.0f +
c);
326 float singular_delta = ratio *
element;
327 MAT(
A, n, row, row) += singular_delta;
334 #define ROT(M, r1, c1, r2, c2, stride) \
336 float M1 = MATS(M, n, r1, c1, stride); \
337 float M2 = MATS(M, n, r2, c2, stride); \
338 MATS(M, n, r1, c1, stride) -= s * (M2 + tan_phi_2 * M1); \
339 MATS(M, n, r2, c2, stride) += s * (M1 - tan_phi_2 * M2); \
344 for (
int i = 0; i <
col; i++)
346 for (
int i =
col + 1; i < row; i++)
348 for (
int i = row + 1; i < n; i++)
351 for (
int i = 0; i < n; i++)
352 ROT(
V,
col, i, row, i, v_stride);
359 for (
int i = 0; i < n - 1; i++) {
360 float v =
MAT(
A, n, i, i);
362 for (
int j = i; j < n; j++) {
363 if (
MAT(
A, n, j, j) >=
v) {
373 for (
int j = 0; j < n; j++) {
374 float v =
MATS(
V, n, i, j, v_stride);
375 MATS(
V, n, i, j, v_stride) =
MATS(
V, n, k, j, v_stride);
376 MATS(
V, n, k, j, v_stride) =
v;
382 #ifdef __KERNEL_SSE3__
385 for (
int i = 0; i < n; i++) {
392 for (
int row = 0; row < n; row++) {
406 for (
int row = 0; row < n; row++) {
415 for (
int i = 0; i < n; i++) {
422 for (
int i = 0; i < n; i++) {
429 for (
int i = 0; i < n; i++) {
430 a[i] =
max(
a[i], b[i]);
436 for (
int row = 0; row < n; row++) {
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
ATTR_WARN_UNUSED_RESULT const void * element
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static T sum(const btAlignedObjectArray< T > &items)
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define make_float4(x, y, z, w)
#define atomic_add_and_fetch_float(p, x)
__forceinline int reduce_add(const avxi &v)
ccl_device_inline void math_vec3_add(float3 *v, int n, float *x, float3 w)
#define MAT(A, size, row, col)
ccl_device void math_trimatrix_cholesky(ccl_global float *A, int n, int stride)
ccl_device_inline void math_matrix_transpose(ccl_global float *A, int n, int stride)
ccl_device_inline void math_trimatrix_add_diagonal(ccl_global float *A, int n, float val, int stride)
ccl_device_inline void math_vector_add(float *a, const float *ccl_restrict b, int n)
ccl_device_inline void math_matrix_zero(float *A, int n)
#define MATHS(A, r, c, s)
ccl_device_inline void math_vec3_add_strided(ccl_global float3 *v, int n, float *x, float3 w, int stride)
ccl_device_inline void math_vector_zero(float *v, int n)
ccl_device_inline void math_vector_mul_strided(ccl_global float *a, const float *ccl_restrict b, int astride, int n)
#define ROT(M, r1, c1, r2, c2, stride)
ccl_device void math_matrix_jacobi_eigendecomposition(float *A, ccl_global float *V, int n, int v_stride)
ccl_device_inline void math_vector_max(float *a, const float *ccl_restrict b, int n)
ccl_device_inline void math_vector_scale(float *a, float b, int n)
ccl_device_inline void math_matrix_add_gramian(float *A, int n, const float *ccl_restrict v, float weight)
ccl_device_inline void math_trimatrix_add_gramian_strided(ccl_global float *A, int n, const float *ccl_restrict v, float weight, int stride)
ccl_device_inline void math_trimatrix_vec3_solve(ccl_global float *A, ccl_global float3 *y, int n, int stride)
#define MATS(A, n, r, c, s)
ccl_device_inline void math_vector_mul(float *a, const float *ccl_restrict b, int n)
ccl_device_inline void math_trimatrix_add_gramian(ccl_global float *A, int n, const float *ccl_restrict v, float weight)
CCL_NAMESPACE_BEGIN struct View V