CCL Library  1.0
Data Structures | Functions

CCL header file for math. More...

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_statistics.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_sort.h>

Go to the source code of this file.

Data Structures

struct  MP_INV_WS
 This structure describes the workspace memory of calculating matrix pseudo inverse MP_INV_WS. More...
 

Functions

void ccl_mat_add (double *A, const double *B, int row, int col)
 Matrix addition. More...
 
void ccl_mat_sub (double *A, const double *B, int row, int col)
 Matrix subtraction. More...
 
double ccl_vec_sum (double *vec, int size)
 Sum of a vector. More...
 
void mat_hotz_app (double *A, int i, int j, const double *B, int k, int d, double *c)
 Append matrix horizontally. More...
 
void mat_vert_app (const double *A, int i, int j, const double *B, int k, int d, double *c)
 Append matrix vertically. More...
 
void ccl_dot_product (const double *A, int i, int j, const double *B, int k, int d, double *C)
 Dot product of two matrix. More...
 
void ccl_mat_inv (const double *A, int i, int j, double *invA)
 Matrix inverse of square matrix. More...
 
void ccl_MP_pinv (const double *A_in, int row, int col, double *invA)
 Matrix inverse of arbitrary matrix. More...
 
int ccl_MP_inv_ws_alloc (MP_INV_WS *ws, int n, int m)
 Allocates the workspace memory for MP_INV_WS. More...
 
int ccl_MP_inv_ws_free (MP_INV_WS *ws)
 Free the workspace memory for MP_INV_WS. More...
 
void linspace (double min, double max, double n, double *y)
 Equally divided space. More...
 
void repmat (const double *mat, int row, int col, int rows, int cols, double *A)
 Replicate matrix. More...
 
void repvec (const gsl_vector *vec, int rows, int cols, gsl_matrix *A)
 Replicate vector. More...
 
void repvvec (const double *vec, int size, int rows, double *A)
 Replicate vector vertically (to be removed). More...
 
void flt_mat (const double *mat, int row, int col, double *vec)
 Flatten matrix to vector. More...
 
void ccl_mat_var (const double *data_in, int row, int col, int axis, double *var)
 Variances of a matrix. More...
 
void print_mat (gsl_matrix *mat)
 Print GSL matrix. More...
 
void print_mat_d (double *mat, int row, int col)
 Print double matrix. More...
 
void print_mat_i (int *mat, int row, int col)
 Print int matrix. More...
 
void vec_to_mat (const gsl_vector *vec, gsl_matrix *mat)
 Convert vector type to matrix type. More...
 
void nround (const double *n, int size, unsigned int c, double *ret)
 Round double array to some decimal. More...
 
void generate_kmeans_centres (const double *X, const int dim_x, const int dim_n, const int dim_b, double *centres)
 K mean algorithm. More...
 
void ccl_get_sub_mat_cols (const double *mat, const int row, const int col, const int *ind, int size, double *ret)
 Get sub cols of a matrix. More...
 
int ccl_mat_distance (const double *A, const int a_i, const int a_j, const double *B, const int b_i, const int b_j, double *D)
 Distance of two matrices. More...
 
void ccl_mat_sum (const double *mat, const int i, const int j, const int axis, double *ret)
 Summation of a matrix. More...
 
void ccl_mat_min (const double *mat, const int i, const int j, const int axis, double *val, int *indx)
 Minimum values of a matrix. More...
 
void ccl_mat_mean (const double *mat, const int i, const int j, const int axis, double *val)
 Mean values of a matrix. More...
 
int ccl_find_index_int (const int *a, const int num_elements, const int operand, const int value, int *idx)
 Find index of an array of integers. More...
 
int ccl_find_index_double (const double *a, const int num_elements, const int operand, const double value, int *idx)
 Find index of an array of integers. operand 1: = ; 2 >=; 3<= . More...
 
void ccl_mat_set_col (double *mat, int i, int j, int c, double *vec)
 Find index of an array of doubles. operand 1: = ; 2 >=; 3<= . More...
 
void ccl_gaussian_rbf (const double *X, int i, int j, const double *C, int k, int d, double s, double *BX)
 Radial basis function. More...
 
void ccl_mat_transpose (const double *mat, int i, int j, double *mat_T)
 Matrix transpose. More...
 
int ccl_any (double *vec, double epx, int size, int op)
 Return true if any of the element in the vector satify the tolerance: op==0 '>=', op==1 '<='. More...
 
void ccl_mat_reshape (const double *vec, int i, int j, double *mat)
 Reshape vector to matrix. More...
 

Detailed Description

CCL header file for math.

Function Documentation

int ccl_any ( double *  vec,
double  epx,
int  size,
int  op 
)

Return true if any of the element in the vector satify the tolerance: op==0 '>=', op==1 '<='.

Parameters
[in]vecInput vector, must point to an array of size doubles
[in]eps Tolerance
[in]size Number of elements
[in]op Operations
Returns
  • 0 false
  • 1 true
void ccl_dot_product ( const double *  A,
int  i,
int  j,
const double *  B,
int  k,
int  d,
double *  C 
)

Dot product of two matrix.

Parameters
[in]AInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]B Output matrix, must point to an array of k * d doubles
[in]k Number of rows
[in]d Number of cols
[out]C Returned matrix, must point to an array of i * d doubles
int ccl_find_index_double ( const double *  a,
const int  num_elements,
const int  operand,
const double  value,
int *  idx 
)

Find index of an array of integers. operand 1: = ; 2 >=; 3<= .

Parameters
[in]aInput array, must point to an array of num_elements integers
[in]num_elements Number of elements
[in]operand Operations
[in]value Tolerance value
[out]idx Index of the value
Returns
  • 1 found
  • 0 not found
int ccl_find_index_int ( const int *  a,
const int  num_elements,
const int  operand,
const int  value,
int *  idx 
)

Find index of an array of integers.

Parameters
[in]aInput array, must point to an array of num_elements int
[in]num_elements Number of elements
[in]operand Operations
[in]value Tolerance value
[out]idx Index of the value
Returns
  • 1 found
  • 0 not found
void ccl_gaussian_rbf ( const double *  X,
int  i,
int  j,
const double *  C,
int  k,
int  d,
double  s,
double *  BX 
)

Radial basis function.

Parameters
[in]XInput variables, must point to an array of i * j double
[in]i Number of rows
[in]j Number of cols
[in]C Centers
[in]k Number of rows of centers
[in]d Number of cols of centers
[in]s Variance
[out]BX Higher dimensionality of the input variables
void ccl_get_sub_mat_cols ( const double *  mat,
const int  row,
const int  col,
const int *  ind,
int  size,
double *  ret 
)

Get sub cols of a matrix.

Parameters
[in]matInput matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[in]ind Index of the sub matrix, must point to an array of size doubles
[in]size Number of index
[out]ret Sub matrix
void ccl_mat_add ( double *  A,
const double *  B,
int  row,
int  col 
)

Matrix addition.

Parameters
[in]AInput matrix, must point to an array of row * col doubles
[in]B Output matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[out]A Input matrix, must point to an array of row * col doubles
int ccl_mat_distance ( const double *  A,
const int  a_i,
const int  a_j,
const double *  B,
const int  b_i,
const int  b_j,
double *  D 
)

Distance of two matrices.

Parameters
[in]AInput matrix, must point to an array of i * j doubles
[in]a_i Number of rows
[in]a_j Number of cols
[in]B Output matrix, must point to an array of k * d doubles
[in]b_i Number of rows
[in]b_j Number of cols
[out]D Distance matrix, must point to an array of a_i * b_j doubles
void ccl_mat_inv ( const double *  A,
int  i,
int  j,
double *  invA 
)

Matrix inverse of square matrix.

Parameters
[in]AInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[out]invA Matrix inverse, must point to an array of j * i doubles
void ccl_mat_mean ( const double *  mat,
const int  i,
const int  j,
const int  axis,
double *  val 
)

Mean values of a matrix.

Parameters
[in]matInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]axis Axis of calculation
[out]val Vector of mean values in the matrix
void ccl_mat_min ( const double *  mat,
const int  i,
const int  j,
const int  axis,
double *  val,
int *  indx 
)

Minimum values of a matrix.

Parameters
[in]matInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]axis Axis of calculation
[out]val Vector of minimum values in the matrix
[out]indx Vector of index for minimum values
void ccl_mat_reshape ( const double *  vec,
int  i,
int  j,
double *  mat 
)

Reshape vector to matrix.

Parameters
[in]vecInput vector, must point to an array of i*j doubles
[in]i Number of rows for the matrix
[in]j Number of cols for the matrix
[in]mat Reshaped matrix
void ccl_mat_set_col ( double *  mat,
int  i,
int  j,
int  c,
double *  vec 
)

Find index of an array of doubles. operand 1: = ; 2 >=; 3<= .

Parameters
[in]matInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]c Index of the col
[out]vec Returned vector
void ccl_mat_sub ( double *  A,
const double *  B,
int  row,
int  col 
)

Matrix subtraction.

Parameters
[in]AInput matrix, must point to an array of row * col doubles
[in]B Output matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[out]A Input matrix, must point to an array of row * col doubles
void ccl_mat_sum ( const double *  mat,
const int  i,
const int  j,
const int  axis,
double *  ret 
)

Summation of a matrix.

Parameters
[in]matInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]axis Axis of calculation
[out]ret Vector of summation
void ccl_mat_transpose ( const double *  mat,
int  i,
int  j,
double *  mat_T 
)

Matrix transpose.

Parameters
[in]matInput matrix, must point to an array of i * j double
[in]i Number of rows
[in]j Number of cols
[out]mat_T Tranpose matrix
void ccl_mat_var ( const double *  data_in,
int  row,
int  col,
int  axis,
double *  var 
)

Variances of a matrix.

Parameters
[in]data_inInput matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[in]axis Axis of calculation
[out]var Returned vector
int ccl_MP_inv_ws_alloc ( MP_INV_WS ws,
int  n,
int  m 
)

Allocates the workspace memory for MP_INV_WS.

Parameters
[in]wsMust point to a valid MP_INV_WS structure
[in]nNumber of rows
[in]mNumber of cols
Returns
  • 1 in case of succes
  • 0 in case of failure (e.g. memory could not be allocated)
int ccl_MP_inv_ws_free ( MP_INV_WS ws)

Free the workspace memory for MP_INV_WS.

Parameters
[in]wsMust point to a valid MP_INV_WS structure
[in]nNumber of rows
[in]mNumber of cols
Returns
  • 1 in case of succes
  • 0 in case of failure (e.g. memory could not be freed)
void ccl_MP_pinv ( const double *  A_in,
int  row,
int  col,
double *  invA 
)

Matrix inverse of arbitrary matrix.

Parameters
[in]A_inInput matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[out]invA Matrix inverse, must point to an array of row * col doubles
double ccl_vec_sum ( double *  vec,
int  size 
)

Sum of a vector.

Parameters
[in]vecInput vector, must point to an array of size * 1 doubles
[in]B Output matrix, must point to an array of row * col doubles
Returns
The summation of input variable
void flt_mat ( const double *  mat,
int  row,
int  col,
double *  vec 
)

Flatten matrix to vector.

Parameters
[in]matInput matrix, must point to an array of row * col doubles
[in]row Number of rows
[in]col Number of cols
[out]vec Returned vector, must point to an array of row*col * 1 doubles
void generate_kmeans_centres ( const double *  X,
const int  dim_x,
const int  dim_n,
const int  dim_b,
double *  centres 
)

K mean algorithm.

Parameters
[in]XInput variable, must point to an array of dim_x * dim_n doubles
[in]dim_x Dimensionality of input variable
[in]dim_n Number of data samples
[in]dim_b Number of rbf centers
[out]centres Centers of input data
void linspace ( double  min,
double  max,
double  n,
double *  y 
)

Equally divided space.

Parameters
[in]minMimimum value
[in]maxmaximum value
[in]nNumber of data
[out]yReturned vector, must point to an array of n doubles
void mat_hotz_app ( double *  A,
int  i,
int  j,
const double *  B,
int  k,
int  d,
double *  c 
)

Append matrix horizontally.

Parameters
[in]AInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]B Output matrix, must point to an array of k * d doubles
[in]k Number of rows
[in]d Number of cols
[out]c Appended matrix, must point to an array of i * j+d doubles
void mat_vert_app ( const double *  A,
int  i,
int  j,
const double *  B,
int  k,
int  d,
double *  c 
)

Append matrix vertically.

Parameters
[in]AInput matrix, must point to an array of i * j doubles
[in]i Number of rows
[in]j Number of cols
[in]B Output matrix, must point to an array of k * d doubles
[in]k Number of rows
[in]d Number of cols
[out]c Appended matrix, must point to an array of i+k * j doubles
void nround ( const double *  n,
int  size,
unsigned int  c,
double *  ret 
)

Round double array to some decimal.

Parameters
[in]nInput double array, must point to an array of size doubles
[in]size Size of array
[in]c Number of decimal
[out]ret Rounded double array
void print_mat ( gsl_matrix *  mat)

Print GSL matrix.

Parameters
[in]matInput GSL matrix
void print_mat_d ( double *  mat,
int  row,
int  col 
)

Print double matrix.

Parameters
[in]matInput GSL matrix
[in]rowNumber of rows
[in]colNumber of cols
void print_mat_i ( int *  mat,
int  row,
int  col 
)

Print int matrix.

Parameters
[in]matInput GSL matrix
[in]rowNumber of rows
[in]colNumber of cols
void repmat ( const double *  mat,
int  row,
int  col,
int  rows,
int  cols,
double *  A 
)

Replicate matrix.

Parameters
[in]matInput matrix, must point to an array of row*col doubles
[in]row Number of rows
[in]col Number of cols
[in]rows Number of rows for replication
[in]cols Number of cols for replication
[out]A Returned matix, must point to an array of row*rows * col*cols doubles
void repvec ( const gsl_vector *  vec,
int  rows,
int  cols,
gsl_matrix *  A 
)

Replicate vector.

Parameters
[in]vecInput vector
[in]rowsNumber of rows for replication
[in]colsNumber of cols for replication
[out]AReturned matix
void repvvec ( const double *  vec,
int  size,
int  rows,
double *  A 
)

Replicate vector vertically (to be removed).

Parameters
[in]vecInput vector, must point to an array of size doubles
[in]rows Number of rows for replication
[out]A Returned matix, must point to an array of row*rows * 1 doubles
void vec_to_mat ( const gsl_vector *  vec,
gsl_matrix *  mat 
)

Convert vector type to matrix type.

Parameters
[in]vecInput GSL vector
[out]matOutput GSL matrix