NcmUtil

NcmUtil — Miscellaneous utilities.

Functions

gdouble ncm_util_sqrt1px_m1 ()
gdouble ncm_util_ln1pexpx ()
gdouble ncm_util_1pcosx ()
gdouble ncm_util_1mcosx ()
gdouble ncm_util_1psinx ()
gdouble ncm_util_1msinx ()
gdouble ncm_util_cos2x ()
gdouble ncm_cmpdbl ()
gdouble ncm_exprel ()
gdouble ncm_d1exprel ()
gdouble ncm_d2exprel ()
gdouble ncm_d3exprel ()
gdouble ncm_util_sinh1 ()
gdouble ncm_util_sinh3 ()
gdouble ncm_util_sinhx_m_xcoshx_x3 ()
void ncm_util_mln_1mIexpzA_1pIexpmzA ()
gint ncm_cmp ()
void ncm_rational_coarce_double ()
void ncm_mpz_inits ()
void ncm_mpz_clears ()
gboolean ncm_util_cvode_check_flag ()
gboolean ncm_util_cvode_print_stats ()
gchar * ncm_util_basename_fits ()
gchar * ncm_util_function_params ()
gulong ncm_util_fact_size ()
void ncm_util_sleep_ms ()
NcmComplex * ncm_complex_new ()
NcmComplex * ncm_complex_ref ()
NcmComplex * ncm_complex_dup ()
void ncm_complex_free ()
void ncm_complex_clear ()
void ncm_complex_set ()
void ncm_complex_set_zero ()
gdouble ncm_complex_Re ()
gdouble ncm_complex_Im ()
void ncm_complex_res_add_mul_real ()
void ncm_complex_res_add_mul ()
void ncm_complex_mul_real ()
void ncm_complex_res_mul ()
gdouble ncm_util_smooth_trans ()
void ncm_util_smooth_trans_get_theta ()
gdouble ncm_util_position_angle ()
gdouble ncm_util_great_circle_distance ()
#define ncm_acb_get_complex()
#define ncm_util_exp10()
#define NCM_GARRAY_MEMCPY()
#define NCM_GARRAY_DUP()
#define ncm_assert_cmpdouble()
#define ncm_assert_cmpdouble_e()
#define NCM_TEST_GSL_RESULT()
#define NCM_COMPLEX_PTR()
#define ncm_g_string_clear()
#define NCM_UNUSED()
#define NCM_TEST_FREE()
#define NCM_TEST_FAIL()
#define NCM_TEST_PASS()
#define NCM_CVODE_CHECK()

Types and Values

Object Hierarchy

    GBoxed
    ╰── NcmComplex

Description

Miscellaneous utility functions, macros and objects.

Functions

ncm_util_sqrt1px_m1 ()

gdouble
ncm_util_sqrt1px_m1 (const gdouble x);

Calculates $\sqrt{1+x}-1$ using the appropriated expression to avoid round-off when $x \approx 0$.

Parameters

x

a real number $>-1$

 

Returns

$\sqrt{1+x}-1$.


ncm_util_ln1pexpx ()

gdouble
ncm_util_ln1pexpx (const gdouble x);

Calculates $\ln[1+\exp(x)]$.

Parameters

x

a real number $x$

 

Returns

$\ln[1+\exp(x)]$.


ncm_util_1pcosx ()

gdouble
ncm_util_1pcosx (const gdouble sinx,
                 const gdouble cosx);

Calculates $1 + \cos(x)$ using the appropriated taylor series when $\cos(x) \approx -1$.

Parameters

sinx

a real number $\sin(x)$

 

cosx

a real number $\cos(x)$

 

Returns

$1 + \cos(x)$.


ncm_util_1mcosx ()

gdouble
ncm_util_1mcosx (const gdouble sinx,
                 const gdouble cosx);

Calculates $1 - \cos(x)$ using the appropriated taylor series when $\cos(x) \approx 1$.

Parameters

sinx

a real number $\sin(x)$

 

cosx

a real number $\cos(x)$

 

Returns

$1 - \cos(x)$.


ncm_util_1psinx ()

gdouble
ncm_util_1psinx (const gdouble sinx,
                 const gdouble cosx);

Calculates $1 + \sin(x)$ using the appropriated taylor series when $\sin(x) \approx -1$.

Parameters

sinx

a real number $\sin(x)$

 

cosx

a real number $\cos(x)$

 

Returns

$1 + \sin(x)$.


ncm_util_1msinx ()

gdouble
ncm_util_1msinx (const gdouble sinx,
                 const gdouble cosx);

Calculates $1 - \sin(x)$ using the appropriated taylor series when $\sin(x) \approx 1$.

Parameters

sinx

a real number $\sin(x)$

 

cosx

a real number $\cos(x)$

 

Returns

$1 - \sin(x)$.


ncm_util_cos2x ()

gdouble
ncm_util_cos2x (const gdouble sinx,
                const gdouble cosx);

Calculates $\cos(2x)$ using the appropriated taylor series when $\sin(x) \approx 1$.

Parameters

sinx

a real number $\sin(x)$

 

cosx

a real number $\cos(x)$

 

Returns

$1 - \sin(x)$.


ncm_cmpdbl ()

gdouble
ncm_cmpdbl (const gdouble x,
            const gdouble y);

Compares x and y and returns the difference between them relative to their mean.

Parameters

x

a double.

 

y

a double.

 

Returns

$\frac{2(x-y)}{x+y}$.


ncm_exprel ()

gdouble
ncm_exprel (const gdouble x);

Computes the relative exponential $(\exp(x) - 1)/x$.

Parameters

x

a double

 

Returns

$(\exp(x) - 1)/x$.


ncm_d1exprel ()

gdouble
ncm_d1exprel (const gdouble x);

Computes the first derivative of the relative exponential $(\exp(x) - 1)/x$.

Parameters

x

a double

 

Returns

first derivative of $(\exp(x) - 1)/x$.


ncm_d2exprel ()

gdouble
ncm_d2exprel (const gdouble x);

Computes the second derivative of the relative exponential $(\exp(x) - 1)/x$.

Parameters

x

a double

 

Returns

second derivative of $(\exp(x) - 1)/x$.


ncm_d3exprel ()

gdouble
ncm_d3exprel (const gdouble x);

Computes the third derivative of the relative exponential $(\exp(x) - 1)/x$.

Parameters

x

a double

 

Returns

third derivative of $(\exp(x) - 1)/x$.


ncm_util_sinh1 ()

gdouble
ncm_util_sinh1 (const gdouble x);

Computes $\frac{\sinh(x)}{x}$. For small values of x the taylor series is used. For large values of x the value is computed using the standard library function.

Parameters

x

a double

 

Returns

$\frac{\sinh(x)}{x}$


ncm_util_sinh3 ()

gdouble
ncm_util_sinh3 (const gdouble x);

Parameters

x

a double

 

Returns

$\frac{\sinh(x)-x}{x^3/3!}$


ncm_util_sinhx_m_xcoshx_x3 ()

gdouble
ncm_util_sinhx_m_xcoshx_x3 (const gdouble x);

Parameters

x

a double

 

Returns

$\frac{\sinh(x)-x\cosh(x)}{x^3}$


ncm_util_mln_1mIexpzA_1pIexpmzA ()

void
ncm_util_mln_1mIexpzA_1pIexpmzA (const gdouble rho,
                                 const gdouble theta,
                                 const gdouble A,
                                 gdouble *rho1,
                                 gdouble *theta1);

Computes $$z_1 = z - \ln\left(\frac{1-i e^{+z} A}{1+i e^{-z} A}\right),$$ where $z = \rho + i\theta$ and return the new $z_1 = \rho_1 + i\theta_1$ into rho1 and $\theta1$.

Parameters

rho

a double $\rho$

 

theta

a double $\theta$

 

A

a double $A$

 

rho1

a double $\rho_1$.

[out]

theta1

a double $\theta_1$.

[out]

ncm_cmp ()

gint
ncm_cmp (gdouble x,
         gdouble y,
         const gdouble reltol,
         const gdouble abstol);

Compare x and y and return -1 if x < y, 0 if x == y and 1 if x > y, all comparisons are done with precision prec .

Parameters

x

a double

 

y

a double

 

reltol

relative precision

 

abstol

the absolute precision

 

Returns

-1, 0, 1.


ncm_rational_coarce_double ()

void
ncm_rational_coarce_double (gdouble x,
                            mpq_t q);

Computes a rational approximation for x and stores the result in q .

[skip]

Parameters

x

a double

 

q

a mpq_t to store the result

 

ncm_mpz_inits ()

void
ncm_mpz_inits (mpz_t z,
               ...);

Initializes z and all the mpz_t in the list.

[skip]

Parameters

z

a mpz_t to initialize

 

...

a null terminated list of mpz_t to initialize

 

ncm_mpz_clears ()

void
ncm_mpz_clears (mpz_t z,
                ...);

Clears z and all the mpz_t in the list.

[skip]

Parameters

z

a mpz_t to clear

 

...

a null terminated list of mpz_t to clear

 

ncm_util_cvode_check_flag ()

gboolean
ncm_util_cvode_check_flag (gpointer flagvalue,
                           const gchar *funcname,
                           gint opt);

Checks the CVode flag value and prints a message if an error occured.

Parameters

flagvalue

pointer to flag value

 

funcname

cvode function name

 

opt

option

 

Returns

TRUE if no error occured, FALSE otherwise.


ncm_util_cvode_print_stats ()

gboolean
ncm_util_cvode_print_stats (gpointer cvode);

Prints the statistics of the CVodeMem object cvode .

Parameters

cvode

a CVodeMem

 

Returns

TRUE.


ncm_util_basename_fits ()

gchar *
ncm_util_basename_fits (const gchar *fits_filename);

Extracts the extension .fits or .fit from fits_filename and returns the prefix. If the extension is not found a copy of fits_filename is returned.

Parameters

fits_filename

a fits filename

 

Returns

prefix of fits_filename .

[transfer full]


ncm_util_function_params ()

gchar *
ncm_util_function_params (const gchar *func,
                          gdouble **x,
                          guint *len);

Extracts the function name and its numerical parameters.

Parameters

func

string representing function and its parameters

 

x

the parameters or NULL if none found.

[out][array][element-type double]

len

number of parameters.

[out caller-allocates]

Returns

function name or NULL if it fails.

[transfer full]


ncm_util_fact_size ()

gulong
ncm_util_fact_size (const gulong n);

Calculate the smallest factorization of n such that $n_f = 2^\mu \times 3^\nu \times 5^\alpha \times 7^\beta$ and $n_f \geq n$.

This functions is useful to find a fft size such that fftw can optimized it more easily.

Parameters

n

a unsigned long integer

 

Returns

$n_f$


ncm_util_sleep_ms ()

void
ncm_util_sleep_ms (gint milliseconds);

Suspend the thread execution for milliseconds .

Parameters

milliseconds

sleep time in milliseconds

 

ncm_complex_new ()

NcmComplex *
ncm_complex_new (void);

Allocates a new complex number.

Returns

a new NcmComplex.

[transfer full]


ncm_complex_ref ()

NcmComplex *
ncm_complex_ref (NcmComplex *c);

ncm_complex_dup ()

NcmComplex *
ncm_complex_dup (NcmComplex *c);

Allocates a new complex number and copy the contents of c to it.

Parameters

c

a NcmComplex

 

Returns

a new NcmComplex.

[transfer full]


ncm_complex_free ()

void
ncm_complex_free (NcmComplex *c);

Frees c , it should not be used on a statically allocated NcmComplex.

Parameters

c

a NcmComplex

 

ncm_complex_clear ()

void
ncm_complex_clear (NcmComplex **c);

Frees *c and sets *c to NULL, it should not be used on a statically allocated NcmComplex.

Parameters

c

a NcmComplex

 

ncm_complex_set ()

void
ncm_complex_set (NcmComplex *c,
                 const gdouble a,
                 const gdouble b);

Sets c to $a + I b$.

Parameters

c

a NcmComplex

 

a

the real part $a$

 

b

the imaginary part $b$

 

ncm_complex_set_zero ()

void
ncm_complex_set_zero (NcmComplex *c);

Sets c to $0 + I 0$.

Parameters

c

a NcmComplex

 

ncm_complex_Re ()

gdouble
ncm_complex_Re (NcmComplex *c);

Returns the real part of c .

Parameters

c

a NcmComplex

 

Returns

Re$(c)$.


ncm_complex_Im ()

gdouble
ncm_complex_Im (NcmComplex *c);

Returns the imaginary part of c .

Parameters

c

a NcmComplex

 

Returns

Im$(c)$.


ncm_complex_res_add_mul_real ()

void
ncm_complex_res_add_mul_real (NcmComplex * restrict c1,
                              const NcmComplex * restrict c2,
                              const gdouble v);

Computes c1 = c1 + c2 * v , assuming that c1 and c2 are different.

Parameters

c1

a NcmComplex

 

c2

a NcmComplex

 

v

a gdouble

 

ncm_complex_res_add_mul ()

void
ncm_complex_res_add_mul (NcmComplex * restrict c1,
                         const NcmComplex * restrict c2,
                         const NcmComplex * restrict c3);

Computes c1 = c1 + c2 * c3 , assuming that c1 and c2 are different.

Parameters

c1

a NcmComplex

 

c2

a NcmComplex

 

c3

NcmComplex

 

ncm_complex_mul_real ()

void
ncm_complex_mul_real (NcmComplex *c,
                      const gdouble v);

Computes c1 = c1 * v .

Parameters

c

a NcmComplex

 

v

a gdouble

 

ncm_complex_res_mul ()

void
ncm_complex_res_mul (NcmComplex * restrict c1,
                     const NcmComplex * restrict c2);

Computes c1 = c1 * c2 , assuming that c1 and c2 are different.

Parameters

c1

a NcmComplex

 

c2

a NcmComplex

 

ncm_util_smooth_trans ()

gdouble
ncm_util_smooth_trans (gdouble f0,
                       gdouble f1,
                       gdouble z0,
                       gdouble dz,
                       gdouble z);

ncm_util_smooth_trans_get_theta ()

void
ncm_util_smooth_trans_get_theta (gdouble z0,
                                 gdouble dz,
                                 gdouble z,
                                 gdouble *theta0,
                                 gdouble *theta1);

ncm_util_position_angle ()

gdouble
ncm_util_position_angle (gdouble ra1,
                         gdouble dec1,
                         gdouble ra2,
                         gdouble dec2);

Computes the on-sky position angle (East of North) between object1 (ra1 , dec1 ) and object2 (ra2 , dec2). The input coordinates ((ra1 , dec1 ), (ra2 , dec2 )) must be given in decimal degrees.

Parameters

ra1

Right ascension of object 1

 

dec1

Declination of object 1

 

ra2

Right ascension of object 2

 

dec2

Declination of object 2

 

Returns

the position angle in radians


ncm_util_great_circle_distance ()

gdouble
ncm_util_great_circle_distance (gdouble ra1,
                                gdouble dec1,
                                gdouble ra2,
                                gdouble dec2);

Compute the great circle distance (or separation, as defined in astropy) between poistion 1 (ra1 , dec1 ) and position 2 (ra2 , dec2 ). See Great-circle distance, in particular the Vincenty equation (implemented here). The input coordinates ((ra1 , dec1 ), (ra2 , dec2 )) must be given in decimal degrees.

Parameters

ra1

Right ascension of object 1

 

dec1

Declination of object 1

 

ra2

Right ascension of object 2

 

dec2

Declination of object 2

 

Returns

the great circle distance in decimal degrees


ncm_acb_get_complex()

#define ncm_acb_get_complex(z) (arf_get_d (arb_midref (acb_realref (z)), ARF_RND_NEAR) + I * arf_get_d (arb_midref (acb_imagref (z)), ARF_RND_NEAR))

ncm_util_exp10()

#define ncm_util_exp10(x) (exp ((x) * M_LN10))

NCM_GARRAY_MEMCPY()

#define             NCM_GARRAY_MEMCPY(dest, src)

NCM_GARRAY_DUP()

#define             NCM_GARRAY_DUP(dest, src)

ncm_assert_cmpdouble()

#define             ncm_assert_cmpdouble(n1, cmp, n2)

ncm_assert_cmpdouble_e()

#define             ncm_assert_cmpdouble_e(n1, cmp, n2, epsilon, abstol)

NCM_TEST_GSL_RESULT()

#define             NCM_TEST_GSL_RESULT(func, ret)

NCM_COMPLEX_PTR()

#define NCM_COMPLEX_PTR(p) ((NcmComplex **) (p))

ncm_g_string_clear()

#define             ncm_g_string_clear(s)

NCM_UNUSED()

#define NCM_UNUSED(x) (void) (x)

NCM_TEST_FREE()

#define             NCM_TEST_FREE(cmd, obj)

NCM_TEST_FAIL()

#define             NCM_TEST_FAIL(cmd)

NCM_TEST_PASS()

#define             NCM_TEST_PASS(cmd)

NCM_CVODE_CHECK()

#define             NCM_CVODE_CHECK(chk, name, val, ret)

Types and Values

NCM_COMPLEX_ZERO

#define             NCM_COMPLEX_ZERO