Skip to content

Commit be415a9

Browse files
committed
fixing vec/mat conversions
1 parent ae9083e commit be415a9

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

libsrc/eclib/matrix.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,19 @@
8686
#undef smat
8787
#undef smat_elim
8888

89-
mat_m to_mat_m(const mat_i& v);
90-
mat_m to_mat_m(const mat_l& v);
91-
mat_i to_mat_i(const mat_m& v);
92-
mat_l to_mat_l(const mat_m& v);
89+
// conversions between matrices of different scalar types
90+
91+
mat_m to_mat_m(const mat_i& m);
92+
mat_m to_mat_m(const mat_l& m);
93+
inline mat_m to_mat_m(const mat_m& m) {return m;}
94+
95+
mat_i to_mat_i(const mat_m& m);
96+
mat_i to_mat_i(const mat_l& m);
97+
inline mat_i to_mat_i(const mat_i& m) {return m;}
98+
99+
mat_l to_mat_l(const mat_m& m);
100+
mat_l to_mat_l(const mat_m& m);
101+
inline mat_l to_mat_l(const mat_l& m) {return m;}
93102

94103
#endif
95104

libsrc/eclib/splitbase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class splitter_base {
5353
public:
5454
virtual mat opmat(int,int,int=0) = 0;
5555
virtual vec opmat_col(int i, int j, int verb=0) = 0;
56-
virtual mat opmat_cols(int i, const vec& jlist, int verb=0) = 0;
56+
virtual mat opmat_cols(int i, const vec_i& jlist, int verb=0) = 0;
5757
virtual mat opmat_restricted(int,const subspace& s, int,int=0) = 0;
5858
virtual smat s_opmat(int,int,int=0) = 0;
5959
virtual svec s_opmat_col(int i, int j, int verb=0) = 0;
60-
virtual smat s_opmat_cols(int i, const vec& jlist, int verb=0) = 0;
60+
virtual smat s_opmat_cols(int i, const vec_i& jlist, int verb=0) = 0;
6161
virtual smat s_opmat_restricted(int,const ssubspace& s, int, int=0) = 0;
6262
virtual long matdim(void) = 0;
6363
virtual scalar matden(void) = 0;

libsrc/eclib/vector.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ class subspace_i; class subspace_l; class subspace_m;
9595
#undef smat
9696
#undef smat_elim
9797

98+
// conversions between vectors of different scalar types
99+
98100
vec_m to_vec_m(const vec_i& v);
99101
vec_m to_vec_m(const vec_l& v);
100-
vec_i to_vec_i(const vec_m& v);
102+
inline vec_m to_vec_m(const vec_m& v) {return v;}
103+
104+
vec_l to_vec_l(const vec_i& v);
105+
inline vec_l to_vec_l(const vec_l& v) {return v;}
101106
vec_l to_vec_l(const vec_m& v);
102107

108+
inline vec_i to_vec_i(const vec_i& v) {return v;}
109+
vec_i to_vec_i(const vec_l& v);
110+
vec_i to_vec_i(const vec_m& v);
111+
103112
#endif

libsrc/matrix.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ mat_i to_mat_i(const mat_m& m)
9494
return mat_i(m.nrows(), m.ncols(), n);
9595
}
9696

97+
mat_i to_mat_i(const mat_l& m)
98+
{
99+
const vector<long> & mij = m.get_entries();
100+
auto toint = [](const long& a) {return int(a);};
101+
vector<int> n(mij.size());
102+
std::transform(mij.begin(), mij.end(), n.begin(), toint);
103+
return mat_i(m.nrows(), m.ncols(), n);
104+
}
105+
97106
mat_l to_mat_l(const mat_m& m)
98107
{
99108
const vector<bigint> & mij = m.get_entries();
@@ -102,3 +111,12 @@ mat_l to_mat_l(const mat_m& m)
102111
std::transform(mij.begin(), mij.end(), n.begin(), tolong);
103112
return mat_l(m.nrows(), m.ncols(), n);
104113
}
114+
115+
mat_l to_mat_l(const mat_i& m)
116+
{
117+
const vector<int> & mij = m.get_entries();
118+
auto tolong = [](const int& a) {return long(a);};
119+
vector<long> n(mij.size());
120+
std::transform(mij.begin(), mij.end(), n.begin(), tolong);
121+
return mat_l(m.nrows(), m.ncols(), n);
122+
}

libsrc/mrank1.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,39 @@ int xsqrt(bigfloat a, bigfloat &b)
8181

8282
vector<long> rank1::qeps(const quartic& q, int x2)
8383
{
84-
vector<long> vec(num_aux); // position 0 is not used
85-
long i; vec[0]=0;
84+
vector<long> v(num_aux); // position 0 is not used
85+
long i; v[0]=0;
8686
for(i=1; i<num_aux; i++)
8787
{
8888
long a = posmod(q.geta(),auxs[i]);
8989
long H = posmod(q.getH(),auxs[i]);
9090
if(x2) H=posmod(hscalemod[i]*H,auxs[i]);
91-
vec[i] = flags[i][a][H];
91+
v[i] = flags[i][a][H];
9292
}
93-
return vec;
93+
return v;
9494
}
9595

96-
void rank1::show_eps_vec(const vector<long>& vec)
96+
void rank1::show_eps_vec(const vector<long>& v)
9797
{
9898
long i;
9999
cout<<"(";
100100
for(i=1; i<num_aux; i++) {
101101
if(i>1) cout<<":";
102102
if(aux_types[i]==1)
103-
switch(vec[i]) {
103+
switch(v[i]) {
104104
case 15: cout<<"0"; break;
105105
case 5: cout<<"1"; break;
106106
default: cout<<"?";
107107
}
108108
else
109-
switch(vec[i]) {
109+
switch(v[i]) {
110110
case 15: cout<<"00"; break;
111111
case 5: cout<<"01"; break;
112112
case 3: cout<<"10"; break;
113113
case 1: cout<<"11"; break;
114114
default: cout<<"??";
115115
}
116-
// cout<<"("<<vec[i]<<")";
116+
// cout<<"("<<v[i]<<")";
117117
}
118118
cout<<")";
119119
}

libsrc/vector.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ vec_i to_vec_i(const vec_m& v)
9797
return vec_i(w);
9898
}
9999

100+
vec_i to_vec_i(const vec_l& v)
101+
{
102+
const vector<long> & vi = v.get_entries();
103+
auto toint = [](const long& a) {return int(a);};
104+
vector<int> w(vi.size());
105+
std::transform(vi.begin(), vi.end(), w.begin(), toint);
106+
return vec_i(w);
107+
}
108+
100109
vec_l to_vec_l(const vec_m& v)
101110
{
102111
const vector<bigint> & vi = v.get_entries();
@@ -105,3 +114,12 @@ vec_l to_vec_l(const vec_m& v)
105114
std::transform(vi.begin(), vi.end(), w.begin(), tolong);
106115
return vec_l(w);
107116
}
117+
118+
vec_l to_vec_l(const vec_i& v)
119+
{
120+
const vector<int> & vi = v.get_entries();
121+
auto tolong = [](const int& a) {return long(a);};
122+
vector<long> w(vi.size());
123+
std::transform(vi.begin(), vi.end(), w.begin(), tolong);
124+
return vec_l(w);
125+
}

0 commit comments

Comments
 (0)