Skip to content

Commit

Permalink
Improve const-correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Mar 6, 2024
1 parent b2e2835 commit 4656913
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
28 changes: 14 additions & 14 deletions LADEL/include/ladel_add.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ extern "C" {
* @param work LADEL workspace
* @return @f$C = \alpha A + \beta B@f$
*/
ladel_sparse_matrix *ladel_add_matrices(ladel_double alpha,
ladel_sparse_matrix *A,
ladel_double beta,
ladel_sparse_matrix *B,
ladel_work *work);
ladel_sparse_matrix *ladel_add_matrices(ladel_double alpha,
const ladel_sparse_matrix *A,
ladel_double beta,
const ladel_sparse_matrix *B,
ladel_work *work);

/**
* Returns a pattern matrix whose pattern includes the patterns of @a A and @a B.
Expand All @@ -39,9 +39,9 @@ ladel_sparse_matrix *ladel_add_matrices(ladel_double alpha,
* @param work LADEL workspace
* @return A sparse matrix whose pattern contains that of @a A and @a B
*/
ladel_sparse_matrix *ladel_add_matrices_pattern(ladel_sparse_matrix* A,
ladel_sparse_matrix *B,
ladel_work *work);
ladel_sparse_matrix *ladel_add_matrices_pattern(const ladel_sparse_matrix *A,
const ladel_sparse_matrix *B,
ladel_work *work);

/**
* Returns a sparse matrix @f$C = \alpha A + \beta B@f$ if @a values==TRUE, or a pattern matrix
Expand All @@ -55,12 +55,12 @@ ladel_sparse_matrix *ladel_add_matrices_pattern(ladel_sparse_matrix* A,
* @param work LADEL workspace
* @return @f$C = \alpha A + \beta B@f$ or the sum of the patterns
*/
ladel_sparse_matrix *ladel_add_matrices_advanced( ladel_double alpha,
ladel_sparse_matrix *A,
ladel_double beta,
ladel_sparse_matrix *B,
ladel_int values,
ladel_work *work);
ladel_sparse_matrix *ladel_add_matrices_advanced(ladel_double alpha,
const ladel_sparse_matrix *A,
ladel_double beta,
const ladel_sparse_matrix *B,
ladel_int values,
ladel_work *work);

#ifdef __cplusplus
}
Expand Down
30 changes: 15 additions & 15 deletions LADEL/include/ladel_matmat.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ extern "C" {
* @param work LADEL workspace
* @return @f$MM^T@f$
*/
ladel_sparse_matrix *ladel_mat_mat_transpose( ladel_sparse_matrix *M,
ladel_sparse_matrix *M_transpose,
ladel_work *work);
ladel_sparse_matrix *ladel_mat_mat_transpose(const ladel_sparse_matrix *M,
const ladel_sparse_matrix *M_transpose,
ladel_work *work);

/**
* Computes the pattern of @f$MM^T@f$.
Expand All @@ -34,9 +34,9 @@ ladel_sparse_matrix *ladel_mat_mat_transpose( ladel_sparse_matrix *M,
* @param work LADEL workspace
* @return The patter of @f$MM^T@f$
*/
ladel_sparse_matrix *ladel_mat_mat_transpose_pattern( ladel_sparse_matrix *M,
ladel_sparse_matrix *M_transpose,
ladel_work *work);
ladel_sparse_matrix *ladel_mat_mat_transpose_pattern(const ladel_sparse_matrix *M,
const ladel_sparse_matrix *M_transpose,
ladel_work *work);

/**
* Computes @f$M\Sigma M^T@f$.
Expand All @@ -46,10 +46,10 @@ ladel_sparse_matrix *ladel_mat_mat_transpose_pattern( ladel_sparse_matrix *M,
* @param diag Array containing the diagonal of @f$\Sigma@f$
* @param work LADEL workspace
*/
ladel_sparse_matrix *ladel_mat_diag_mat_transpose( ladel_sparse_matrix *M,
ladel_sparse_matrix *M_transpose,
ladel_double *diag,
ladel_work *work);
ladel_sparse_matrix *ladel_mat_diag_mat_transpose(const ladel_sparse_matrix *M,
const ladel_sparse_matrix *M_transpose,
const ladel_double *diag,
ladel_work *work);

/**
* Core mat_mat_transpose function with all options (diag and value/pattern).
Expand All @@ -63,11 +63,11 @@ ladel_sparse_matrix *ladel_mat_diag_mat_transpose( ladel_sparse_matrix *M,
* @param values Values or pattern computation
* @param work LADEL workspace
*/
ladel_sparse_matrix *ladel_mat_mat_transpose_advanced( ladel_sparse_matrix *M,
ladel_sparse_matrix *M_transpose,
ladel_double *diag,
ladel_int values,
ladel_work *work);
ladel_sparse_matrix *ladel_mat_mat_transpose_advanced(const ladel_sparse_matrix *M,
const ladel_sparse_matrix *M_transpose,
const ladel_double *diag,
ladel_int values,
ladel_work *work);

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions LADEL/include/ladel_scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {
* @param S Array with scale factors for the columns
*/
void ladel_scale_columns( ladel_sparse_matrix *M,
ladel_double *S);
const ladel_double *S);

/**
* Scales the rows of @a M with the scalars in @a S, that is @f$M(i,:) = S(i)*M(i,:)@f$.
Expand All @@ -30,7 +30,7 @@ void ladel_scale_columns( ladel_sparse_matrix *M,
* @param S Array with scale factors for the rows
*/
void ladel_scale_rows( ladel_sparse_matrix *M,
ladel_double *S);
const ladel_double *S);

/**
* Scales the elements of @a M with @a s, that is @f$M = sM@f$.
Expand Down
6 changes: 3 additions & 3 deletions LADEL/include/ladel_submatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ extern "C" {
* @param nb_cols Number of columns to take (size of cols)
* @return @f$M(:,cols)@f$
*/
ladel_sparse_matrix *ladel_column_submatrix(ladel_sparse_matrix *M,
ladel_int *cols,
ladel_int nb_cols);
ladel_sparse_matrix *ladel_column_submatrix(const ladel_sparse_matrix *M,
const ladel_int *cols,
ladel_int nb_cols);

#ifdef __cplusplus
}
Expand Down
6 changes: 3 additions & 3 deletions LADEL/src/ladel_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
#include "ladel_types.h"
#include "ladel_add.h"

ladel_sparse_matrix *ladel_add_matrices(ladel_double alpha, ladel_sparse_matrix* A, ladel_double beta, ladel_sparse_matrix *B, ladel_work *work)
ladel_sparse_matrix *ladel_add_matrices(ladel_double alpha, const ladel_sparse_matrix* A, ladel_double beta, const ladel_sparse_matrix *B, ladel_work *work)
{
return ladel_add_matrices_advanced(alpha, A, beta, B, TRUE, work);
}

ladel_sparse_matrix *ladel_add_matrices_pattern(ladel_sparse_matrix* A, ladel_sparse_matrix *B, ladel_work *work)
ladel_sparse_matrix *ladel_add_matrices_pattern(const ladel_sparse_matrix* A, const ladel_sparse_matrix *B, ladel_work *work)
{
return ladel_add_matrices_advanced(0, A, 0, B, FALSE, work);
}

ladel_sparse_matrix *ladel_add_matrices_advanced(ladel_double alpha, ladel_sparse_matrix* A, ladel_double beta, ladel_sparse_matrix *B, ladel_int values, ladel_work *work)
ladel_sparse_matrix *ladel_add_matrices_advanced(ladel_double alpha, const ladel_sparse_matrix* A, ladel_double beta, const ladel_sparse_matrix *B, ladel_int values, ladel_work *work)
{
/* TODO: for different symmetries this will fail. */
if (!A || !B) return NULL;
Expand Down
8 changes: 4 additions & 4 deletions LADEL/src/ladel_matmat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
#include "ladel_copy.h"
#include "ladel_matmat.h"

ladel_sparse_matrix *ladel_mat_mat_transpose(ladel_sparse_matrix *M, ladel_sparse_matrix *M_transpose, ladel_work *work)
ladel_sparse_matrix *ladel_mat_mat_transpose(const ladel_sparse_matrix *M, const ladel_sparse_matrix *M_transpose, ladel_work *work)
{
return ladel_mat_mat_transpose_advanced(M, M_transpose, NULL, TRUE, work);
}

ladel_sparse_matrix *ladel_mat_mat_transpose_pattern(ladel_sparse_matrix *M, ladel_sparse_matrix *M_transpose, ladel_work *work)
ladel_sparse_matrix *ladel_mat_mat_transpose_pattern(const ladel_sparse_matrix *M, const ladel_sparse_matrix *M_transpose, ladel_work *work)
{
return ladel_mat_mat_transpose_advanced(M, M_transpose, NULL, FALSE, work);
}

ladel_sparse_matrix *ladel_mat_diag_mat_transpose(ladel_sparse_matrix *M, ladel_sparse_matrix *M_transpose, ladel_double *diag, ladel_work *work)
ladel_sparse_matrix *ladel_mat_diag_mat_transpose(const ladel_sparse_matrix *M, const ladel_sparse_matrix *M_transpose, const ladel_double *diag, ladel_work *work)
{
return ladel_mat_mat_transpose_advanced(M, M_transpose, diag, TRUE, work);
}

ladel_sparse_matrix *ladel_mat_mat_transpose_advanced(ladel_sparse_matrix *M, ladel_sparse_matrix *M_transpose, ladel_double *diag, ladel_int values, ladel_work *work)
ladel_sparse_matrix *ladel_mat_mat_transpose_advanced(const ladel_sparse_matrix *M, const ladel_sparse_matrix *M_transpose, const ladel_double *diag, ladel_int values, ladel_work *work)
{
if (!M || !M_transpose || !work) return NULL;

Expand Down
4 changes: 2 additions & 2 deletions LADEL/src/ladel_scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include "ladel_scale.h"


void ladel_scale_columns(ladel_sparse_matrix* M, ladel_double* S)
void ladel_scale_columns(ladel_sparse_matrix* M, const ladel_double* S)
{
ladel_int col, index;
for (col = 0; col < M->ncol; col++)
LADEL_FOR(index, M, col)
M->x[index] *= S[col];
}

void ladel_scale_rows(ladel_sparse_matrix* M, ladel_double* S)
void ladel_scale_rows(ladel_sparse_matrix* M, const ladel_double* S)
{
ladel_int index;
for (index = 0; index < M->nzmax; index++)
Expand Down
2 changes: 1 addition & 1 deletion LADEL/src/ladel_submatrix.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ladel_types.h"
#include "ladel_global.h"

ladel_sparse_matrix *ladel_column_submatrix(ladel_sparse_matrix *M, ladel_int* cols, ladel_int nb_cols)
ladel_sparse_matrix *ladel_column_submatrix(const ladel_sparse_matrix *M, const ladel_int* cols, ladel_int nb_cols)
{
if (!M) return NULL;
if (!cols) return ladel_sparse_alloc_empty(M->nrow, M->ncol, M->symmetry, M->values, FALSE);
Expand Down

0 comments on commit 4656913

Please sign in to comment.