diff --git a/src/bigintegerR.cc b/src/bigintegerR.cc index 666510850002e4356917db17d805843604d27670..395d8d971c77ed4c51a8358070b241885f0c4101 100644 --- a/src/bigintegerR.cc +++ b/src/bigintegerR.cc @@ -142,7 +142,7 @@ namespace bigintegerR { //std::cout << "import value" << std::endl; bigvec vMod = bigintegerR::create_vector(modAttr); - for (int i = 0 ; i < v.size(); i++){ + for (unsigned int i = 0 ; i < v.size(); i++){ v[i].setModulus(vMod[i % vMod.size()].getValuePtr()); } v.setType(vMod.size() == 1 ? TYPE_MODULUS::MODULUS_GLOBAL : TYPE_MODULUS::MODULUS_BY_CELL); @@ -177,7 +177,7 @@ namespace bigintegerR } - SEXP create_SEXP(const bigvec & v , bigmod_accessor_fn fct, int size) + SEXP create_SEXP(const bigvec & v , bigmod_accessor_fn fct, unsigned int size) { unsigned int i; int sizeRaw = sizeof(int); // starting with vector-size-header @@ -359,9 +359,9 @@ SEXP biginteger_div (SEXP a, SEXP b) { // called from "/.bigz" == div.bigz } else { // len_m_a > 0 and len_m_b > 0: bool same_mod = true;// are the two mods the "same" (after recycling)? - int len_m_a = A.getModulusSize(); - int len_m_b = B.getModulusSize(); - int m = (len_m_a < len_m_b) ? len_m_b : len_m_a; // = max(l..a, l..b) + unsigned int len_m_a = A.getModulusSize(); + unsigned int len_m_b = B.getModulusSize(); + unsigned int m = (len_m_a < len_m_b) ? len_m_b : len_m_a; // = max(l..a, l..b) for(unsigned int i = 0; i < m; i++) if(A[i % len_m_a].getModulus() != B[i % len_m_b].getModulus()) { same_mod = false; break; diff --git a/src/bigvec.cc b/src/bigvec.cc index 2a4b8544369b5be7c4e51fc38bdda4647240b474..8be847a785065f51e6becb6703d40230ea887048 100644 --- a/src/bigvec.cc +++ b/src/bigvec.cc @@ -12,13 +12,13 @@ bigvec::bigvec(unsigned int size) : math::Matrix<bigmod>(), values(), type(NO_MODULUS), - nrow(-1), - modulus() + modulus(), + nrow(-1) { count++; countAll++; - for (int i=0 ; i < size; i++){ + for (unsigned int i=0 ; i < size; i++){ values.push_back(bigmod()); } } @@ -28,8 +28,8 @@ bigvec::bigvec(const bigvec & vecteur) : math::Matrix<bigmod>(), values(), type(vecteur.type), - nrow(vecteur.nrow), - modulus(vecteur.modulus) + modulus(vecteur.modulus), + nrow(vecteur.nrow) { count++; countAll++; @@ -224,7 +224,7 @@ void bigvec::print() void bigvec::setGlobalModulus(std::shared_ptr<biginteger> & val){ modulus = val; type = MODULUS_GLOBAL; - for (int i = 0 ; i < values.size(); i++){ + for (unsigned int i = 0 ; i < values.size(); i++){ values[i].setModulus(val); } } diff --git a/src/matrix.cc b/src/matrix.cc index 3b9f349ebd30a79d7744e1337919d4d93cd9d425..39628378d21a4b8507627ebb4fe7ee59c40c436e 100644 --- a/src/matrix.cc +++ b/src/matrix.cc @@ -5,7 +5,7 @@ * \version 1 * * \date Created: 19/02/06 - * \date Last modified: Time-stamp: <2023-01-21 21:18:14 (antoine)> + * \date Last modified: Time-stamp: <2023-01-21 21:33:01 (antoine)> * * \author A. Lucas * @@ -109,7 +109,7 @@ SEXP as_matrixz (SEXP x, SEXP nrR, SEXP ncR, SEXP byrowR, SEXP mod) - if(modulus.size()>0) // should be allways the case + if(modulus.size()>0) {// should be allways the case if(modulus[0].isNA()) { // nothing but mat could have already a modulus } else { @@ -122,7 +122,7 @@ SEXP as_matrixz (SEXP x, SEXP nrR, SEXP ncR, SEXP byrowR, SEXP mod) mat.setType( modulus.size() == 1 ? TYPE_MODULUS::MODULUS_GLOBAL : TYPE_MODULUS::MODULUS_BY_CELL); // sizemod = modulus.size(); } - + } if(byrow) { @@ -283,8 +283,7 @@ SEXP matrix_mul_z (SEXP a, SEXP b, SEXP op) mat_b = bigintegerR::create_bignum(b); - int sizemod_a = mat_a.getModulusSize(), - sizemod_b = mat_b.getModulusSize(); + int a_nrow = mat_a.nrow, a_len = mat_a.size(), @@ -474,7 +473,7 @@ SEXP matrix_mul_z (SEXP a, SEXP b, SEXP op) */ SEXP biginteger_rbind(SEXP args) { - int i=0,j=0; + bigvec result; vector<bigvec*> source; unsigned int maxSize=0; @@ -482,9 +481,9 @@ SEXP biginteger_rbind(SEXP args) bigvec v = bigintegerR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; - for (int row = 0 ; row < v.nRows(); row++){ + for (unsigned int row = 0 ; row < v.nRows(); row++){ bigvec * line = new bigvec(); - for(int col = 0 ; col < v.nCols(); col++){ + for(unsigned int col = 0 ; col < v.nCols(); col++){ line->push_back(v.get(row,col)); } source.push_back(line); @@ -494,15 +493,15 @@ SEXP biginteger_rbind(SEXP args) - for (int j = 0 ; j < maxSize; j++){ - for(int i = 0 ; i < source.size() ; i++){ + for (unsigned int j = 0 ; j < maxSize; j++){ + for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec * u = source[i]; if(u->size() == 0) result.push_back(bigmod()); else result.push_back((*u)[j % u->size()]); } } result.nrow = source.size(); - for (int i = 0 ; i < source.size() ; i++){ + for (unsigned int i = 0 ; i < source.size() ; i++){ if(source[i] != nullptr) delete source[i]; source[i] = nullptr; } @@ -516,7 +515,7 @@ SEXP biginteger_rbind(SEXP args) */ SEXP biginteger_cbind(SEXP args) { - int i=0,j=0; + bigvec result; vector<bigvec*> source; unsigned int maxSize=0; @@ -525,9 +524,9 @@ SEXP biginteger_cbind(SEXP args) if(v.size() == 0) continue; if(v.nrow <0) v.nrow = v.size(); - for(int col = 0 ; col < v.nCols(); col++){ + for(unsigned int col = 0 ; col < v.nCols(); col++){ bigvec * column = new bigvec(); - for (int row = 0 ; row < v.nRows(); row++){ + for (unsigned int row = 0 ; row < v.nRows(); row++){ column->push_back(v.get(row,col)); } source.push_back(column); @@ -535,15 +534,15 @@ SEXP biginteger_cbind(SEXP args) } } - for(int i = 0 ; i < source.size() ; i++){ + for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec * u = source[i]; - for (int j = 0 ; j < maxSize; j++){ + for (unsigned int j = 0 ; j < maxSize; j++){ if(u->size() == 0) result.push_back(bigmod()); else result.push_back((*u)[j % u->size()]); } } result.nrow = result.size() / source.size(); - for (int i = 0 ; i < source.size() ; i++){ + for (unsigned int i = 0 ; i < source.size() ; i++){ if(source[i] != nullptr) delete source[i]; source[i] = nullptr; } diff --git a/src/matrixq.cc b/src/matrixq.cc index ef8d6e7f827ad0e809d62e0bf050f25e86da9511..0c688aec409379e17ac6c446392d953de0a8fb8b 100644 --- a/src/matrixq.cc +++ b/src/matrixq.cc @@ -5,7 +5,7 @@ * \version 1 * * \date Created: 19/02/06 - * \date Last modified: Time-stamp: <2023-01-21 16:26:18 (antoine)> + * \date Last modified: Time-stamp: <2023-01-21 21:40:12 (antoine)> * * \author A. Lucas * @@ -163,7 +163,7 @@ SEXP matrix_crossp_q (SEXP a, SEXP trans) int a_ncol = a_len / a_nrow; // Result R is R[1..m, 1..m] -- and R_{ij} = sum_{k=1}^p A.. B.. - int m, p; + unsigned int m, p; if(tr) { // tcrossprod() m= a_nrow; p= a_ncol; } else { // crossprod() @@ -177,12 +177,12 @@ SEXP matrix_crossp_q (SEXP a, SEXP trans) mpq_init(tt); // here the computation: - for(int i=0; i < m; i++) - for(int j=0; j < m; j++) { + for(unsigned int i=0; i < m; i++) + for(unsigned int j=0; j < m; j++) { mpq_set_ui(R_ij, 0,1); bool isna = false; #define K_LOOP \ - for(int k=0; k < p; k++) { \ + for(unsigned int k=0; k < p; k++) { \ /* R_ij = \sum_{k=1}^p a_{ik} b_{kj} */ \ if( !(A_I_K.isNA() || B_K_J.isNA())) { \ mpq_mul(tt, A_I_K.getValueTemp(), B_K_J.getValueTemp()); \ @@ -221,7 +221,7 @@ SEXP matrix_crossp_q (SEXP a, SEXP trans) mpq_clear(R_ij); mpq_clear(tt); - +#undef K_LOOP return( bigrationalR::create_SEXP (res)); } // matrix_crossp_q() @@ -408,18 +408,17 @@ SEXP matrix_mul_q (SEXP a, SEXP b, SEXP op) SEXP bigrational_rbind(SEXP args) { - int i=0,j=0; bigvec_q result; bigvec_q v; vector<bigvec_q> source; unsigned int maxSize=0; - for(int i = 0 ; i < LENGTH(args) ; i++){ + for( int i = 0 ; i < LENGTH(args) ; i++){ v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; - for (int row = 0 ; row < v.nRows(); row++){ + for (unsigned int row = 0 ; row < v.nRows(); row++){ bigvec_q line ; - for(int col = 0 ; col < v.nCols(); col++){ + for(unsigned int col = 0 ; col < v.nCols(); col++){ line.push_back(v.get(row,col)); } source.push_back(line); @@ -427,8 +426,8 @@ SEXP bigrational_rbind(SEXP args) } } - for (int j = 0 ; j < maxSize; j++){ - for(int i = 0 ; i < source.size() ; i++){ + for (unsigned int j = 0 ; j < maxSize; j++){ + for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec_q u = source[i]; if(u.size() == 0) result.push_back(bigrational()); else result.push_back(u[j % u.size()]); @@ -440,19 +439,18 @@ SEXP bigrational_rbind(SEXP args) } SEXP bigrational_cbind(SEXP args){ - int i=0,j=0; bigvec_q result; bigvec_q v; vector<bigvec_q> source; unsigned int maxSize=0; - for(int i = 0 ; i < LENGTH(args) ; i++){ + for( int i = 0 ; i < LENGTH(args) ; i++){ v = bigrationalR::create_bignum(VECTOR_ELT(args,i)); if(v.size() == 0) continue; if(v.nrow <0) v.nrow = v.size(); - for(int col = 0 ; col < v.nCols(); col++){ + for(unsigned int col = 0 ; col < v.nCols(); col++){ bigvec_q column ; - for (int row = 0 ; row < v.nRows(); row++){ + for (unsigned int row = 0 ; row < v.nRows(); row++){ column.push_back(v.get(row,col)); } source.push_back(column); @@ -460,9 +458,9 @@ SEXP bigrational_cbind(SEXP args){ } } - for(int i = 0 ; i < source.size() ; i++){ + for(unsigned int i = 0 ; i < source.size() ; i++){ bigvec_q u = source[i]; - for (int j = 0 ; j < maxSize; j++){ + for (unsigned int j = 0 ; j < maxSize; j++){ if(u.size() == 0) result.push_back(bigrational()); else result.push_back(u[j % u.size()]); } diff --git a/src/solve.cc b/src/solve.cc index b4d87b734e8fca1e06664285ed8151ed8d46040c..8c1e48a18cd3287c486f296e33870fed2936a854 100644 --- a/src/solve.cc +++ b/src/solve.cc @@ -4,7 +4,7 @@ * \version 1 * * \date Created: 25/05/06 - * \date Last modified: Time-stamp: <2023-01-21 13:18:55 (antoine)> + * \date Last modified: Time-stamp: <2023-01-21 21:28:50 (antoine)> * * \author A. Lucas * @@ -78,7 +78,6 @@ SEXP inverse_z (SEXP A) // solve AX=B SEXP solve_z(SEXP A,SEXP B) { - bool common_modulus=true; bigvec a = bigintegerR::create_bignum(A); bigvec b = bigintegerR::create_bignum(B);