Gamma  0.9.5
Generic Synthesis Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
gam::arr Namespace Reference

Array rank functions for numerical types. More...

Functions

void linToDB (float *arr, uint32_t len, float minDB)
 Mapping from linear range [-1, 1] to normalized dB range [-1, 1].
void clip1 (float *arr, uint32_t len, uint32_t str=1)
 Clip array values between [-1, 1].
uint32_t zeroCross (const float *src, uint32_t len, float prev)
 Returns number of zero-crossings in array.
uint32_t zeroCrossFirst (const float *src, uint32_t len)
 Returns index of first zero-crossing or 0 if none detected.
uint32_t zeroCrossN (const float *src, uint32_t len, float prev)
 Returns # of negative slope zero-crossings.
template<class T >
void add (T *dst, const T *src, uint32_t len, uint32_t str=1)
 Add source array to destination array.
template<class T >
void add (T *dst, const T *src1, const T *src2, uint32_t len, uint32_t str=1)
 Add two source arrays into destination array.
template<class T >
uint32_t addToRing (T *ring, uint32_t ringSize, uint32_t ringTap, const T *src, uint32_t len)
 Sum elements from src into ring-buffer ring.
template<class T >
void cluster (const T *src, uint32_t *indices, uint32_t &numIndices, T threshold)
 Finds elements that are within a threshold of their nearest neighbors.
template<class T >
dot (const T *src1, const T *src2, uint32_t len, uint32_t str=1)
 Returns dot-product of two arrays.
template<class T >
dot4 (const T *src1, const T *src2)
 Returns dot-product of two arrays of length 4.
template<class T >
void extrema (const T *src, uint32_t len, uint32_t &indexMin, uint32_t &indexMax)
 Get indices of min and max values.
template<class T1 , class T2 , class T3 >
void fitLine (const T1 *src, uint32_t len, T2 &slope, T3 &inter)
 Perform linear least squares fitting of array.
template<class Ts , class Tb >
void histogram (const Ts *src, uint32_t len, Tb *bins, uint32_t numBins, Ts scale=1)
 Compute histogram of 'src'.
template<class T >
uint32_t indexOfMax (const T *src, uint32_t len, uint32_t str=1)
 Returns index of maximum value.
template<class T >
uint32_t indexOfMaxNorm (const T *src, uint32_t len, uint32_t str=1)
 Returns index of maximum normed value (i.e., magnitude)
template<class T >
uint32_t indexOfMin (const T *src, uint32_t len)
 Returns index of minimum value.
void indicesComplement (uint32_t *indices, uint32_t numIndices, uint32_t maxNumIndices)
 Sets indices [numIndices, maxNumIndices) to complement indices.
template<class T >
uint32_t maxima (uint32_t *dst, const T *src, uint32_t len, uint32_t str=1)
 Locates local maxima and writes their indices into 'dst'.
template<class T >
mean (const T *src, uint32_t len, uint32_t str=1)
 Returns the mean (average) value of array values.
template<class T >
meanNorm (const T *src, uint32_t len, uint32_t str=1)
 Returns the mean norm of array values.
template<class T >
meanAbsDiff (const T *src, uint32_t len)
 Returns mean absolute difference of array values.
template<class T >
meanWeighted (const T *src, T *weights, uint32_t len)
 Returns weighted mean of array values.
template<class T >
meanWeightedIndex (const T *weights, uint32_t len)
 Returns weighted mean in [0, len) of indices of weights.
template<class T >
void mirror_dp (T *arr, uint32_t len)
 Applies mirror isometry sequence [dp] from first half of array.
template<class T >
void mirror_dq (T *arr, uint32_t len)
 Applies mirror isometry sequence [dq] from first half of array.
template<class T >
void mul (T *dst, const T *src, uint32_t len, uint32_t str=1)
 Multiply destination array by source array.
template<class T >
void mulBartlett (T *arr, uint32_t len)
 Multiply array by a Bartlett (triangle) window.
template<class T >
void mulHalfWindow (T *arr, const T *src, uint32_t len)
template<class T >
double normalize (T *arr, uint32_t len, double scale=1)
 Uniformly scale array values to fit in [-1, 1].
template<class T >
double norm (const T *src, uint32_t len, uint32_t str=1)
 Returns norm of array values.
template<class T >
double normTaxi (const T *src, uint32_t len, uint32_t str=1)
 Returns taxicab norm of array values (sum of absolute values).
template<class T >
nyquist (const T *src, uint32_t len, uint32_t str=1)
 Returns unnormalized Nyquist value for use with DFT.
template<class T >
rms (const T *src, uint32_t len, uint32_t str=1)
 Returns root mean square- the normalized norm.
template<class T >
uint32_t slopeAbsMax (const T *src, uint32_t len)
 Returns index of absolute maximum slope in array.
template<class T >
uint32_t slopeMax (const T *src, uint32_t len)
 Returns index of maximum slope in array.
template<class T >
void sortInsertion (T *arr, uint32_t len)
 Insertion sort of elements.
template<class T >
void sortInsertion (const T *src, uint32_t *indices, uint32_t numIndices)
 Insertion sort of indexed elements.
template<class T >
void sortQuick (const T *src, uint32_t *indices, long beg, long end)
 Quick sort of elements.
template<class T >
sum (const T *src, uint32_t len, uint32_t str=1)
 Returns sum of values.
template<class T >
sumSquares (const T *src, uint32_t len, uint32_t str=1)
 Returns sum of values squared.
template<class T >
variance (const T *src, uint32_t len, uint32_t str=1)
 Variance (deviation from mean).
template<class T >
uint32_t within (const T *src, uint32_t len, T threshold)
 Returns number of values within [-threshold, theshold].
template<class T >
uint32_t within (const T *src, uint32_t len, T lo, T hi)
 Returns number of values within [lo, hi].
template<class T >
uint32_t zeroCount (const T *src, uint32_t len, uint32_t str=1)
 Returns number of values that equal zero.

Detailed Description

Array rank functions for numerical types.

The following are names commonly used for input parameters.

'src' - array that will only be read from
'dst' - array that will be written to
'arr' - array that will be read from and written to, i.e. in-place
'len' - length of array
'stride' - how many elements to step through the array by
Many of these functions are numerically generic meaning that the object is required to understand one or more of arithmetic operators +, -, *, \, and/or relational operators <, <=, >, >=.


Function Documentation

uint32_t addToRing ( T *  ring,
uint32_t  ringSize,
uint32_t  ringTap,
const T *  src,
uint32_t  len 
)

Sum elements from src into ring-buffer ring.

Returns the next tap index. This will not guaranteed to be in the range [0, ringSize).

void cluster ( const T *  src,
uint32_t *  indices,
uint32_t &  numIndices,
threshold 
)

Finds elements that are within a threshold of their nearest neighbors.

Parameters:
[in]srcSource array of elements
[in]indicesIndex array used for iterating the source array.
[out]indicesCluster indices.
[in]numIndicesNumber of source indices.
[out]numIndicesNumber of cluster indices.
[in]thresholdMagnitude threshold of cluster.
void gam::arr::fitLine ( const T1 *  src,
uint32_t  len,
T2 &  slope,
T3 &  inter 
)

Perform linear least squares fitting of array.

The independent axis is the array indices, i. The best fit line equation is y = inter + slope * i.

void histogram ( const Ts *  src,
uint32_t  len,
Tb *  bins,
uint32_t  numBins,
Ts  scale = 1 
)

Compute histogram of 'src'.

Values in 'src' are tallied and placed in 'bins', where the index of the bin is the integer part of the source values. Source values greater than the number of bins are ignored. The scale and offset parameters can be used to put the src values into the proper range.

void indicesComplement ( uint32_t *  indices,
uint32_t  numIndices,
uint32_t  maxNumIndices 
)

Sets indices [numIndices, maxNumIndices) to complement indices.

Indices must be sorted from low to high.

uint32_t maxima ( uint32_t *  dst,
const T *  src,
uint32_t  len,
uint32_t  str = 1 
)

Locates local maxima and writes their indices into 'dst'.

Returns number of maxima found.

T meanWeighted ( const T *  src,
T *  weights,
uint32_t  len 
)

Returns weighted mean of array values.

Weights must be positive.

T meanWeightedIndex ( const T *  weights,
uint32_t  len 
)

Returns weighted mean in [0, len) of indices of weights.

Weights must be positive. Can be used to compute centroid of spectrum.

void mirror_dp ( T *  arr,
uint32_t  len 
)

Applies mirror isometry sequence [dp] from first half of array.

The sequence of mirror isometries are identity (d) and rotation (p). The first len/2 elements of the array are mirrored.
Ex.: [ 1, 2, 3, 4, x, x, x, x] -> [ 1, 2, 3, 4,-4,-3,-2,-1]

void mirror_dq ( T *  arr,
uint32_t  len 
)

Applies mirror isometry sequence [dq] from first half of array.

The sequence of mirror isometries are identity (d) and glide relfection (q). The first len/2 elements of the array are mirrored.
Ex.: [ 1, 2, 3, 4, x, x, x, x] -> [ 1, 2, 3, 4,-1,-2,-3,-4]

void mulBartlett ( T *  arr,
uint32_t  len 
)

Multiply array by a Bartlett (triangle) window.

Works only for even sized arrays.

void mulHalfWindow ( T *  arr,
const T *  src,
uint32_t  len 
)

Multiply 'arr' by 'src' where 'src' is the first 'len'/2 + 1 elements of a symmetric window.

double normalize ( T *  arr,
uint32_t  len,
double  scale = 1 
)

Uniformly scale array values to fit in [-1, 1].

Returns the applied normalization multiplication factor.

void sortInsertion ( T *  arr,
uint32_t  len 
)

Insertion sort of elements.

Elements are sorted from lowest to highest. This sort is fastest for small length arrays and mostly sorted sets.

void sortInsertion ( const T *  src,
uint32_t *  indices,
uint32_t  numIndices 
)

Insertion sort of indexed elements.

Elements are sorted from lowest to highest. This sort is fastest for small length arrays and mostly sorted sets.

void sortQuick ( const T *  src,
uint32_t *  indices,
long  beg,
long  end 
)

Quick sort of elements.

Elements are sorted from lowest to highest.

uint32_t zeroCross ( const float *  src,
uint32_t  len,
float  prev 
)

Returns number of zero-crossings in array.

'prev' is the last value from the previous buffer.

uint32_t zeroCrossN ( const float *  src,
uint32_t  len,
float  prev 
)

Returns # of negative slope zero-crossings.

'prev' is the last value from the previous buffer.