Top | ![]() |
![]() |
![]() |
![]() |
Functions
Description
This object defines the functions for allocating and accessing matrices. Also includes serveral 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.
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.
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.
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]
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]
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 |
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]
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]
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]
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]
ncm_matrix_new_variant ()
NcmMatrix *
ncm_matrix_new_variant (GVariant *var
);
Creates a new matrix using the values from var
.
ncm_matrix_ref ()
NcmMatrix *
ncm_matrix_ref (NcmMatrix *cm
);
Increase the reference count of cm
by one.
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.
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
.
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.
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.
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.
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
.
ncm_matrix_get_variant ()
GVariant *
ncm_matrix_get_variant (NcmMatrix *cm
);
This function gets a variant of values taken from cm
.
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.
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.
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.
ncm_matrix_new_gsl_const ()
const NcmMatrix *
ncm_matrix_new_gsl_const (gsl_matrix *m
);
This function converts m
into a constant NcmMatrix.
[skip]
ncm_matrix_const_ptr ()
const gdouble * ncm_matrix_const_ptr (const NcmMatrix *cm
,const guint i
,const guint j
);
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
.
ncm_matrix_set_colmajor ()
void ncm_matrix_set_colmajor (NcmMatrix *cm
,const guint i
,const guint j
,gdouble val
);
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
.
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.
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.
ncm_matrix_set_zero ()
void
ncm_matrix_set_zero (NcmMatrix *cm
);
This function sets all the elements of the matrix cm
to zero.
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
.
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.
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.
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.
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.
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
.
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
.
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
.
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
.
ncm_matrix_memcpy ()
void ncm_matrix_memcpy (NcmMatrix *cm1
,const NcmMatrix *cm2
);
This function copies the elements of the matrix cm1
into the matrix cm2
.
The two matrices must have the same size.
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.
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.
ncm_matrix_fast_set ()
void ncm_matrix_fast_set (NcmMatrix *cm
,const guint ij
,const gdouble val
);
FIXME
ncm_matrix_size ()
guint
ncm_matrix_size (const NcmMatrix *cm
);
Calculates the total size of the matrix, ncols * nrows.
ncm_matrix_dup ()
NcmMatrix *
ncm_matrix_dup (const NcmMatrix *cm
);
Duplicates cm
setting the same values of the original propertities.
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.
ncm_matrix_add_mul ()
void ncm_matrix_add_mul (NcmMatrix *cm
,const gdouble alpha
,NcmMatrix *b
);
FIXME
ncm_matrix_cmp ()
gdouble ncm_matrix_cmp (const NcmMatrix *cm1
,const NcmMatrix *cm2
,const gdouble scale
);
FIXME
ncm_matrix_cmp_diag ()
gdouble ncm_matrix_cmp_diag (const NcmMatrix *cm1
,const NcmMatrix *cm2
,const gdouble scale
);
FIXME
ncm_matrix_norma_diag ()
NcmMatrix * ncm_matrix_norma_diag (const NcmMatrix *cm1
,NcmMatrix *cm2
);
FIXME
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.
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.
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.
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 lower.
ncm_matrix_dsymm ()
void ncm_matrix_dsymm (NcmMatrix *cm
,gchar UL
,const gdouble alpha
,NcmMatrix *A
,NcmMatrix *B
,const gdouble beta
);
FIXME
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$.
ncm_matrix_cholesky_decomp ()
gint ncm_matrix_cholesky_decomp (NcmMatrix *cm
,gchar UL
);
Calculates inplace the Cholesky decomposition for a symmetric positive definite 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()
.
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()
.
ncm_matrix_cholesky_solve ()
gint ncm_matrix_cholesky_solve (NcmMatrix *cm
,NcmVector *b
,gchar UL
);
Calculates inplace the Cholesky decomposition for a symmetric positive
definite matrix and solve the system $A x = B$ where $A=$cm
and $B$=b
.
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
.
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.
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^\textsc{T}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^\textsc{T}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^\textsc{T}\times M$ if
cm
is upper triangular or $M\times M^\textsc{T}$ 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.
ncm_matrix_log_vals ()
void ncm_matrix_log_vals (NcmMatrix *cm
,gchar *prefix
,gchar *format
);
Prints to the log the values of cm
.
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.
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.
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.
Property Details
The “values”
property
“values” GVariant *
values.
Flags: Read / Write
Allowed values: GVariant<a*>
Default value: NULL