This is an automated email from the git hooks/post-receive script. logari81 pushed a commit to branch master in repository getfem.
The following commit(s) were added to refs/heads/master by this push: new 90a30c01 Remove const_cast occurrences 90a30c01 is described below commit 90a30c01a9f7cf0d39e254d69e6ac0cf1cd58a0b Author: Konstantinos Poulios <logar...@gmail.com> AuthorDate: Mon Mar 25 11:20:26 2024 +0100 Remove const_cast occurrences --- src/gmm/gmm_blas_interface.h | 59 ++++++++++++++++-------------------------- src/gmm/gmm_lapack_interface.h | 34 ++++++++++++------------ 2 files changed, 38 insertions(+), 55 deletions(-) diff --git a/src/gmm/gmm_blas_interface.h b/src/gmm/gmm_blas_interface.h index 71663bdd..07861ec5 100644 --- a/src/gmm/gmm_blas_interface.h +++ b/src/gmm/gmm_blas_interface.h @@ -210,8 +210,7 @@ namespace gmm { (const scaled_vector_const_ref<std::vector<base_type>,base_type> &x_, \ const std::vector<base_type> &y) { \ GMMLAPACK_TRACE("dot_interface"); \ - std::vector<base_type > &x = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(x_))); \ + const std::vector<base_type> &x = *(linalg_origin(x_)); \ base_type a(x_.r); \ BLAS_INT inc(1), n(BLAS_INT(vect_size(y))); \ return a* blas_name(&n, &x[0], &inc, &y[0], &inc); \ @@ -220,8 +219,7 @@ namespace gmm { (const std::vector<base_type> &x, \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &y_) {\ GMMLAPACK_TRACE("dot_interface"); \ - std::vector<base_type > &y = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(y_))); \ + const std::vector<base_type> &y = *(linalg_origin(y_)); \ base_type b(y_.r); \ BLAS_INT inc(1), n(BLAS_INT(vect_size(y))); \ return b* blas_name(&n, &x[0], &inc, &y[0], &inc); \ @@ -230,11 +228,9 @@ namespace gmm { (const scaled_vector_const_ref<std::vector<base_type>,base_type> &x_, \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &y_) {\ GMMLAPACK_TRACE("dot_interface"); \ - std::vector<base_type > &x = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(x_))); \ + const std::vector<base_type> &x = *(linalg_origin(x_)); \ base_type a(x_.r); \ - std::vector<base_type > &y = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(y_))); \ + const std::vector<base_type> &y = *(linalg_origin(y_)); \ base_type b(y_.r); \ BLAS_INT inc(1), n(BLAS_INT(vect_size(y))); \ return a* b* blas_name(&n, &x[0], &inc, &y[0], &inc); \ @@ -263,8 +259,7 @@ namespace gmm { # define dotc_p1_s(base_type) \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &x_ # define dotc_trans1_s(base_type) \ - std::vector<base_type > &x = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(x_))); \ + const std::vector<base_type> &x = *(linalg_origin(x_)); \ base_type a(x_.r) # define dotc_p2(base_type) const std::vector<base_type> &y @@ -272,8 +267,7 @@ namespace gmm { # define dotc_p2_s(base_type) \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &y_ # define dotc_trans2_s(base_type) \ - std::vector<base_type > &y = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(y_))); \ + const std::vector<base_type> &y = *(linalg_origin(y_)); \ base_type b(gmm::conj(y_.r)) dotc_interface(dotc_p1, dotc_trans1, (BLAS_S), @@ -421,8 +415,7 @@ namespace gmm { # define axpy_p1_s(base_type) \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &x_ # define axpy_trans1_s(base_type) \ - std::vector<base_type > &x = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(x_))); \ + const std::vector<base_type> &x = *(linalg_origin(x_)); \ base_type a(x_.r) axpy_interface(axpy_p1, axpy_trans1, saxpy_, BLAS_S) @@ -458,15 +451,15 @@ namespace gmm { # define gem_trans1_n(base_type) const char t = 'N' # define gem_p1_t(base_type) \ const transposed_col_ref<dense_matrix<base_type> *> &A_ -# define gem_trans1_t(base_type) dense_matrix<base_type > &A = \ - const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ +# define gem_trans1_t(base_type) const dense_matrix<base_type> &A = \ + *(linalg_origin(A_)); \ const char t = 'T' # define gem_p1_tc(base_type) \ - const transposed_col_ref<const dense_matrix<base_type > *> &A_ + const transposed_col_ref<const dense_matrix<base_type> *> &A_ # define gem_p1_c(base_type) \ const conjugated_col_matrix_const_ref<dense_matrix<base_type> > &A_ -# define gem_trans1_c(base_type) dense_matrix<base_type > &A = \ - const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ +# define gem_trans1_c(base_type) const dense_matrix<base_type> &A = \ + *(linalg_origin(A_)); \ const char t = 'C' // second parameter @@ -474,8 +467,8 @@ namespace gmm { # define gemv_trans2_n(base_type) base_type alpha(1) # define gemv_p2_s(base_type) \ const scaled_vector_const_ref<std::vector<base_type>,base_type> &x_ -# define gemv_trans2_s(base_type) std::vector<base_type > &x = \ - const_cast<std::vector<base_type > &>(*(linalg_origin(x_))); \ +# define gemv_trans2_s(base_type) const std::vector<base_type> &x = \ + (*(linalg_origin(x_))); \ base_type alpha(x_.r) // Z <- AX + Z. @@ -753,8 +746,7 @@ namespace gmm { const dense_matrix<base_type> &B, \ dense_matrix<base_type> &C, rcmult) { \ GMMLAPACK_TRACE("gemm_interface_tn"); \ - dense_matrix<base_type > &A \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ + const dense_matrix<base_type> &A = *(linalg_origin(A_)); \ const char t = 'T', u = 'N'; \ BLAS_INT m(BLAS_INT(mat_ncols(A))), k(BLAS_INT(mat_nrows(A))); \ BLAS_INT n(BLAS_INT(mat_ncols(B))); \ @@ -784,8 +776,7 @@ namespace gmm { const transposed_col_ref<is_const<base_type> *> &B_, \ dense_matrix<base_type> &C, r_mult) { \ GMMLAPACK_TRACE("gemm_interface_nt"); \ - dense_matrix<base_type > &B \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(B_))); \ + const dense_matrix<base_type> &B = *(linalg_origin(B_)); \ const char t = 'N', u = 'T'; \ BLAS_INT m(BLAS_INT(mat_nrows(A))), lda = m; \ BLAS_INT k(BLAS_INT(mat_ncols(A))); \ @@ -817,10 +808,8 @@ namespace gmm { const transposed_col_ref<isB_const <base_type> *> &B_, \ dense_matrix<base_type> &C, r_mult) { \ GMMLAPACK_TRACE("gemm_interface_tt"); \ - dense_matrix<base_type > &A \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ - dense_matrix<base_type > &B \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(B_))); \ + const dense_matrix<base_type> &A = *(linalg_origin(A_)); \ + const dense_matrix<base_type> &B = *(linalg_origin(B_)); \ const char t = 'T', u = 'T'; \ BLAS_INT m(BLAS_INT(mat_ncols(A))), k(BLAS_INT(mat_nrows(A))); \ BLAS_INT n(BLAS_INT(mat_nrows(B))); \ @@ -860,8 +849,7 @@ namespace gmm { const dense_matrix<base_type> &B, \ dense_matrix<base_type> &C, rcmult) { \ GMMLAPACK_TRACE("gemm_interface_cn"); \ - dense_matrix<base_type > &A \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ + const dense_matrix<base_type> &A = *(linalg_origin(A_)); \ const char t = 'C', u = 'N'; \ BLAS_INT m(BLAS_INT(mat_ncols(A))), k(BLAS_INT(mat_nrows(A))); \ BLAS_INT n(BLAS_INT(mat_ncols(B))); \ @@ -887,8 +875,7 @@ namespace gmm { const conjugated_col_matrix_const_ref<dense_matrix<base_type> > &B_, \ dense_matrix<base_type> &C, c_mult, row_major) { \ GMMLAPACK_TRACE("gemm_interface_nc"); \ - dense_matrix<base_type > &B \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(B_))); \ + const dense_matrix<base_type> &B = *(linalg_origin(B_)); \ const char t = 'N', u = 'C'; \ BLAS_INT m(BLAS_INT(mat_nrows(A))), lda = m; \ BLAS_INT k(BLAS_INT(mat_ncols(A))); \ @@ -915,10 +902,8 @@ namespace gmm { const conjugated_col_matrix_const_ref<dense_matrix<base_type> > &B_, \ dense_matrix<base_type> &C, r_mult) { \ GMMLAPACK_TRACE("gemm_interface_cc"); \ - dense_matrix<base_type > &A \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(A_))); \ - dense_matrix<base_type > &B \ - = const_cast<dense_matrix<base_type > &>(*(linalg_origin(B_))); \ + const dense_matrix<base_type> &A = *(linalg_origin(A_)); \ + const dense_matrix<base_type> &B = *(linalg_origin(B_)); \ const char t = 'C', u = 'C'; \ BLAS_INT m(BLAS_INT(mat_ncols(A))), k(BLAS_INT(mat_nrows(A))); \ BLAS_INT lda = k, n(BLAS_INT(mat_nrows(B))), ldb = n, ldc = m; \ diff --git a/src/gmm/gmm_lapack_interface.h b/src/gmm/gmm_lapack_interface.h index 7113432d..9a71da8d 100644 --- a/src/gmm/gmm_lapack_interface.h +++ b/src/gmm/gmm_lapack_interface.h @@ -152,10 +152,8 @@ namespace gmm { # define getri_interface(lapack_name, base_type) inline \ void lu_inverse(const dense_matrix<base_type> &LU, \ - const lapack_ipvt &ipvt, const dense_matrix<base_type> &A_) { \ + const lapack_ipvt &ipvt, dense_matrix<base_type> &A) { \ GMMLAPACK_TRACE("getri_interface"); \ - dense_matrix<base_type >& \ - A = const_cast<dense_matrix<base_type > &>(A_); \ BLAS_INT n = BLAS_INT(mat_nrows(A)), info(0), lwork(-1); \ base_type work1; \ if (n) { \ @@ -200,8 +198,8 @@ namespace gmm { // geqrf_interface(zgeqrf_, BLAS_Z) # define geqrf_interface2(lapack_name1, lapack_name2, base_type) inline \ - void qr_factor(const dense_matrix<base_type > &A, \ - dense_matrix<base_type > &Q, dense_matrix<base_type > &R) { \ + void qr_factor(const dense_matrix<base_type> &A, \ + dense_matrix<base_type> &Q, dense_matrix<base_type> &R) { \ GMMLAPACK_TRACE("geqrf_interface2"); \ BLAS_INT m = BLAS_INT(mat_nrows(A)), n=BLAS_INT(mat_ncols(A)); \ BLAS_INT info(0), lwork(-1); \ @@ -234,8 +232,8 @@ namespace gmm { # define gees_interface(lapack_name, base_type) \ template <typename VECT> inline void implicit_qr_algorithm( \ - const dense_matrix<base_type > &A, const VECT &eigval_, \ - dense_matrix<base_type> &Q, \ + const dense_matrix<base_type> &A, VECT &eigval_, \ + dense_matrix<base_type> &Q, \ double tol=gmm::default_tol(base_type()), bool compvect = true) { \ GMMLAPACK_TRACE("gees_interface"); \ typedef bool (*L_fp)(...); L_fp p = 0; \ @@ -252,13 +250,13 @@ namespace gmm { lapack_name(&jobvs, &sort, p, &n, &H(0,0), &n, &sdim, &eigv1[0], \ &eigv2[0], &Q(0,0), &n, &work[0], &lwork, &rwork[0],&info);\ GMM_ASSERT1(!info, "QR algorithm failed"); \ - extract_eig(H, const_cast<VECT &>(eigval_), tol); \ + extract_eig(H, eigval_, tol); \ } # define gees_interface2(lapack_name, base_type) \ template <typename VECT> inline void implicit_qr_algorithm( \ - const dense_matrix<base_type > &A, const VECT &eigval_, \ - dense_matrix<base_type > &Q, \ + const dense_matrix<base_type> &A, VECT &eigval_, \ + dense_matrix<base_type> &Q, \ double tol=gmm::default_tol(base_type()), bool compvect = true) { \ GMMLAPACK_TRACE("gees_interface2"); \ typedef bool (*L_fp)(...); L_fp p = 0; \ @@ -275,7 +273,7 @@ namespace gmm { lapack_name(&jobvs, &sort, p, &n, &H(0,0), &n, &sdim, &eigvv[0], \ &Q(0,0), &n, &work[0], &lwork, &rwork[0], &rwork[0],&info);\ GMM_ASSERT1(!info, "QR algorithm failed"); \ - extract_eig(H, const_cast<VECT &>(eigval_), tol); \ + extract_eig(H, eigval_, tol); \ } gees_interface(sgees_, BLAS_S) @@ -289,8 +287,8 @@ namespace gmm { # define geev_interface(lapack_name, base_type, side) \ template <typename VECT> inline void geev_interface_ ## side( \ - const dense_matrix<base_type > &A, const VECT &eigval_, \ - dense_matrix<base_type > &Q) { \ + const dense_matrix<base_type> &A, VECT &eigval_, \ + dense_matrix<base_type> &Q) { \ GMMLAPACK_TRACE("geev_interface"); \ BLAS_INT n = BLAS_INT(mat_nrows(A)), info(0), lwork(-1); \ base_type work1; \ @@ -305,14 +303,14 @@ namespace gmm { lapack_name(&jobvl, &jobvr, &n, &H(0,0), &n, &eigvr[0], &eigvi[0], \ &Q(0,0), &n, &Q(0,0), &n, &work[0], &lwork, &info); \ GMM_ASSERT1(!info, "QR algorithm failed"); \ - gmm::copy(eigvr, gmm::real_part(const_cast<VECT &>(eigval_))); \ - gmm::copy(eigvi, gmm::imag_part(const_cast<VECT &>(eigval_))); \ + gmm::copy(eigvr, gmm::real_part(eigval_)); \ + gmm::copy(eigvi, gmm::imag_part(eigval_)); \ } # define geev_interface2(lapack_name, base_type, side) \ template <typename VECT> inline void geev_interface_ ## side( \ - const dense_matrix<base_type > &A, const VECT &eigval_, \ - dense_matrix<base_type > &Q) { \ + const dense_matrix<base_type> &A, VECT &eigval_, \ + dense_matrix<base_type> &Q) { \ GMMLAPACK_TRACE("geev_interface"); \ BLAS_INT n = BLAS_INT(mat_nrows(A)), info(0), lwork(-1); \ base_type work1; \ @@ -328,7 +326,7 @@ namespace gmm { lapack_name(&jobvl, &jobvr, &n, &H(0,0), &n, &eigv[0], &Q(0,0), &n, \ &Q(0,0), &n, &work[0], &lwork, &rwork[0], &info); \ GMM_ASSERT1(!info, "QR algorithm failed"); \ - gmm::copy(eigv, const_cast<VECT &>(eigval_)); \ + gmm::copy(eigv, eigval_); \ } geev_interface(sgeev_, BLAS_S, right)