NcmMatrix

NcmMatrix — Matrix object representing an array of doubles.

Functions

NcmMatrix * ncm_matrix_new ()
NcmMatrix * ncm_matrix_new0 ()
NcmMatrix * ncm_matrix_new_full ()
NcmMatrix * ncm_matrix_new_gsl ()
NcmMatrix * ncm_matrix_new_gsl_static ()
NcmMatrix * ncm_matrix_new_array ()
NcmMatrix * ncm_matrix_new_data_slice ()
NcmMatrix * ncm_matrix_new_data_malloc ()
NcmMatrix * ncm_matrix_new_data_static ()
NcmMatrix * ncm_matrix_new_data_static_tda ()
NcmMatrix * ncm_matrix_new_variant ()
NcmMatrix * ncm_matrix_ref ()
const NcmMatrix * ncm_matrix_const_new_data ()
const NcmMatrix * ncm_matrix_const_new_variant ()
NcmMatrix * ncm_matrix_get_submatrix ()
NcmVector * ncm_matrix_get_col ()
NcmVector * ncm_matrix_get_row ()
NcmVector * ncm_matrix_as_vector ()
void ncm_matrix_set_from_variant ()
GVariant * ncm_matrix_get_variant ()
GVariant * ncm_matrix_peek_variant ()
void ncm_matrix_set_from_data ()
void ncm_matrix_set_from_array ()
const NcmMatrix * ncm_matrix_new_gsl_const ()
gdouble ncm_matrix_get ()
gdouble ncm_matrix_get_colmajor ()
gdouble * ncm_matrix_ptr ()
const gdouble * ncm_matrix_const_ptr ()
GArray * ncm_matrix_get_array ()
GArray * ncm_matrix_dup_array ()
void ncm_matrix_set ()
void ncm_matrix_set_colmajor ()
void ncm_matrix_addto ()
void ncm_matrix_transpose ()
void ncm_matrix_transpose_memcpy ()
void ncm_matrix_set_identity ()
void ncm_matrix_set_zero ()
void ncm_matrix_set_all ()
void ncm_matrix_add ()
void ncm_matrix_sub ()
void ncm_matrix_mul_elements ()
void ncm_matrix_div_elements ()
void ncm_matrix_scale ()
void ncm_matrix_add_constant ()
void ncm_matrix_mul_row ()
void ncm_matrix_mul_col ()
void ncm_matrix_get_diag ()
void ncm_matrix_set_diag ()
void ncm_matrix_memcpy ()
void ncm_matrix_memcpy_to_colmajor ()
void ncm_matrix_set_col ()
void ncm_matrix_set_row ()
gdouble ncm_matrix_fast_get ()
void ncm_matrix_fast_set ()
gsl_matrix * ncm_matrix_gsl ()
const gsl_matrix * ncm_matrix_const_gsl ()
guint ncm_matrix_col_len ()
guint ncm_matrix_row_len ()
guint ncm_matrix_nrows ()
guint ncm_matrix_ncols ()
guint ncm_matrix_size ()
guint ncm_matrix_tda ()
gdouble * ncm_matrix_data ()
const gdouble * ncm_matrix_const_data ()
NcmMatrix * ncm_matrix_dup ()
void ncm_matrix_substitute ()
void ncm_matrix_add_mul ()
gdouble ncm_matrix_cmp ()
gdouble ncm_matrix_cmp_diag ()
void ncm_matrix_free ()
void ncm_matrix_clear ()
void ncm_matrix_const_free ()
void ncm_matrix_copy_triangle ()
void ncm_matrix_dsymm ()
void ncm_matrix_dgemm ()
gint ncm_matrix_cholesky_decomp ()
gint ncm_matrix_cholesky_inverse ()
gdouble ncm_matrix_cholesky_lndet ()
gint ncm_matrix_cholesky_solve ()
gint ncm_matrix_cholesky_solve2 ()
gint ncm_matrix_nearPD ()
void ncm_matrix_sym_exp_cholesky ()
void ncm_matrix_sym_posdef_log ()
void ncm_matrix_triang_to_sym ()
void ncm_matrix_square_to_sym ()
void ncm_matrix_update_vector ()
void ncm_matrix_sym_update_vector ()
void ncm_matrix_log_vals ()
void ncm_matrix_fill_rand_cor ()
void ncm_matrix_fill_rand_cov ()
void ncm_matrix_fill_rand_cov2 ()
void ncm_matrix_cov2cor ()
NcmMatrix * ncm_matrix_cov_dup_cor ()

Properties

GVariant * values Read / Write

Types and Values

Object Hierarchy

    GEnum
    ╰── NcmMatrixInternal
    GObject
    ╰── NcmMatrix

Description

This object defines the functions for allocating and accessing matrices. Also includes several matrix operations.

Functions

ncm_matrix_new ()

NcmMatrix *
ncm_matrix_new (const guint nrows,
                const guint ncols);

This function allocates memory for a new NcmMatrix of doubles with nrows rows and ncols columns.

Parameters

nrows

number of rows

 

ncols

number of columns

 

Returns

A new NcmMatrix.


ncm_matrix_new0 ()

NcmMatrix *
ncm_matrix_new0 (const guint nrows,
                 const guint ncols);

This function allocates memory for a new NcmMatrix of doubles with nrows rows and ncols columns and sets all elements to zero.

Parameters

nrows

number of rows

 

ncols

number of columns

 

Returns

A new NcmMatrix.

[transfer full]


ncm_matrix_new_full ()

NcmMatrix *
ncm_matrix_new_full (gdouble *d,
                     guint nrows,
                     guint ncols,
                     guint tda,
                     gpointer pdata,
                     GDestroyNotify pfree);

This function allocates memory for a new NcmMatrix of doubles with nrows rows and ncols columns.

Parameters

d

pointer to the data

 

nrows

number of rows

 

ncols

number of columns

 

tda

row trailing dimension

 

pdata

descending data pointer.

[allow-none]

pfree

free function to be called when destroying the matrix.

[scope notified][allow-none]

Returns

A new NcmMatrix.


ncm_matrix_new_gsl ()

NcmMatrix *
ncm_matrix_new_gsl (gsl_matrix *gm);

This function saves gm internally and frees it when it is no longer necessary. The gm matrix must not be freed.

[skip]

Parameters

gm

matrix from GNU Scientific Library (GSL) to be converted into a NcmMatrix

 

Returns

A new NcmMatrix.


ncm_matrix_new_gsl_static ()

NcmMatrix *
ncm_matrix_new_gsl_static (gsl_matrix *gm);

This function saves gm internally and does not frees it. The gm matrix must be valid during the life of the created NcmMatrix.

[skip]

Parameters

gm

matrix from GNU Scientific Library (GSL) to be converted into a NcmMatrix

 

Returns

A new NcmMatrix.


ncm_matrix_new_array ()

NcmMatrix *
ncm_matrix_new_array (GArray *a,
                      const guint ncols);

The number of rows is defined dividing the lenght of a by ncols . This function saves a internally and frees it when it is no longer necessary. The GArray a must not be freed.

Parameters

a

GArray of doubles to be converted into a NcmMatrix.

[array][element-type double]

ncols

number of columns

 

Returns

A new NcmMatrix.

[transfer full]


ncm_matrix_new_data_slice ()

NcmMatrix *
ncm_matrix_new_data_slice (gdouble *d,
                           const guint nrows,
                           const guint ncols);

This function returns a NcmMatrix of the array d allocated using g_slice function. It saves d internally and frees it when it is no longer necessary. The matrix has nrows rows and ncols columns. The physical number of columns in memory is also given by ncols .

[skip]

Parameters

d

pointer to the first double allocated

 

nrows

number of rows

 

ncols

number of columns

 

Returns

A new NcmMatrix.


ncm_matrix_new_data_malloc ()

NcmMatrix *
ncm_matrix_new_data_malloc (gdouble *d,
                            const guint nrows,
                            const guint ncols);

This function returns a NcmMatrix of the array d allocated using malloc. It saves d internally and frees it when it is no longer necessary.

[skip]

Parameters

d

pointer to the first double allocated

 

nrows

number of rows

 

ncols

number of columns

 

Returns

A new NcmMatrix.


ncm_matrix_new_data_static ()

NcmMatrix *
ncm_matrix_new_data_static (gdouble *d,
                            const guint nrows,
                            const guint ncols);

This function returns a NcmMatrix of the array d . The memory allocated is kept during all time life of the object and must not be freed during this period.

[skip]

Parameters

d

pointer to the first double allocated

 

nrows

number of rows

 

ncols

number of columns

 

Returns

A new NcmMatrix.


ncm_matrix_new_data_static_tda ()

NcmMatrix *
ncm_matrix_new_data_static_tda (gdouble *d,
                                const guint nrows,
                                const guint ncols,
                                const guint tda);

This function returns a NcmMatrix of the array d with a physical number of columns tda which may differ from the corresponding dimension of the matrix. The matrix has nrows rows and ncols columns, and the physical number of columns in memory is given by tda.

[skip]

Parameters

d

pointer to the first double allocated

 

nrows

number of rows

 

ncols

number of columns

 

tda

physical number of columns which may differ from the corresponding dimension of the matrix

 

Returns

A new NcmMatrix.


ncm_matrix_new_variant ()

NcmMatrix *
ncm_matrix_new_variant (GVariant *var);

Creates a new matrix using the values from var .

Parameters

var

a variant of type "aad"

 

Returns

a NcmMatrix with the values from var .

[transfer full]


ncm_matrix_ref ()

NcmMatrix *
ncm_matrix_ref (NcmMatrix *cm);

Increase the reference count of cm by one.

Parameters

cm

a NcmMatrix

 

Returns

cm .

[transfer full]


ncm_matrix_const_new_data ()

const NcmMatrix *
ncm_matrix_const_new_data (const gdouble *d,
                           guint nrows,
                           guint ncols);

This function returns a constant NcmMatrix of the array d . The memory allocated is kept during all time life of the object and must not be freed during this period.

Parameters

d

pointer to the first double allocated

 

nrows

number of rows

 

ncols

number of cols

 

Returns

A new constant NcmMatrix.


ncm_matrix_const_new_variant ()

const NcmMatrix *
ncm_matrix_const_new_variant (GVariant *var);

Creates a new constant matrix using the same memory of var .

Parameters

var

a variant of type "aad"

 

Returns

a NcmMatrix with the values from var .

[transfer full]


ncm_matrix_get_submatrix ()

NcmMatrix *
ncm_matrix_get_submatrix (NcmMatrix *cm,
                          const guint k1,
                          const guint k2,
                          const guint nrows,
                          const guint ncols);

This function returns a submatrix NcmMatrix of the matrix cm . The upper-left element of the submatrix is the element (k1 ,k2 ) of the original matrix. The submatrix has nrows rows and ncols columns.

Parameters

cm

a NcmMatrix

 

k1

row index of the original matrix cm

 

k2

column index of the original matrix cm

 

nrows

number of rows of the submatrix

 

ncols

number of columns of the submatrix

 

Returns

A NcmMatrix.

[transfer full]


ncm_matrix_get_col ()

NcmVector *
ncm_matrix_get_col (NcmMatrix *cm,
                    const guint col);

This function returns the elements of the col column of the matrix cm into a NcmVector.

Parameters

cm

a NcmMatrix

 

col

column index

 

Returns

A NcmVector.

[transfer full]


ncm_matrix_get_row ()

NcmVector *
ncm_matrix_get_row (NcmMatrix *cm,
                    const guint row);

This function returns the elements of the row row of the matrix cm into a NcmVector.

Parameters

cm

a NcmMatrix

 

row

row index

 

Returns

A NcmVector.

[transfer full]


ncm_matrix_as_vector ()

NcmVector *
ncm_matrix_as_vector (NcmMatrix *cm);

Creates a vector containing the row-wise concatenation of the matrix cm . It requires a matrix with tda==ncols.

Parameters

cm

a NcmMatrix

 

Returns

A NcmVector.

[transfer full]


ncm_matrix_set_from_variant ()

void
ncm_matrix_set_from_variant (NcmMatrix *cm,
                             GVariant *var);

This function sets the values of cm using the variant var .

Parameters

cm

a NcmMatrix

 

var

a GVariant of type "aad"

 

ncm_matrix_get_variant ()

GVariant *
ncm_matrix_get_variant (NcmMatrix *cm);

This function gets a variant of values taken from cm .

Parameters

cm

a NcmMatrix

 

Returns

the newly created GVariant.

[transfer full]


ncm_matrix_peek_variant ()

GVariant *
ncm_matrix_peek_variant (NcmMatrix *cm);

This function gets a variant of values taken from cm using the same memory. The matrix cm should not be modified during the variant existance.

Parameters

cm

a NcmMatrix

 

Returns

the newly created GVariant.

[transfer full]


ncm_matrix_set_from_data ()

void
ncm_matrix_set_from_data (NcmMatrix *cm,
                          gdouble *data);

This function sets the valuus of cm using data . Data must have the same size as NcmMatrix.

Parameters

cm

a NcmMatrix

 

data

Array of doubles.

[array][element-type double]

ncm_matrix_set_from_array ()

void
ncm_matrix_set_from_array (NcmMatrix *cm,
                           GArray *a);

This function sets the valuus of cm using data . Data must have the same size as NcmMatrix.

Parameters

cm

a NcmMatrix

 

a

Array of doubles.

[array][element-type double]

ncm_matrix_new_gsl_const ()

const NcmMatrix *
ncm_matrix_new_gsl_const (gsl_matrix *gm);

This function converts gm into a constant NcmMatrix.

[skip]

Parameters

gm

matrix from GNU Scientific Library (GSL)

 

Returns

A new constant NcmMatrix.


ncm_matrix_get ()

gdouble
ncm_matrix_get (const NcmMatrix *cm,
                const guint i,
                const guint j);

Parameters

cm

a constant NcmMatrix

 

i

row index

 

j

column index

 

Returns

The (i ,j )-th element of the matrix cm .


ncm_matrix_get_colmajor ()

gdouble
ncm_matrix_get_colmajor (const NcmMatrix *cm,
                         const guint i,
                         const guint j);

Gets the (i ,j )-th component of cm assuming a column-major order.

All column-major methods should be used carefully, they are inconsistent with most other methods and are used mainly to interface with Fortran sub-routines.

Parameters

cm

a constant NcmMatrix

 

i

row index

 

j

column index

 

Returns

The (i ,j )-th element of the matrix cm .


ncm_matrix_ptr ()

gdouble *
ncm_matrix_ptr (NcmMatrix *cm,
                const guint i,
                const guint j);

Parameters

cm

a NcmMatrix

 

i

row index

 

j

column index

 

Returns

A pointer to the (i ,j )-th element of the matrix cm .


ncm_matrix_const_ptr ()

const gdouble *
ncm_matrix_const_ptr (const NcmMatrix *cm,
                      const guint i,
                      const guint j);

Parameters

cm

a NcmMatrix

 

i

row index

 

j

column index

 

Returns

A constant pointer to the (i ,j )-th element of the matrix cm .


ncm_matrix_get_array ()

GArray *
ncm_matrix_get_array (NcmMatrix *cm);

This function returns the array of cv . It is only applied if the matrix cm was created with ncm_matrix_new_array().

Parameters

cm

a NcmMatrix

 

Returns

A pointer to a double GArray.

[transfer container][element-type double]


ncm_matrix_dup_array ()

GArray *
ncm_matrix_dup_array (NcmMatrix *cm);

This function returns an GArray containing a copy of its elements..

Parameters

cm

a NcmMatrix

 

Returns

A pointer to a double GArray.

[transfer full][element-type double]


ncm_matrix_set ()

void
ncm_matrix_set (NcmMatrix *cm,
                const guint i,
                const guint j,
                const gdouble val);

This function sets the value of the (i ,j )-th element of the matrix cm to val .

Parameters

cm

a NcmMatrix

 

i

row index

 

j

column index

 

val

a double

 

ncm_matrix_set_colmajor ()

void
ncm_matrix_set_colmajor (NcmMatrix *cm,
                         const guint i,
                         const guint j,
                         gdouble val);

This function sets the value of the (i ,j )-th element of the matrix cm to val considering it being in the column-major order.

All column-major methods should be used carefully, they are inconsistent with most other methods and are used mainly to interface with Fortran sub-routines.

Parameters

cm

a NcmMatrix

 

i

row index

 

j

column index

 

val

a double

 

ncm_matrix_addto ()

void
ncm_matrix_addto (NcmMatrix *cm,
                  const guint i,
                  const guint j,
                  const gdouble val);

This function adds the value val to the (i ,j )-th element of the matrix cm .

Parameters

cm

a NcmMatrix

 

i

row index

 

j

column index

 

val

a double

 

ncm_matrix_transpose ()

void
ncm_matrix_transpose (NcmMatrix *cm);

This function replaces the matrix cm by its transpose by copying the elements of the matrix in-place. The matrix must be square for this operation to be possible.

Parameters

cm

a NcmMatrix

 

ncm_matrix_transpose_memcpy ()

void
ncm_matrix_transpose_memcpy (NcmMatrix *cm,
                             NcmMatrix *src);

ncm_matrix_set_identity ()

void
ncm_matrix_set_identity (NcmMatrix *cm);

This function sets the elements of the matrix cm to the corresponding elements of the identity matrix, i.e. a unit diagonal with all off-diagonal elements zero. This applies to both square and rectangular matrices.

Parameters

cm

a NcmMatrix

 

ncm_matrix_set_zero ()

void
ncm_matrix_set_zero (NcmMatrix *cm);

This function sets all the elements of the matrix cm to zero.

Parameters

cm

a NcmMatrix

 

ncm_matrix_set_all ()

void
ncm_matrix_set_all (NcmMatrix *cm,
                    const gdouble val);

This function sets all the elements of the matrix cm to val .

Parameters

cm

a NcmMatrix

 

val

a double

 

ncm_matrix_add ()

void
ncm_matrix_add (NcmMatrix *cm1,
                const NcmMatrix *cm2);

This function adds the elements of the matrices cm1 and cm2 . The two matrices must have the same size.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_sub ()

void
ncm_matrix_sub (NcmMatrix *cm1,
                const NcmMatrix *cm2);

This function subtracts the elements of the matrices cm1 and cm2 . The two matrices must have the same size.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_mul_elements ()

void
ncm_matrix_mul_elements (NcmMatrix *cm1,
                         const NcmMatrix *cm2);

This function multiplies the elements of the matrices cm1 and cm2 . The two matrices must have the same size.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_div_elements ()

void
ncm_matrix_div_elements (NcmMatrix *cm1,
                         const NcmMatrix *cm2);

This function divides the elements of the matrices cm1 and cm2 . The two matrices must have the same size.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_scale ()

void
ncm_matrix_scale (NcmMatrix *cm,
                  const gdouble val);

This function multiplies the elements of the matrix cm by the constant factor val . The result is stored in cm .

Parameters

cm

a NcmMatrix

 

val

a double

 

ncm_matrix_add_constant ()

void
ncm_matrix_add_constant (NcmMatrix *cm,
                         const gdouble val);

This function adds the the constant factor val to the elements of the matrix cm . The result is stored in cm .

Parameters

cm

a NcmMatrix

 

val

a double

 

ncm_matrix_mul_row ()

void
ncm_matrix_mul_row (NcmMatrix *cm,
                    const guint row_i,
                    const gdouble val);

This function multiplies row row_i elements by val .

Parameters

cm

a NcmMatrix

 

row_i

row index

 

val

a double

 

ncm_matrix_mul_col ()

void
ncm_matrix_mul_col (NcmMatrix *cm,
                    const guint col_i,
                    const gdouble val);

This function multiplies column col_i elements by val .

Parameters

cm

a NcmMatrix

 

col_i

column index

 

val

a double

 

ncm_matrix_get_diag ()

void
ncm_matrix_get_diag (NcmMatrix *cm,
                     NcmVector *diag);

This function copies de diagonal elements of the matrix cm to the vector diag .

Parameters

cm

a NcmMatrix

 

diag

a NcmVector

 

ncm_matrix_set_diag ()

void
ncm_matrix_set_diag (NcmMatrix *cm,
                     NcmVector *diag);

This function copies de the elements of the vector diag to the diagonal elements of the matrix cm .

Parameters

cm

a NcmMatrix

 

diag

a NcmVector

 

ncm_matrix_memcpy ()

void
ncm_matrix_memcpy (NcmMatrix *cm1,
                   const NcmMatrix *cm2);

This function copies the elements of the matrix cm2 into the matrix cm1 . The two matrices must have the same size.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_memcpy_to_colmajor ()

void
ncm_matrix_memcpy_to_colmajor (NcmMatrix *cm1,
                               const NcmMatrix *cm2);

This function copies the elements of the matrix cm2 into the matrix cm1 . The two matrices must have the same size. The elements are written in cm1 in column-major order order.

All column-major methods should be used carefully, they are inconsistent with most other methods and are used mainly to interface with Fortran sub-routines.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

ncm_matrix_set_col ()

void
ncm_matrix_set_col (NcmMatrix *cm,
                    const guint n,
                    const NcmVector *cv);

This function copies the elements of the vector cv into the n -th column of the matrix cm . The length of the vector must be the same as the length of the column.

Parameters

cm

a NcmMatrix

 

n

column index

 

cv

a constant NcmVector

 

ncm_matrix_set_row ()

void
ncm_matrix_set_row (NcmMatrix *cm,
                    const guint n,
                    const NcmVector *cv);

This function copies the elements of the vector cv into the n -th row of the matrix cm . The length of the vector must be the same as the length of the row.

Parameters

cm

a NcmMatrix

 

n

row index

 

cv

a constant NcmVector

 

ncm_matrix_fast_get ()

gdouble
ncm_matrix_fast_get (NcmMatrix *cm,
                     const guint ij);

This function returns the value of the cm [i ,j ] element by direct access of its base data. Where ij = i $\times$ tda $+$ j.

If the matrix was created with ncm_matrix_new() or ncm_matrix_new0() then tda = ncols .

Parameters

cm

a NcmMatrix

 

ij

element index of the NcmMatrix base data

 

Returns

The (i ,j )-th element of cm .


ncm_matrix_fast_set ()

void
ncm_matrix_fast_set (NcmMatrix *cm,
                     const guint ij,
                     const gdouble val);

This function sets the value of the cm [i ,j ] element to val by direct access of its base data. Where ij = i $\times$ tda $+$ j.

If the matrix was created with ncm_matrix_new() or ncm_matrix_new0() then tda = ncols .

Parameters

cm

a NcmMatrix

 

ij

element index of the NcmMatrix base data

 

val

a double

 

ncm_matrix_gsl ()

gsl_matrix *
ncm_matrix_gsl (NcmMatrix *cm);

This function returns a pointer to the gsl_matrix associated to the matrix cm .

[skip]

Parameters

cm

a NcmMatrix

 

Returns

A pointer to a gsl_matrix.


ncm_matrix_const_gsl ()

const gsl_matrix *
ncm_matrix_const_gsl (const NcmMatrix *cm);

This function returns a constant pointer to the gsl_matrix associated to the matrix cm .

[skip]

Parameters

cm

a NcmMatrix

 

Returns

A constant pointer to a gsl_matrix.


ncm_matrix_col_len ()

guint
ncm_matrix_col_len (const NcmMatrix *cm);

This function returns the number of elements in a column of the matrix cm . The columns length.

Parameters

cm

a NcmMatrix

 

Returns

The columns length of cm (a.k.a. nrows ).


ncm_matrix_row_len ()

guint
ncm_matrix_row_len (const NcmMatrix *cm);

This function returns the number of elements in a row of the matrix cm . The rows length.

Parameters

cm

a NcmMatrix

 

Returns

The rows length of cm (a.k.a. ncols ).


ncm_matrix_nrows ()

guint
ncm_matrix_nrows (const NcmMatrix *cm);

This function returns the number of elements in a row of the matrix cm .

Parameters

cm

a NcmMatrix

 

Returns

The number of elements in a row of cm .


ncm_matrix_ncols ()

guint
ncm_matrix_ncols (const NcmMatrix *cm);

This function returns the number of elements in a column of the matrix cm .

Parameters

cm

a NcmMatrix

 

Returns

The number of elements in a column of cm .


ncm_matrix_size ()

guint
ncm_matrix_size (const NcmMatrix *cm);

Calculates the total size of the matrix, ncols $\times$ nrows .

Parameters

cm

a NcmMatrix

 

Returns

Total size of the matrix.


ncm_matrix_tda ()

guint
ncm_matrix_tda (const NcmMatrix *cm);

This functions returns the matrix cm tda value.

Parameters

cm

a NcmMatrix

 

Returns

The matrix tda.


ncm_matrix_data ()

gdouble *
ncm_matrix_data (NcmMatrix *cm);

This function returns a pointer to the matrix cm base data.

Parameters

cm

a NcmMatrix

 

Returns

A pointer to cm base data.

[transfer none]


ncm_matrix_const_data ()

const gdouble *
ncm_matrix_const_data (const NcmMatrix *cm);

This function returns a constant pointer to the matrix cm base data.

Parameters

cm

a NcmMatrix

 

Returns

A constant pointer to the matrix cm base data.

[transfer none]


ncm_matrix_dup ()

NcmMatrix *
ncm_matrix_dup (const NcmMatrix *cm);

Duplicates cm setting the same values of the original propertities.

Parameters

cm

a constant NcmMatrix

 

Returns

A NcmMatrix.

[transfer full]


ncm_matrix_substitute ()

void
ncm_matrix_substitute (NcmMatrix **cm,
                       NcmMatrix *nm,
                       gboolean check_size);

Substitute the matrix *cm by nm , first it unref *cm if it is not NULL. If check_size is TRUE then check if the two matrix have the same size.

Parameters

cm

a NcmMatrix

 

nm

a NcmMatrix.

[allow-none]

check_size

a boolean

 

ncm_matrix_add_mul ()

void
ncm_matrix_add_mul (NcmMatrix *cm1,
                    const gdouble a,
                    NcmMatrix *cm2);

This function performs the operation cm1 = a $\times$ cm2 $+$ cm1 .

Parameters

cm1

a NcmMatrix

 

a

a constant gdouble

 

cm2

a NcmMatrix

 

ncm_matrix_cmp ()

gdouble
ncm_matrix_cmp (const NcmMatrix *cm1,
                const NcmMatrix *cm2,
                const gdouble scale);

This function performes a comparison, component-wise, of the two matrices, given by $\left| \right. ($cm1 $-$ cm2 $)/($scale $+$ cm2 $)\left. \right|$ and returns its maximum value.

Parameters

cm1

a constant NcmMatrix

 

cm2

a constant NcmMatrix

 

scale

a constant gdouble

 

Returns

The maximum value of the operation $\left| \right. ($cm1 $-$ cm2 $)/($scale $+$ cm2 $)\left. \right|$.


ncm_matrix_cmp_diag ()

gdouble
ncm_matrix_cmp_diag (const NcmMatrix *cm1,
                     const NcmMatrix *cm2,
                     const gdouble scale);

This function is similar to ncm_matrix_cmp(), but now only the diagonal elements are compared.

Parameters

cm1

a NcmMatrix

 

cm2

a NcmMatrix

 

scale

a constant gdouble

 

Returns

The maximum value of the operation $\left| \right. ($cm1 $-$ cm2 $)/($scale $+$ cm2 $)\left. \right|$ comparing only the diagonal elements.


ncm_matrix_free ()

void
ncm_matrix_free (NcmMatrix *cm);

Atomically decrements the reference count of cm by one. If the reference count drops to 0, all memory allocated by cm is released.

Parameters

cm

a NcmMatrix

 

ncm_matrix_clear ()

void
ncm_matrix_clear (NcmMatrix **cm);

Atomically decrements the reference count of cm by one. If the reference count drops to 0, all memory allocated by cm is released. The pointer is set to NULL.

Parameters

cm

a NcmMatrix

 

ncm_matrix_const_free ()

void
ncm_matrix_const_free (const NcmMatrix *cm);

Atomically decrements the reference count of cv by one. If the reference count drops to 0, all memory allocated by cv is released.

Parameters

cm

a constant NcmMatrix

 

ncm_matrix_copy_triangle ()

void
ncm_matrix_copy_triangle (NcmMatrix *cm,
                          gchar UL);

If UL == 'U' copy the upper triangle over the lower. If UL == 'L' copy the lower triangle over the upper.

Parameters

cm

a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ncm_matrix_dsymm ()

void
ncm_matrix_dsymm (NcmMatrix *cm,
                  gchar UL,
                  const gdouble alpha,
                  NcmMatrix *A,
                  NcmMatrix *B,
                  const gdouble beta);

This function performes the following operation:

if UL == 'U': $\left( \mathsf{cm} \leftarrow \alpha \mathbf{A} \mathbf{B} + \beta \, \mathsf{cm} \right)$;

if UL == 'L': $\left( \mathsf{cm} \leftarrow \alpha \mathbf{B} \mathbf{A} + \beta \, \mathsf{cm} \right)$.

Where $\mathbf{A} = \mathbf{A}^\intercal$.

Parameters

cm

a NcmMatrix

 

UL

gchar indicating 'U'pper or 'L'ower matrix

 

alpha

a constant gdouble

 

A

a NcmMatrix

 

B

a NcmMatrix

 

beta

a constant gdouble

 

ncm_matrix_dgemm ()

void
ncm_matrix_dgemm (NcmMatrix *cm,
                  gchar TransA,
                  gchar TransB,
                  const gdouble alpha,
                  NcmMatrix *A,
                  NcmMatrix *B,
                  const gdouble beta);

Calculates $C = \alpha\mathrm{op}(A)\mathrm{op}(B) + \beta C$.

Parameters

cm

a NcmMatrix $C$

 

TransA

char indicating 'T'ranspose or 'N'ot transposed matrix

 

TransB

char indicating 'T'ranspose or 'N'ot transposed matrix

 

alpha

$\alpha$

 

A

a NcmMatrix $A$

 

B

a NcmMatrix $B$

 

beta

$\beta$

 

ncm_matrix_cholesky_decomp ()

gint
ncm_matrix_cholesky_decomp (NcmMatrix *cm,
                            gchar UL);

Calculates in-place the Cholesky decomposition for a symmetric positive definite matrix.

Parameters

cm

a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ncm_matrix_cholesky_inverse ()

gint
ncm_matrix_cholesky_inverse (NcmMatrix *cm,
                             gchar UL);

Calculates inplace the inverse of cm that has been previously decomposed by the Cholesky decomposition ncm_matrix_cholesky_decomp().

Parameters

cm

a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ncm_matrix_cholesky_lndet ()

gdouble
ncm_matrix_cholesky_lndet (NcmMatrix *cm);

Calculates determinant of a symmetric positive definite matrix, that was previously decomposed using ncm_matrix_cholesky_decomp().

Parameters

cm

a NcmMatrix

 

Returns

the log determinant of cm .


ncm_matrix_cholesky_solve ()

gint
ncm_matrix_cholesky_solve (NcmMatrix *cm,
                           NcmVector *b,
                           gchar UL);

Calculates in-place the Cholesky decomposition for a symmetric positive definite matrix and solve the system $A x = B$ where $A=$cm and $B$=b .

Parameters

cm

a NcmMatrix

 

b

a NcmVector

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ncm_matrix_cholesky_solve2 ()

gint
ncm_matrix_cholesky_solve2 (NcmMatrix *cm,
                            NcmVector *b,
                            gchar UL);

Using a previously computed Cholesky decomposition in cm , through ncm_matrix_cholesky_decomp(), solves the system $A x = B$ where $A=$cm and $B$=b .

Parameters

cm

a NcmMatrix

 

b

a NcmVector

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ncm_matrix_nearPD ()

gint
ncm_matrix_nearPD (NcmMatrix *cm,
                   gchar UL,
                   gboolean cholesky_decomp,
                   const guint maxiter);

Assuming that cm is a symmetric matrix with data on UL side, computes the nearest positive definite matrix in the Frobenius norm. See Higham (2002). The iterations stop when the Cholesky decomposition is valid.

Parameters

cm

a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

cholesky_decomp

if true substitue cm for its Cholesky decomposition

 

maxiter

maximum number of iterations

 

Returns

the return value of the last Cholesky decomposition.


ncm_matrix_sym_exp_cholesky ()

void
ncm_matrix_sym_exp_cholesky (NcmMatrix *cm,
                             gchar UL,
                             NcmMatrix *exp_cm_dec);

Assuming that cm is a symmetric matrix with data on UL side, computes the matrix exponential of cm and its cholesky decomposition.

Parameters

cm

$M$ a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

exp_cm_dec

on exit this matrix contain the upper triangular matrix $U$ where $\exp(M) = U^\intercal U$

 

ncm_matrix_sym_posdef_log ()

void
ncm_matrix_sym_posdef_log (NcmMatrix *cm,
                           gchar UL,
                           NcmMatrix *ln_cm);

Assuming that cm is a symmetric matrix with data on UL side, computes the matrix logarithm of cm .

Parameters

cm

$M$ a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

ln_cm

on exit this matrix contain the upper triangular matrix $U$ where $\exp(M) = U^\intercal U$

 

ncm_matrix_triang_to_sym ()

void
ncm_matrix_triang_to_sym (NcmMatrix *cm,
                          gchar UL,
                          gboolean zero,
                          NcmMatrix *sym);

Assuming that cm is a triangular square matrix with data on UL side, computes the symmetric matrix $M^\intercal \times M$ if cm is upper triangular or $M\times M^\intercal$ if it is lower triangular.

If zero is TRUE it first sets to zero all elements above/below the diagonal for UL == 'L'/'U'. It should be TRUE whenever cm has non-zero values at the other side.

Parameters

cm

$M$ a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

zero

whether it should first set to zero the other side of the matrix

 

sym

a NcmMatrix to store the result

 

ncm_matrix_square_to_sym ()

void
ncm_matrix_square_to_sym (NcmMatrix *cm,
                          gchar NT,
                          gchar UL,
                          NcmMatrix *sym);

Computes the symmetric matrix $M^\intercal \times M$ if NT == 'T' or $M\times M^\intercal$ if NT == 'N'. The result is stored in the upper/lower triangle if UL ='U'/'L'

Parameters

cm

$M$ a NcmMatrix

 

NT

char indicating 'N' or 'T'

 

UL

char indicating 'U'pper or 'L'ower matrix

 

sym

a NcmMatrix to store the result

 

ncm_matrix_update_vector ()

void
ncm_matrix_update_vector (NcmMatrix *cm,
                          gchar NT,
                          const gdouble alpha,
                          NcmVector *v,
                          const gdouble beta,
                          NcmVector *u);

Computes the matrix - vector product $u = \alpha M v + \beta u$ if NT == 'N' or $u = \alpha M^\intercal v + u$ if NT == 'T' and stores the result in u .

Parameters

cm

$M$ a NcmMatrix

 

NT

char indicating 'N' or 'T'

 

alpha

a double $\alpha$

 

v

a NcmVector to update

 

beta

a double $\beta$

 

u

a NcmVector to store the result

 

ncm_matrix_sym_update_vector ()

void
ncm_matrix_sym_update_vector (NcmMatrix *cm,
                              gchar UL,
                              const gdouble alpha,
                              NcmVector *v,
                              const gdouble beta,
                              NcmVector *u);

Computes the matrix - vector product $u = \alpha M v + \beta u$ if NT == 'N' or $u = M^\intercal v$ if NT == 'T' and stores the result in u . This function assumes that $M$ is symmetric and it´s stored in the Upper/Lower triangle if UL == 'U'/'L'.

Parameters

cm

$M$ a NcmMatrix

 

UL

char indicating 'U'pper or 'L'ower matrix

 

alpha

a double $\alpha$

 

v

a NcmVector to update

 

beta

a double $\beta$

 

u

a NcmVector to store the result

 

ncm_matrix_log_vals ()

void
ncm_matrix_log_vals (NcmMatrix *cm,
                     gchar *prefix,
                     gchar *format);

Prints to the log the values of cm .

Parameters

cm

a NcmMatrix

 

prefix

the prefixed text

 

format

double format

 

ncm_matrix_fill_rand_cor ()

void
ncm_matrix_fill_rand_cor (NcmMatrix *cm,
                          const gdouble cor_level,
                          NcmRNG *rng);

Overwrite cm with a random correlation matrix, the parameter cor_level controls the correlation between entries the lower cor_level more correlated the entries are.

Parameters

cm

a square NcmMatrix

 

cor_level

correlation level parameter

 

rng

a NcmRNG

 

ncm_matrix_fill_rand_cov ()

void
ncm_matrix_fill_rand_cov (NcmMatrix *cm,
                          const gdouble sigma_min,
                          const gdouble sigma_max,
                          const gdouble cor_level,
                          NcmRNG *rng);

Overwrite cm with a random covariance matrix, the parameter cor_level controls the correlation between entries the lower cor_level more correlated the entries are.

Parameters

cm

a square NcmMatrix

 

sigma_min

mininum standard deviation

 

sigma_max

maximum standard deviation

 

cor_level

correlation level parameter

 

rng

a NcmRNG

 

ncm_matrix_fill_rand_cov2 ()

void
ncm_matrix_fill_rand_cov2 (NcmMatrix *cm,
                           NcmVector *mu,
                           const gdouble reltol_min,
                           const gdouble reltol_max,
                           const gdouble cor_level,
                           NcmRNG *rng);

Overwrite cm with a random covariance matrix, the parameter cor_level controls the correlation between entries the lower cor_level more correlated the entries are.

Parameters

cm

a square NcmMatrix

 

mu

mean NcmVector

 

reltol_min

mininum standard deviation

 

reltol_max

maximum standard deviation

 

cor_level

correlation level parameter

 

rng

a NcmRNG

 

ncm_matrix_cov2cor ()

void
ncm_matrix_cov2cor (const NcmMatrix *cov,
                    NcmMatrix *cor);

Convert a covariance matrix cov to a correlation matrix cor . The matrices cor and cov can be the same object.

Parameters

cov

a square NcmMatrix

 

cor

the output matrix

 

ncm_matrix_cov_dup_cor ()

NcmMatrix *
ncm_matrix_cov_dup_cor (const NcmMatrix *cov);

Convert a covariance matrix cov to a newly allocated correlation matrix.

Parameters

cov

a square NcmMatrix

 

Returns

the newly allocated correlation matrix.

[transfer full]

Types and Values

NCM_TYPE_MATRIX

#define NCM_TYPE_MATRIX (ncm_matrix_get_type ())

enum NcmMatrixInternal

This enumerator is only used internally. Only by developers.

Members

NCM_MATRIX_SLICE

Uses g_slice_* family functions from Glib to alloc and free memory segments.

 

NCM_MATRIX_GSL_MATRIX

Uses gsl_matrix from GSL as the base object.

 

NCM_MATRIX_MALLOC

Uses malloc for memory allocation and free functions.

 

NCM_MATRIX_GARRAY

Uses g_array from Glib as base.

 

NCM_MATRIX_DERIVED

Uses another NcmMatrix (for example, if it is getting a submatrix from a NcmMatrix).

 

struct NcmMatrix

struct NcmMatrix;

Property Details

The “values” property

  “values”                   GVariant *

GVariant representation of the matrix used to serialize the object.

Owner: NcmMatrix

Flags: Read / Write

Allowed values: GVariant<aad>

Default value: NULL