LADEL main
Sparse LDL factorization package with rank 1 and rowadd/rowdel updates
ladel_submatrix.c
Go to the documentation of this file.
1#include "ladel_types.h"
2#include "ladel_global.h"
3
5{
6 if (!M) return NULL;
7 if (!cols) return ladel_sparse_alloc_empty(M->nrow, M->ncol, M->symmetry, M->values, FALSE);
8
9 ladel_int index, col, nnz = 0, index_M;
10 for (index = 0; index < nb_cols; index++)
11 {
12 col = cols[index];
13 nnz += (M->nz) ? M->nz[col] : M->p[col+1] - M->p[col];
14 }
15
16 if (nnz == 0) return ladel_sparse_alloc_empty(M->nrow, M->ncol, M->symmetry, M->values, FALSE);
17
18 ladel_sparse_matrix *M_sub = ladel_sparse_alloc(M->nrow, nb_cols, nnz, M->symmetry, M->values, FALSE);
19 nnz = 0;
20 M_sub->p[0] = 0;
21 for (index = 0; index < nb_cols; index++)
22 {
23 col = cols[index];
24 LADEL_FOR(index_M, M, col)
25 {
26 M_sub->i[nnz] = M->i[index_M];
27 M_sub->x[nnz] = M->x[index_M];
28 nnz++;
29 }
30 M_sub->p[index+1] = nnz;
31 }
32
33 return M_sub;
34}
#define FALSE
For booleans.
#define LADEL_FOR(index, M, col)
Loop through a column of a sparse matrix.
Memory allocation routines.
ladel_sparse_matrix * ladel_sparse_alloc(ladel_int nrow, ladel_int ncol, ladel_int nzmax, ladel_int symmetry, ladel_int values, ladel_int nz)
Allocate a sparse matrix.
Definition: ladel_global.c:101
ladel_sparse_matrix * ladel_sparse_alloc_empty(ladel_int nrow, ladel_int ncol, ladel_int symmetry, ladel_int values, ladel_int nz)
Allocate a sparse empty matrix (used in special cases).
Definition: ladel_global.c:122
ladel_sparse_matrix * ladel_column_submatrix(const ladel_sparse_matrix *M, const ladel_int *cols, ladel_int nb_cols)
Returns a matrix that is a selection of columns of M, that is .
Structures and types used in LADEL routines.
int64_t ladel_int
Type for integer numbers (default: int64_t)
Definition: ladel_types.h:24
Sparse matrix in compressed column storage.
Definition: ladel_types.h:35
ladel_int symmetry
type of symmetry (UNSYMMETRIC, UPPER or LOWER)
Definition: ladel_types.h:46
ladel_int ncol
number of columns
Definition: ladel_types.h:38
ladel_double * x
numerical values (size nzmax)
Definition: ladel_types.h:42
ladel_int * p
column pointers (size ncol+1)
Definition: ladel_types.h:40
ladel_int * nz
(optional) number of elements in each column (size ncol)
Definition: ladel_types.h:43
ladel_int values
has numerical values
Definition: ladel_types.h:45
ladel_int nrow
number of rows
Definition: ladel_types.h:37
ladel_int * i
row pointers (size nzmax)
Definition: ladel_types.h:41