Matrix

Matrix — Allocation and access.

Synopsis

#define             NCM_MATRIX_COL_LEN                  (cm)
#define             NCM_MATRIX_DATA                     (cm)
#define             NCM_MATRIX_GSL                      (cm)
#define             NCM_MATRIX_NCOLS                    (cm)
#define             NCM_MATRIX_NROWS                    (cm)
#define             NCM_MATRIX_ROW_LEN                  (cm)
struct              NcmMatrix;
struct              NcmMatrixClass;
enum                NcmMatrixInternal;
NcmMatrix *         ncm_matrix_copy                     (const NcmMatrix *cm);
void                ncm_matrix_free                     (NcmMatrix *cm);
gdouble             ncm_matrix_get                      (const NcmMatrix *cm,
                                                         const guint i,
                                                         const guint j);
GArray *            ncm_matrix_get_array                (NcmMatrix *cm);
NcmVector *         ncm_matrix_get_col                  (NcmMatrix *cm,
                                                         const gsize col);
NcmVector *         ncm_matrix_get_row                  (NcmMatrix *cm,
                                                         const gsize row);
NcmMatrix *         ncm_matrix_get_submatrix            (NcmMatrix *cm,
                                                         const gsize k1,
                                                         const gsize k2,
                                                         const gsize nrows,
                                                         const gsize ncols);
void                ncm_matrix_memcpy                   (NcmMatrix *cm1,
                                                         const NcmMatrix *cm2);
NcmMatrix *         ncm_matrix_new                      (const gsize nrows,
                                                         const gsize ncols);
NcmMatrix *         ncm_matrix_new_array                (GArray *a,
                                                         const gsize ncols);
NcmMatrix *         ncm_matrix_new_data_malloc          (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize ncols);
NcmMatrix *         ncm_matrix_new_data_slice           (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize ncols);
NcmMatrix *         ncm_matrix_new_data_static          (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize ncols);
NcmMatrix *         ncm_matrix_new_data_static_tda      (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize ncols,
                                                         const gsize tda);
NcmMatrix *         ncm_matrix_new_gsl                  (gsl_matrix *gm);
const NcmMatrix *   ncm_matrix_new_gsl_const            (gsl_matrix *m);
gdouble *           ncm_matrix_ptr                      (NcmMatrix *cm,
                                                         const guint i,
                                                         const guint j);
NcmMatrix *         ncm_matrix_ref                      (NcmMatrix *cm);
void                ncm_matrix_scale                    (NcmMatrix *cm,
                                                         const gdouble val);
void                ncm_matrix_set                      (NcmMatrix *cm,
                                                         const guint i,
                                                         const guint j,
                                                         const gdouble val);
void                ncm_matrix_set_col                  (NcmMatrix *cm,
                                                         const guint n,
                                                         const NcmVector *cv);
void                ncm_matrix_set_identity             (NcmMatrix *cm);
void                ncm_matrix_set_zero                 (NcmMatrix *cm);
void                ncm_matrix_transpose                (NcmMatrix *cm);

Object Hierarchy

  GObject
   +----GInitiallyUnowned
         +----NcmMatrix

Description

This object defines the functions for allocating and accessing matrices.

Details

NCM_MATRIX_COL_LEN()

#define NCM_MATRIX_COL_LEN(cm) ((cm)->mv.matrix.size1)

NCM_MATRIX_DATA()

#define NCM_MATRIX_DATA(cm) ((cm)->mv.matrix.data)

NCM_MATRIX_GSL()

#define NCM_MATRIX_GSL(cm) (&(cm)->mv.matrix)

NCM_MATRIX_NCOLS()

#define NCM_MATRIX_NCOLS(cm) ((cm)->mv.matrix.size2)

NCM_MATRIX_NROWS()

#define NCM_MATRIX_NROWS(cm) ((cm)->mv.matrix.size1)

NCM_MATRIX_ROW_LEN()

#define NCM_MATRIX_ROW_LEN(cm) ((cm)->mv.matrix.size2)

struct NcmMatrix

struct NcmMatrix;

FIXME


struct NcmMatrixClass

struct NcmMatrixClass {
};

enum NcmMatrixInternal

typedef enum {
  NCM_MATRIX_SLICE = 0,
  NCM_MATRIX_GSL_MATRIX,
  NCM_MATRIX_MALLOC,
  NCM_MATRIX_GARRAY,
  NCM_MATRIX_DERIVED,
} NcmMatrixInternal;

FIXME

NCM_MATRIX_SLICE

FIXME

NCM_MATRIX_GSL_MATRIX

FIXME

NCM_MATRIX_MALLOC

FIXME

NCM_MATRIX_GARRAY

FIXME

NCM_MATRIX_DERIVED

FIXME

ncm_matrix_copy ()

NcmMatrix *         ncm_matrix_copy                     (const NcmMatrix *cm);

Duplicates cm setting the same values of the original propertities.

cm :

a constant NcmMatrix

Returns :

A NcmMatrix. [transfer full]

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.

cm :

a NcmMatrix.

ncm_matrix_get ()

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

cm :

a constant NcmMatrix.

i :

row index.

j :

column index.

Returns :

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

ncm_matrix_get_array ()

GArray *            ncm_matrix_get_array                (NcmMatrix *cm);

FIXME

cm :

a NcmMatrix.

Returns :

FIXME. [transfer container][element-type double]

ncm_matrix_get_col ()

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

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

cm :

a NcmMatrix.

col :

column index.

Returns :

A NcmVector. [transfer full]

ncm_matrix_get_row ()

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

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

cm :

a NcmMatrix.

row :

row index.

Returns :

A NcmVector. [transfer full]

ncm_matrix_get_submatrix ()

NcmMatrix *         ncm_matrix_get_submatrix            (NcmMatrix *cm,
                                                         const gsize k1,
                                                         const gsize k2,
                                                         const gsize nrows,
                                                         const gsize 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.

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_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.

cm1 :

a NcmMatrix.

cm2 :

a NcmMatrix.

ncm_matrix_new ()

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

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

nrows :

number of rows.

ncols :

number of columns.

Returns :

A new NcmMatrix.

ncm_matrix_new_array ()

NcmMatrix *         ncm_matrix_new_array                (GArray *a,
                                                         const gsize 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.

a :

GArray of doubles to be converted into a NcmMatrix.

ncols :

number of columns.

Returns :

A new NcmMatrix.

ncm_matrix_new_data_malloc ()

NcmMatrix *         ncm_matrix_new_data_malloc          (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize 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.

d :

pointer to the first double allocated.

nrows :

number of rows.

ncols :

number of columns.

Returns :

A new NcmMatrix.

ncm_matrix_new_data_slice ()

NcmMatrix *         ncm_matrix_new_data_slice           (gdouble *d,
                                                         const gsize nrows,
                                                         const gsize 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.

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 gsize nrows,
                                                         const gsize 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.

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 gsize nrows,
                                                         const gsize ncols,
                                                         const gsize 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.

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_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.

gm :

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

Returns :

A new NcmMatrix.

ncm_matrix_new_gsl_const ()

const NcmMatrix *   ncm_matrix_new_gsl_const            (gsl_matrix *m);

This function converts m into a constant NcmMatrix.

m :

matrix from GNU Scientific Library (GSL).

Returns :

A new constant NcmMatrix.

ncm_matrix_ptr ()

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

cm :

a NcmMatrix.

i :

row index.

j :

column index.

Returns :

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

ncm_matrix_ref ()

NcmMatrix *         ncm_matrix_ref                      (NcmMatrix *cm);

Increase the reference count of cm by one.

cm :

a NcmMatrix.

Returns :

cm. [transfer full]

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.

cm :

a NcmMatrix.

val :

a 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.

cm :

a NcmMatrix.

i :

row index.

j :

column index.

val :

a double.

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.

cm :

a NcmMatrix.

n :

column index.

cv :

a constant NcmVector.

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.

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.

cm :

a NcmMatrix.

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.

cm :

a NcmMatrix.