FFmpeg
Loading...
Searching...
No Matches
utils.h File Reference

Utility functions for checkasm tests. More...

#include <stdint.h>
#include "checkasm/attributes.h"

Go to the source code of this file.

Data Structures

struct  CheckasmDist
 Describes a normal (Gaussian) distribution. More...
 

Macros

#define checkasm_dist_standard   ((CheckasmDist) { 0.0, 1.0 })
 Standard normal distribution (mean=0, stddev=1)
 
#define CLEAR_BUF(buf)
 Clear a fixed size buffer (convenience macro)
 
#define RANDOMIZE_BUF(buf)
 Fill a fixed size buffer with random data (convenience macro)
 
#define INITIALIZE_BUF(buf)
 Fill a fixed size buffer with pathological test data (convenience macro)
 
#define float_near_ulp   checkasm_float_near_ulp
 
#define float_near_abs_eps   checkasm_float_near_abs_eps
 
#define float_near_abs_eps_ulp   checkasm_float_near_abs_eps_ulp
 
#define float_near_ulp_array   checkasm_float_near_ulp_array
 
#define float_near_abs_eps_array   checkasm_float_near_abs_eps_array
 
#define float_near_abs_eps_array_ulp   checkasm_float_near_abs_eps_array_ulp
 
#define double_near_abs_eps   checkasm_double_near_abs_eps
 
#define double_near_abs_eps_array   checkasm_double_near_abs_eps_array
 
#define CHECKASM_ALIGN(x)
 Declare a variable with platform-specific alignment requirements.
 
#define DECL_CHECK_FUNC(NAME, TYPE)
 
#define DECL_CHECKASM_CHECK_FUNC(type)
 
#define checkasm_check_impl2(type)
 
#define checkasm_check_impl(type)
 
#define checkasm_check1(type, ...)
 
#define checkasm_check2(type, ...)
 
#define checkasm_check2d(type, ...)
 Compare two 2D buffers and fail test if different.
 
#define checkasm_check2d_padded(type, ...)
 Compare two 2D buffers, including padding regions (detect over-write)
 
#define BUF_RECT(type, name, w, h)
 
#define CLEAR_BUF_RECT(name)
 Clear a rectangular buffer (including padding)
 
#define INITIALIZE_BUF_RECT(name)
 Initialize a rectangular buffer (including padding) with pathological values.
 
#define RANDOMIZE_BUF_RECT(name)
 Randomize a rectangular buffer (including padding)
 
#define checkasm_check_rect(rect1, ...)
 Compare two rectangular buffers.
 
#define checkasm_check_rect_padded(rect1, ...)
 Compare two rectangular buffers including padding.
 
#define checkasm_check_rect_padded_align(rect1, ...)
 Compare two rectangular buffers, with custom alignment (over-write)
 
#define CHECK_BUF_RECT(buf1, buf2, w, h)
 Compare two rectangular buffers (convenience macro)
 

Functions

CHECKASM_API int checkasm_rand (void)
 Generate a random non-negative integer.
 
CHECKASM_API double checkasm_randf (void)
 Generate a random double-precision floating-point number.
 
CHECKASM_API uint8_t checkasm_rand_uint8 (void)
 Generate a random 8-bit unsigned integer.
 
CHECKASM_API uint16_t checkasm_rand_uint16 (void)
 Generate a random 16-bit unsigned integer.
 
CHECKASM_API uint32_t checkasm_rand_uint32 (void)
 Generate a random 32-bit unsigned integer.
 
CHECKASM_API uint64_t checkasm_rand_uint64 (void)
 Generate a random 64-bit unsigned integer.
 
CHECKASM_API int8_t checkasm_rand_int8 (void)
 Generate a random 8-bit signed integer.
 
CHECKASM_API int16_t checkasm_rand_int16 (void)
 Generate a random 16-bit signed integer.
 
CHECKASM_API int32_t checkasm_rand_int32 (void)
 Generate a random 32-bit signed integer.
 
CHECKASM_API int64_t checkasm_rand_int64 (void)
 Generate a random 64-bit signed integer.
 
CHECKASM_API float checkasm_rand_float32 (void)
 Generate a truly random 32-bit float.
 
CHECKASM_API double checkasm_rand_float64 (void)
 Generate a truly random 64-bit float.
 
CHECKASM_API double checkasm_rand_dist (CheckasmDist dist)
 Generate a normally distributed random number.
 
CHECKASM_API double checkasm_rand_norm (void)
 Generate a random number from the standard normal distribution.
 
CHECKASM_API void checkasm_randomize (void *buf, size_t bytes)
 Fill a buffer with uniformly chosen random bytes.
 
CHECKASM_API void checkasm_randomize_mask8 (uint8_t *buf, int width, uint8_t mask)
 Fill a uint8_t buffer with random values chosen uniformly within a mask.
 
CHECKASM_API void checkasm_randomize_mask16 (uint16_t *buf, int width, uint16_t mask)
 Fill a uint16_t buffer with random values chosen uniformly within a mask.
 
CHECKASM_API void checkasm_randomize_range (double *buf, int width, double range)
 Fill a double buffer with random values chosen uniformly below a limit.
 
CHECKASM_API void checkasm_randomize_rangef (float *buf, int width, float range)
 Fill a float buffer with random values chosen uniformly below a limit.
 
CHECKASM_API void checkasm_randomize_interval (double *buf, int width, double low, double high)
 Fill a double buffer with random values chosen uniformly from an interval.
 
CHECKASM_API void checkasm_randomize_intervalf (float *buf, int width, float low, float high)
 Fill a float buffer with random values chosen uniformly from an interval.
 
CHECKASM_API void checkasm_randomize_dist (double *buf, int width, CheckasmDist dist)
 Fill a double buffer with normally distributed random values.
 
CHECKASM_API void checkasm_randomize_distf (float *buf, int width, CheckasmDist dist)
 Fill a float buffer with normally distributed random values.
 
CHECKASM_API void checkasm_randomize_norm (double *buf, int width)
 Fill a double buffer with values from a standard normal distribution.
 
CHECKASM_API void checkasm_randomize_normf (float *buf, int width)
 Fill a float buffer with values from a standard normal distribution.
 
CHECKASM_API void checkasm_clear (void *buf, size_t bytes)
 Clear a buffer to a pre-determined pattern (currently 0xAA)
 
CHECKASM_API void checkasm_clear8 (uint8_t *buf, int width, uint8_t val)
 Fill a uint8_t buffer with a constant value.
 
CHECKASM_API void checkasm_clear16 (uint16_t *buf, int width, uint16_t val)
 Fill a uint16_t buffer with a constant value.
 
CHECKASM_API void checkasm_init (void *buf, size_t bytes)
 Initialize a buffer with pathological test patterns.
 
CHECKASM_API void checkasm_init_mask8 (uint8_t *buf, int width, uint8_t mask)
 Initialize a uint8_t buffer with pathological values within a mask.
 
CHECKASM_API void checkasm_init_mask16 (uint16_t *buf, int width, uint16_t mask)
 Initialize a uint16_t buffer with pathological values within a mask.
 
CHECKASM_API int checkasm_float_near_ulp (float a, float b, unsigned max_ulp)
 Compare floats using ULP (Units in Last Place) tolerance.
 
CHECKASM_API int checkasm_float_near_abs_eps (float a, float b, float eps)
 Compare floats using absolute epsilon tolerance.
 
CHECKASM_API int checkasm_float_near_abs_eps_ulp (float a, float b, float eps, unsigned max_ulp)
 Compare floats using both epsilon and ULP tolerances.
 
CHECKASM_API int checkasm_float_near_ulp_array (const float *a, const float *b, unsigned max_ulp, int len)
 Compare float arrays using ULP tolerance.
 
CHECKASM_API int checkasm_float_near_abs_eps_array (const float *a, const float *b, float eps, int len)
 Compare float arrays using absolute epsilon tolerance.
 
CHECKASM_API int checkasm_float_near_abs_eps_array_ulp (const float *a, const float *b, float eps, unsigned max_ulp, int len)
 Compare float arrays using both epsilon and ULP tolerances.
 
CHECKASM_API int checkasm_double_near_abs_eps (double a, double b, double eps)
 Compare doubles using absolute epsilon tolerance.
 
CHECKASM_API int checkasm_double_near_abs_eps_array (const double *a, const double *b, double eps, unsigned len)
 Compare double arrays using absolute epsilon tolerance.
 
 DECL_CHECKASM_CHECK_FUNC (int)
 
 DECL_CHECKASM_CHECK_FUNC (int8_t)
 
 DECL_CHECKASM_CHECK_FUNC (int16_t)
 
 DECL_CHECKASM_CHECK_FUNC (int32_t)
 
 DECL_CHECKASM_CHECK_FUNC (unsigned)
 
 DECL_CHECKASM_CHECK_FUNC (uint8_t)
 
 DECL_CHECKASM_CHECK_FUNC (uint16_t)
 
 DECL_CHECKASM_CHECK_FUNC (uint32_t)
 
CHECKASM_API int checkasm_check_impl_float_ulp (const char *file, int line, const float *buf1, ptrdiff_t stride1, const float *buf2, ptrdiff_t stride2, int w, int h, const char *name, unsigned max_ulp, int align_w, int align_h, int padding)
 Compare float buffers with ULP tolerance.
 

Detailed Description

Utility functions for checkasm tests.

This header provides utility functions commonly needed when writing checkasm tests, including:

  • Random number generation (uniform and normal distributions)
  • Memory initialization and randomization
  • Floating-point comparison utilities
  • Buffer definition and checking helpers

Definition in file utils.h.

Macro Definition Documentation

◆ checkasm_dist_standard

#define checkasm_dist_standard   ((CheckasmDist) { 0.0, 1.0 })

Standard normal distribution (mean=0, stddev=1)

Definition at line 156 of file utils.h.

Function Documentation

◆ checkasm_rand_dist()

CHECKASM_API double checkasm_rand_dist ( CheckasmDist dist)

Generate a normally distributed random number.

Parameters
[in]distDistribution parameters (mean and standard deviation)
Returns
Random value from the specified normal distribution

Definition at line 285 of file utils.c.

◆ checkasm_rand_norm()

CHECKASM_API double checkasm_rand_norm ( void )

Generate a random number from the standard normal distribution.

Returns
Random value from N(0,1) distribution
See also
checkasm_dist_standard

Definition at line 274 of file utils.c.

Referenced by checkasm_rand_dist().