Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
math.h File Reference
#include <stddef.h>
#include <math.h>
#include <stdint.h>
#include "system/openmp.h"
#include "system/simd.h"
+ Include dependency graph for math.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NORM_MIN   1.52587890625e-05f
 
#define M_LN10   2.30258509299404568402
 
#define M_PI   3.14159265358979323846
 
#define M_PI_F   3.14159265358979324f
 
#define DT_M_PI_F   (3.14159265358979324f)
 
#define DT_M_PI   (3.14159265358979324)
 
#define DT_M_LN2f   (0.6931471805599453f)
 
#define DT_FMA(x, y, z)   ((x) * (y) + (z))
 
#define PHI   1.61803398874989479F
 
#define INVPHI   0.61803398874989479F
 
#define CLAMPS(A, L, H)   ((A) > (L) ? ((A) < (H) ? (A) : (H)) : (L))
 
#define CLIP(x)   (((x) >= 0) ? ((x) <= 1 ? (x) : 1) : 0)
 
#define MM_CLIP_PS(X)   (_mm_min_ps(_mm_max_ps((X), _mm_setzero_ps()), _mm_set1_ps(1.0)))
 
#define LCLIP(x)   ((x < 0) ? 0.0 : (x > 100.0) ? 100.0 : x)
 
#define CLAMPF(a, mn, mx)   ((a) >= (mn) ? ((a) <= (mx) ? (a) : (mx)) : (mn))
 

Functions

static float clamp_range_f (const float x, const float low, const float high)
 
static float Kahan_sum (const float m, float *const __restrict__ c, const float add)
 
static float Log2 (float x)
 
static float Log2Thres (float x, float Thres)
 
static float fastlog2 (float x)
 
static float fastlog (float x)
 
static void mat3mulv (float *const __restrict__ dest, const float *const mat, const float *const __restrict__ v)
 
static void mat3mul (float *const __restrict__ dest, const float *const __restrict__ m1, const float *const __restrict__ m2)
 
static void mul_mat_vec_2 (const float *m, const float *p, float *o)
 
 __OMP_DECLARE_SIMD__ (uniform(v_2) aligned(v_1, v_2:16)) static inline float scalar_product(const dt_aligned_pixel_t v_1
 
 __OMP_SIMD__ (aligned(v_1, v_2:16) reduction(+:acc)) for(size_t c=0
 
static void dt_fast_expf_4wide (const float x[4], float result[4])
 
static float dt_fast_mexp2f (const float x)
 
static float fast_mexp2f (const float x)
 
static float ceil_fast (float x)
 
static float sinf_fast (float t)
 
static int ipow (int base, int exp)
 Fast integer power, computing base^exp.
 
static void dt_vector_sin (const dt_aligned_pixel_t arg, dt_aligned_pixel_t sine)
 
static float f_inv_sqrtf (const float x)
 

Variables

const dt_aligned_pixel_t v_2
 
c< 3;c++) acc+=v_1[c] *v_2[c];return acc;}static inline float sqf(const float x){ return x *x;}static inline float euclidean_norm(const dt_aligned_pixel_t vector){ return fmaxf(sqrtf(sqf(vector[0])+sqf(vector[1])+sqf(vector[2])), 1.52587890625e-05f);}static inline void downscale_vector(dt_aligned_pixel_t vector, const float scaling){ const int valid=(scaling > 1.52587890625e-05f) &&!isnan(scaling);for(size_t c=0;c< 3;c++) vector[c]=(valid) ? vector[c]/(scaling+1.52587890625e-05f) :vector[c]/1.52587890625e-05f ;}static inline void upscale_vector(dt_aligned_pixel_t vector, const float scaling){ const int valid=(scaling > 1.52587890625e-05f) &&!isnan(scaling);for(size_t c=0;c< 3;c++) vector[c]=(valid) ? vector[c] *(scaling+1.52587890625e-05f) :vector[c] *1.52587890625e-05f ;}static inline float dt_log2f(const float f){ return logf(f)/logf(2.0f);}union float_int { float f;int k;};static inline float dt_fast_hypotf(const float x, const float y){ return sqrtf(x *x+y *y);}static inline float dt_fast_expf(const float x){ const int i1=0x3f800000u;const int i2=0x402DF854u;const int k0=i1+x *(i2 - i1);union float_int u;u.k=k0 > k0
 
returnf
 

Macro Definition Documentation

◆ CLAMPF

#define CLAMPF (   a,
  mn,
  mx 
)    ((a) >= (mn) ? ((a) <= (mx) ? (a) : (mx)) : (mn))

Definition at line 91 of file math.h.

◆ CLAMPS

#define CLAMPS (   A,
  L,
  H 
)    ((A) > (L) ? ((A) < (H) ? (A) : (H)) : (L))

Definition at line 78 of file math.h.

◆ CLIP

#define CLIP (   x)    (((x) >= 0) ? ((x) <= 1 ? (x) : 1) : 0)

Definition at line 83 of file math.h.

◆ DT_FMA

#define DT_FMA (   x,
  y,
 
)    ((x) * (y) + (z))

Definition at line 64 of file math.h.

◆ DT_M_LN2f

#define DT_M_LN2f   (0.6931471805599453f)

Definition at line 57 of file math.h.

◆ DT_M_PI

#define DT_M_PI   (3.14159265358979324)

Definition at line 55 of file math.h.

◆ DT_M_PI_F

#define DT_M_PI_F   (3.14159265358979324f)

Definition at line 54 of file math.h.

◆ INVPHI

#define INVPHI   0.61803398874989479F

Definition at line 74 of file math.h.

◆ LCLIP

#define LCLIP (   x)    ((x < 0) ? 0.0 : (x > 100.0) ? 100.0 : x)

Definition at line 87 of file math.h.

◆ M_LN10

#define M_LN10   2.30258509299404568402

ln(10)

Definition at line 42 of file math.h.

◆ M_PI

#define M_PI   3.14159265358979323846

PI

Definition at line 47 of file math.h.

◆ M_PI_F

#define M_PI_F   3.14159265358979324f

Definition at line 50 of file math.h.

◆ MM_CLIP_PS

#define MM_CLIP_PS (   X)    (_mm_min_ps(_mm_max_ps((X), _mm_setzero_ps()), _mm_set1_ps(1.0)))

Definition at line 84 of file math.h.

◆ NORM_MIN

#define NORM_MIN   1.52587890625e-05f

Definition at line 37 of file math.h.

◆ PHI

#define PHI   1.61803398874989479F

Definition at line 69 of file math.h.

Function Documentation

◆ __OMP_DECLARE_SIMD__()

__OMP_DECLARE_SIMD__ ( uniform(v_2) aligned(v_1, v_2:16)  ) const

◆ __OMP_SIMD__()

__OMP_SIMD__ ( aligned(v_1, v_2:16) reduction(+:acc)  )
pure virtual

◆ ceil_fast()

static float ceil_fast ( float  x)
inlinestatic

Compute ceil value of a float

Remarks
Avoid libc ceil for now. Maybe we'll revert to libc later.
Parameters
xValue to ceil
Returns
ceil value

Definition at line 324 of file math.h.

References x.

Referenced by _compute_downsampling_kernel(), and _prepare_resampling_plan().

◆ clamp_range_f()

static float clamp_range_f ( const float  x,
const float  low,
const float  high 
)
inlinestatic

Definition at line 98 of file math.h.

References x.

Referenced by _blendop_blendif_boost_factor_callback(), and _develop_blend_process_mask_tone_curve().

◆ dt_fast_expf_4wide()

static void dt_fast_expf_4wide ( const float  x[4],
float  result[4] 
)
inlinestatic

Definition at line 269 of file math.h.

References __OMP_SIMD__, k0, and x.

◆ dt_fast_mexp2f()

static float dt_fast_mexp2f ( const float  x)
inlinestatic

Definition at line 290 of file math.h.

References f, i, k, k0, and x.

Referenced by gh().

◆ dt_vector_sin()

static void dt_vector_sin ( const dt_aligned_pixel_t  arg,
dt_aligned_pixel_t  sine 
)
inlinestatic

Compute approximate sines, four at a time. This function behaves correctly for the range [-pi pi] only. It has the following properties:

  • It has exact values for 0, pi/2, pi, -pi/2, -pi
  • It has matching derivatives to sine for these same points
  • Its relative error margin is <= 1% iirc
  • It computational cost is 5 mults + 3 adds + 2 abs
Parameters
argRadian parameters
Returns
sine: guess what

Definition at line 447 of file math.h.

References for_four_channels, M_PI_F, and p.

◆ f_inv_sqrtf()

static float f_inv_sqrtf ( const float  x)
inlinestatic

Fast inverse square root approximation, based on the famous Quake III algorithm, with a Newton-Raphson iteration for improved accuracy. approximation of 1/sqrtf() for x > 0.0f, with a maximum relative error of ~0.0005% at 1.0f

Definition at line 476 of file math.h.

References f, i, and x.

Referenced by _dt_masks_find_best_attachment_point().

◆ fast_mexp2f()

static float fast_mexp2f ( const float  x)
inlinestatic

Definition at line 306 of file math.h.

References f, i, k, k0, and x.

Referenced by dn_weight().

◆ fastlog()

static float fastlog ( float  x)
inlinestatic

Definition at line 140 of file math.h.

References DT_M_LN2f, fastlog2(), and x.

Referenced by kernel().

◆ fastlog2()

static float fastlog2 ( float  x)
inlinestatic

Definition at line 124 of file math.h.

References f, i, and x.

Referenced by fastlog(), and process().

◆ ipow()

static int ipow ( int  base,
int  exp 
)
inlinestatic

Fast integer power, computing base^exp.

Parameters
base
exp
Returns
int

Definition at line 415 of file math.h.

Referenced by _bh_round_to_n_digits(), _bh_slider_get_min_step(), _slider_add_step(), and dt_bauhaus_slider_set_normalized().

◆ Kahan_sum()

static float Kahan_sum ( const float  m,
float *const __restrict__  c,
const float  add 
)
inlinestatic

Definition at line 105 of file math.h.

References m.

Referenced by blur_vertical_1wide_Kahan().

◆ Log2()

static float Log2 ( float  x)
inlinestatic

Definition at line 113 of file math.h.

References DT_M_LN2f, and x.

Referenced by apply_auto_grey(), dt_iop_tonecurve_draw(), and grey_point_source_callback().

◆ Log2Thres()

static float Log2Thres ( float  x,
float  Thres 
)
inlinestatic

◆ mat3mul()

static void mat3mul ( float *const __restrict__  dest,
const float *const __restrict__  m1,
const float *const __restrict__  m2 
)
inlinestatic

Definition at line 163 of file math.h.

References i, k, and x.

Referenced by _exif_decode_exif_data(), and homography().

◆ mat3mulv()

static void mat3mulv ( float *const __restrict__  dest,
const float *const  mat,
const float *const __restrict__  v 
)
inlinestatic

◆ mul_mat_vec_2()

static void mul_mat_vec_2 ( const float *  m,
const float *  p,
float *  o 
)
inlinestatic

Definition at line 178 of file math.h.

References m, and p.

Referenced by backtransform(), backtransform(), transform(), and transform().

◆ sinf_fast()

static float sinf_fast ( float  t)
inlinestatic

Compute an approximate sine. This function behaves correctly for the range [-pi pi] only. It has the following properties:

  • It has exact values for 0, pi/2, pi, -pi/2, -pi
  • It has matching derivatives to sine for these same points
  • Its relative error margin is <= 1% iirc
  • It computational cost is 5 mults + 3 adds + 2 abs
Parameters
tRadian parameter
Returns
guess what

Definition at line 360 of file math.h.

References M_PI, M_PI_F, p, and t.

Variable Documentation

◆ f

return u f

Definition at line 266 of file math.h.

Referenced by f_inv_sqrtf(), fast_mexp2f(), and fastlog2().

◆ k0

c< 3; c++) acc += v_1[c] * v_2[c]; return acc;}static inline float sqf(const float x){ return x * x;}static inline float euclidean_norm(const dt_aligned_pixel_t vector){ return fmaxf(sqrtf(sqf(vector[0]) + sqf(vector[1]) + sqf(vector[2])), 1.52587890625e-05f );}static inline void downscale_vector(dt_aligned_pixel_t vector, const float scaling){ const int valid = (scaling > 1.52587890625e-05f ) && !isnan(scaling); for(size_t c = 0; c < 3; c++) vector[c] = (valid) ? vector[c] / (scaling + 1.52587890625e-05f ) : vector[c] / 1.52587890625e-05f ;}static inline void upscale_vector(dt_aligned_pixel_t vector, const float scaling){ const int valid = (scaling > 1.52587890625e-05f ) && !isnan(scaling); for(size_t c = 0; c < 3; c++) vector[c] = (valid) ? vector[c] * (scaling + 1.52587890625e-05f ) : vector[c] * 1.52587890625e-05f ;}static inline float dt_log2f(const float f){ return logf(f) / logf(2.0f);}union float_int { float f; int k;};static inline float dt_fast_hypotf(const float x, const float y){ return sqrtf(x * x + y * y);}static inline float dt_fast_expf(const float x){ const int i1 = 0x3f800000u; const int i2 = 0x402DF854u; const int k0 = i1 + x * (i2 - i1); union float_int u; u.k = k0 > k0

Definition at line 265 of file math.h.

Referenced by dt_fast_expf_4wide(), dt_fast_mexp2f(), dt_hash(), and fast_mexp2f().

◆ v_2

const dt_aligned_pixel_t v_2
Initial value:
{
float acc = 0.f

Definition at line 185 of file math.h.