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.

Ancestors

Constructors

ncm_matrix_const_new_data

Creates a constant matrix over d, which must outlive it.

ncm_matrix_const_new_variant

Creates a constant matrix over the data of var, holding a reference to it.

ncm_matrix_new

Allocates a matrix, not initialized.

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_data_slice

Creates a matrix over d, which it takes ownership of.

ncm_matrix_new_data_static

Creates a matrix over d, which must outlive it.

ncm_matrix_new_data_static_tda

Creates a matrix over d, which must outlive it.

ncm_matrix_new_full

Creates a matrix over d; pfree is called on pdata when the matrix is finalized.

ncm_matrix_new_gsl

Creates a matrix over gm, which it takes ownership of and frees with gsl_matrix_free().

ncm_matrix_new_gsl_const

Creates a constant matrix over gm, which must outlive it.

ncm_matrix_new_gsl_static

Creates a matrix over gm, which must outlive it.

ncm_matrix_new_variant

Creates a matrix with a copy of the elements of var.

Functions

ncm_matrix_clear

If cm is not NULL, decreases its reference count by one and sets cm to NULL.

ncm_matrix_new0

Allocates a matrix with every element zero.

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_add

Adds cm2 to cm1; they must have the same shape.

ncm_matrix_add_constant

Adds val to every element.

ncm_matrix_add_mul

Sets $M_1 \to M_1 + a M_2$.

ncm_matrix_addto

Adds val to the element ($i$, $j$).

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_cmp
No description available.

ncm_matrix_cmp_diag

Same as ncm_matrix_cmp() over the diagonal only.

ncm_matrix_col_len

Same as ncm_matrix_nrows().

ncm_matrix_const_data
No description available.

ncm_matrix_const_free

Decreases the reference count of cm by one.

ncm_matrix_const_gsl
No description available.

ncm_matrix_const_ptr
No description available.

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_cov_dup_cor
No description available.

ncm_matrix_data
No description available.

ncm_matrix_dgemm

Sets $C \to \alpha\,\mathrm{op}(A)\,\mathrm{op}(B) + \beta C$.

ncm_matrix_div_elements

Divides cm1 by cm2, element by element; they must have the same shape.

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_dup
No description available.

ncm_matrix_dup_array
No description available.

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_free

Decreases the reference count of cm by one.

ncm_matrix_get
No description available.

ncm_matrix_get_array

cm must have been created by ncm_matrix_new_array().

ncm_matrix_get_col

Creates a view of the column col, holding a reference to cm.

ncm_matrix_get_colmajor

Reads the data of cm in column-major order.

ncm_matrix_get_diag

Copies the diagonal of cm to the first entries of diag.

ncm_matrix_get_row

Creates a view of the row row, holding a reference to cm.

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_get_variant
No description available.

ncm_matrix_gsl
No description available.

ncm_matrix_is_identity

Aborts if cm is not square.

ncm_matrix_log_vals

Logs the elements of cm, one row per line.

ncm_matrix_memcpy

Copies cm2 into cm1; they must have the same shape.

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_mul_col

Multiplies the column col_i by val.

ncm_matrix_mul_elements

Multiplies cm1 by cm2, element by element; they must have the same shape.

ncm_matrix_mul_row

Multiplies the row row_i by val.

ncm_matrix_ncols
No description available.

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_nrows
No description available.

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_ptr
No description available.

ncm_matrix_ref

Increases the reference count of cm by one.

ncm_matrix_row_len

Same as ncm_matrix_ncols().

ncm_matrix_scale

Multiplies every element by val.

ncm_matrix_scale_cols

Sets $M \to M\,\mathrm{diag}(s)$.

ncm_matrix_scale_rows

Sets $M \to \mathrm{diag}(s)\,M$.

ncm_matrix_set

Sets the element ($i$, $j$) to val.

ncm_matrix_set_all

Sets every element to val.

ncm_matrix_set_col

Copies cv into the column n; its length must be the number of rows.

ncm_matrix_set_colmajor

Sets the element ($i$, $j$), in column-major order, to val.

ncm_matrix_set_diag

Sets the diagonal of cm to the first entries of diag.

ncm_matrix_set_from_array

Sets the elements of cm; a must hold as many values as cm has elements.

ncm_matrix_set_from_data

Sets the elements of cm; data must hold as many values as cm has elements.

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_set_identity

Sets cm, square or not, to one on the diagonal and zero elsewhere.

ncm_matrix_set_row

Copies cv into the row n; its length must be the number of columns.

ncm_matrix_set_zero

Sets every element to zero.

ncm_matrix_size
No description available.

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_sub

Subtracts cm2 from cm1; they must have the same shape.

ncm_matrix_sub_row_vector

Sets $M_{ij} \to M_{ij} - v_j$, subtracting v from every row.

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_tda
No description available.

ncm_matrix_transpose

Transposes the square cm in place.

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.

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

NumCosmoMath.Matrix:values

GVariant representation of the matrix used to serialize the object.

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.

Class structure

struct NumCosmoMathMatrixClass {
  GObjectClass parent_class;
  
}

No description available.

Class members
parent_class: GObjectClass

No description available.