Class
NumCosmoMathMatrix
Description [src]
class NumCosmoMath.Matrix : GObject.Object
{
/* No available fields */
}
Reference-counted row-major matrix of doubles, a view over a #gsl_matrix.
Rows are separated by the trailing dimension, the tda, which is at least the number of
columns. The data can be allocated by the matrix or come from GSL, a GArray, a GVariant,
another NcmMatrix (a submatrix) or a user array, with the ownership stated by each
constructor. Functions whose names contain colmajor read or write the data in
column-major order, for Fortran routines; the rest of the API is row-major. Wrappers of
BLAS and LAPACK take their character arguments (‘N’/’T’, ‘U’/’L’, ‘L’/’R’) in the row-major sense.
Constructors
ncm_matrix_const_new_variant
Creates a constant matrix over the data of var, holding a reference to it.
ncm_matrix_new_array
Creates a matrix over the elements of a, holding a reference to it, with ncols columns
and the length of a divided by ncols rows. Aborts if ncols does not divide the length.
ncm_matrix_new_data_malloc
Creates a matrix over d, which it takes ownership of and frees with g_free().
ncm_matrix_new_gsl
Creates a matrix over gm, which it takes ownership of and frees with gsl_matrix_free().
Functions
ncm_matrix_substitute
Replaces *cm by a new reference to nm, releasing the previous one. With check_size,
aborts if both are set and their shapes differ.
Instance methods
ncm_matrix_as_vector
Creates a view of all the elements of cm, row after row, holding a reference to cm.
The tda of cm must equal its number of columns.
ncm_matrix_chol_chi2_cols
Computes the squared Mahalanobis distance of each column of cm from theta under the
covariance $C = U^\intercal U$,
$$\chi^2_p = (x_p - \theta)^\intercal C^{-1} (x_p - \theta),$$
and stores it in the first $n_p$ entries of chi2. The triangular solve
$y_p = (x_p - \theta) U^{-1}$ and the norm $|y_p|^2$ are done in one pass, on blocks of $n_b$
columns, with work as the only scratch.
ncm_matrix_cholesky_decomp
Replaces the UL triangle of the symmetric positive definite cm by its Cholesky factor,
with LAPACK dpotrf.
ncm_matrix_cholesky_decomp_nearPD
Stores in decomp the Cholesky factor of cm, reading the UL triangle and leaving cm
unchanged. If cm is not positive definite to rounding, the factor of the nearest
positive definite matrix, from ncm_matrix_nearPD(), is stored instead.
ncm_matrix_cholesky_inverse
Replaces the Cholesky factor in the UL triangle of cm, from
ncm_matrix_cholesky_decomp(), by that triangle of the inverse of the original matrix,
with LAPACK dpotri.
ncm_matrix_cholesky_lndet
cm holds the Cholesky factor from ncm_matrix_cholesky_decomp(). The product of the
diagonal is rescaled as it is accumulated, so it cannot overflow.
ncm_matrix_cholesky_solve
Solves $A x = b$ for the symmetric positive definite $A$ in cm, with LAPACK dposv:
cm is replaced by the Cholesky factor in its UL triangle and b by $x$.
ncm_matrix_cholesky_solve2
Solves $A x = b$ with the Cholesky factor of $A$ already in cm, from
ncm_matrix_cholesky_decomp(), with LAPACK dpotrs; b is replaced by $x$.
ncm_matrix_copy_triangle
Copies the upper triangle of the square cm over the lower for UL ‘U’, or the lower over
the upper for ‘L’. Aborts if cm is not square or UL is invalid.
ncm_matrix_cov2cor
Stores in cor the correlation matrix of the covariance cov; they may be the same object.
ncm_matrix_dsymm
Sets $C \to \alpha A B + \beta C$, reading only the UL triangle of $A$. The three
matrices are square and of the same size.
ncm_matrix_dsyrk
Sets $C \to \alpha A A^\intercal + \beta C$ for Trans ‘N’, or $C \to \alpha A^\intercal A + \beta C$
for ‘T’. Only the UL triangle of $C$ is written.
ncm_matrix_dtrmm
Sets $B \to \alpha\,\mathrm{op}(A)\,B$ for Side ‘L’, or $B \to \alpha B\,\mathrm{op}(A)$ for ‘R’.
Only the UL triangle of $A$ is read, its diagonal taken as stored.
ncm_matrix_dtrmv
Sets $v \to \mathrm{op}(A)\,v$. Only the UL triangle of $A$ is read, its diagonal taken as stored.
ncm_matrix_dtrsm
Sets $B \to \alpha\,\mathrm{op}(A)^{-1} B$ for Side ‘L’, or $B \to \alpha B\,\mathrm{op}(A)^{-1}$
for ‘R’. Only the UL triangle of $A$ is read, its diagonal taken as stored.
ncm_matrix_dtrsv
Sets $v \to \mathrm{op}(A)^{-1} v$. Only the UL triangle of $A$ is read, its diagonal taken
as stored.
ncm_matrix_fast_get
Reads the data directly: the element ($i$, $j$) is at ij $= i\,\mathrm{tda} + j$.
ncm_matrix_fast_set
Writes the data directly: the element ($i$, $j$) is at ij $= i\,\mathrm{tda} + j$.
ncm_matrix_fill_rand_cor
Replaces cm by a random correlation matrix from the vine construction of
Lewandowski, Kurowicka and Joe (2009): the
partial correlations are drawn from Beta($\beta$, $\beta$) mapped to $[-1, 1]$, so a smaller
cor_level gives stronger correlations.
ncm_matrix_fill_rand_cov
Replaces cm by a random covariance matrix: the correlations of
ncm_matrix_fill_rand_cor() and standard deviations drawn uniformly in
[sigma_min, sigma_max].
ncm_matrix_fill_rand_cov2
Replaces cm by a random covariance matrix: the correlations of
ncm_matrix_fill_rand_cor() and standard deviations $\sigma_k = |\mu_k| r_k$, or $r_k$ where
$\mu_k = 0$, with $r_k$ drawn log-uniformly in [reltol_min, reltol_max].
ncm_matrix_get_submatrix
Creates a view of the nrows by ncols block of cm whose first element is (k1, k2),
holding a reference to cm.
ncm_matrix_memcpy_to_colmajor
Copies cm2 into cm1, writing the data of cm1 in column-major order; they must have
the same shape.
ncm_matrix_nearPD
Replaces the symmetric cm, stored in its UL triangle, by the nearest positive definite
matrix in the Frobenius norm, Higham (2002),
iterating until its Cholesky decomposition succeeds or maxiter is reached.
ncm_matrix_peek_variant
Creates a GVariant of type aad sharing the data of cm, which must not change while
the variant exists.
ncm_matrix_set_from_variant
Sets the elements of cm to those of var. A matrix without elements is allocated with
the shape of var. Aborts if var has another type or shape.
ncm_matrix_square_to_sym
Stores in the UL triangle of sym the symmetric $M M^\intercal$ for NT ‘N’, or $M^\intercal M$ for ‘T’.
ncm_matrix_sym_exp_cholesky
Computes the matrix exponential of cm from its eigendecomposition, and stores in
exp_cm_dec the upper triangular $U$ with $\exp(M) = U^\intercal U$.
ncm_matrix_sym_posdef_log
Stores in ln_cm the matrix logarithm $\ln M$, from the eigendecomposition of cm.
ncm_matrix_sym_update_vector
Sets $u \to \alpha M v + \beta u$, reading only the UL triangle of $M$.
ncm_matrix_transpose_memcpy
Copies the transpose of src into cm, whose shape must be that of the transpose.
ncm_matrix_triang_to_sym
Stores in sym the symmetric $M^\intercal M$ for an upper triangular cm, or $M M^\intercal$ for a
lower one. Unless zero is TRUE, the other triangle of cm must already be zero.
ncm_matrix_update_vector
Sets $u \to \alpha\,\mathrm{op}(M)\,v + \beta u$; any NT other than ‘N’ transposes.
ncm_matrix_zero_triangle
Sets to zero the strict lower triangle of the square cm for UL ‘U’, or its strict upper
triangle for ‘L’. Factorizations leave the other triangle as it was, so a routine reading
the whole matrix needs it cleared. Aborts if cm is not square or UL is invalid.
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.